Cod sursa(job #902664)

Utilizator alexsuciuAlex Suciu alexsuciu Data 1 martie 2013 15:57:01
Problema Sate Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<fstream>
using namespace std;
ifstream f("sate.in");
ofstream g("sate.out");
int i,j,k,q[10000],a[100][100],n,m,x,prim,viz[100],c,y;
void bf(int x)
{
    if(i<=j)
    {
        prim=q[i];
        for(k=1;k<=n;k++)
            if(a[prim][k]!=0 && viz[k]==0)
        {
            j++;
            q[j]=k;
            if(prim<k)
            viz[k]=viz[prim]+a[prim][k];
            else viz[k]=viz[prim]-a[prim][k];
        }
    i++; bf(x);}
}
int main()
{
    f>>n>>m>>x>>y;
    while(f>>i>>j>>c)
        a[i][j]=a[j][i]=c;
    q[1]=x;
    viz[x]=1;
    i=j=1;
    bf(x);
    g<<viz[y]-1;
}