Cod sursa(job #1809976)

Utilizator novistaAlex Staicu novista Data 19 noiembrie 2016 14:37:00
Problema Sate Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>
using namespace std;
int a[1001][1001],x,y,c[1001],v[1001],n,m,u,p;
ifstream fin ("sate.in");
ofstream fout ("sate.out");
void latime(int r)
{
    int k,i;
    p=1;
    u=1;
    v[r]=1;
    c[1]=r;
    while (p<=u)
    {
        k=c[p];
        for (i=1;i<=n;i++)
            if (a[k][i]!=0&&v[i]==0)
            {
                v[i]=v[k]+a[k][i];
                u++;
                c[u]=i;
            }
        p++;
    }
}
int main()
{
    int i,j,h,d;
    fin>>n>>m>>x>>y;
    for (h=1;h<=m;h++)
    {
        fin>>i>>j>>d;
        a[i][j]=d;
        a[j][i]=d*(-1);
    }
    latime(x);
    fout<<v[y]-1;
    fin.close();
    fout.close();
    return 0;
}