Cod sursa(job #2244955)

Utilizator DanutAldeaDanut Aldea DanutAldea Data 24 septembrie 2018 13:45:54
Problema Sate Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <vector>
using namespace std;

ifstream fin("sate.in");
ofstream fout("sate.out");

int n,m,x,y,cnt,k,i,j,p,u,c[30001],f[30001],drum[30001];

vector <int> l[30001];
vector <int> cost[30001];

int main(){
    fin>>n>>m>>x>>y;
    for(cnt=1;cnt<=m;cnt++){
        fin>>i>>j;
        l[i].push_back(j);
        l[j].push_back(i);
        fin>>k;
        cost[j].push_back(0-k);
        cost[i].push_back(k);
    }

    c[1]=x;
    f[x]=1;
    p=1; u=1;

    while(f[y]==0 && p<=u){
        for(k=0;k<l[c[p]].size();k++){
            if(f[l[c[p]][k]]==0){
                c[++u]=l[c[p]][k];
                drum[l[c[p]][k]]=drum[c[p]]+cost[c[p]][k];
                f[l[c[p]][k]]=1;
            }
        }
        p++;
    }

    fout<<drum[y];

    return 0;
}