Cod sursa(job #2210964)

Utilizator AndreiCroitoruAndrei Croitoru AndreiCroitoru Data 8 iunie 2018 20:16:10
Problema Sate Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("sate.in");
ofstream out("sate.out");
struct graf
{
    int nod,c;
};
vector <graf> G[30001];
int viz[30001],n,x,m,y;
void dfs(int i)
{
    int j,w,cost;
    for(j=0;j< G[i].size(); j++)
    {
        w=G[i][j].nod;
        cost=G[i][j].c;
        if(viz[w]==0)
        {
            viz[w]=viz[i]+cost;
            dfs(w);
        }
    }
}
int main()
{
    int a,b;
    in>>n>>m>>a>>b;
    if(b<a)
        swap(a,b);
    for(int i = 1; i <= n; i++)
    {
        int x,y,c;
        in>>x>>y>>c;
        G[x].push_back({y,c});
        G[y].push_back({x,-c});
    }
    dfs(a);
    out<<viz[b];
    return 0;
}