Cod sursa(job #1032835)

Utilizator arvinte.razvanarvinte razvan arvinte.razvan Data 16 noiembrie 2013 09:44:08
Problema Sate Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<cstdio>
#include<vector>
using namespace std;
struct da
{
    int x,p;
};
vector<da> v[30001];
da t;
int u[30001],n,m,a,b,x,y,z,viz[30001],i,c,p;
int main()
{
    freopen("sate.in","rt",stdin);
    freopen("sate.out","wt",stdout);
    scanf("%ld%ld%ld%ld",&n,&m,&a,&b);
    for(i=1;i<=m;i++)
    {
        scanf("%ld%ld%ld",&x,&y,&z);
        t.p=z;
        t.x=y;
        v[x].push_back(t);
        t.x=x;
        t.p=-z;
        v[y].push_back(t);
    }
    u[1]=a;
    viz[a]=0;
    c=p=1;
    while(p>=c)
    {
        for(i=0;i<v[u[c]].size();i++)
        if(viz[v[u[c]][i].x]==0)
        {viz[v[u[c]][i].x]=viz[u[c]]+v[u[c]][i].p;
        u[++p]=v[u[c]][i].x;}
        c++;
    }
    printf("%ld",viz[b]);
}