Cod sursa(job #952186)

Utilizator costin7856Antonesi Florean Costin costin7856 Data 22 mai 2013 20:32:07
Problema Sate Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include<fstream>
#define dim 30009
#define dim2 4009
using namespace std;
int viz[dim],n,m,x,y,c[dim],k;
int a[dim2][dim2],dist,l;
int cost[dim];
ofstream g("sate.out");
ifstream f("sate.in");
void citire()
{
    int x,y;
    f>>n>>m>>k>>l;
    int l;
    for(l=1;l<=m;l++)
    {
        f>>x>>y>>dist;
        a[x][y]=dist;
        a[y][x]=-dist;
    }
}
void bfs(int k)
{
    int li,lf;
    li=1;
    lf=1;
    c[li]=k;
    viz[k]=1;
    while (li<=lf)
    {
        k=c[li];
        for(int i=1;i<=n;i++)
        if(!viz[i]&&a[k][i]!=0)
        {
            lf++;
            c[lf]=i;
            viz[i]=1;
            cost[i]=cost[k]+a[k][i];;
        }
        li++;
    }
}
int main()
{
    int i;
    citire();
    bfs(k);
    g<<cost[l];
}