Cod sursa(job #1876670)

Utilizator dsergiu05Sergiu Druga dsergiu05 Data 12 februarie 2017 15:33:18
Problema Sate Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#include <vector>

using namespace std;

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

struct str {
    int x, y;
};

const int nmax=30000;
vector <str> g[nmax+1];
int sol[nmax+1];

void dfs (int x) {
    for (vector <str>::iterator it = g[x].begin(); it != g[x].end(); ++ it ) {
        if (sol[it->x]==0) {
            sol[it->x]=sol[x]+it->y;
            dfs(it->x);
        }
    }
}

int main () {
    int n, m, a, b;
    fin>>n>>m>>a>>b;

    for (int i=1; i<=m; i++) {
        int x, y, c;
        fin>>x>>y>>c;
        str aux;
        aux.x=y;
        aux.y=c;
        g[x].push_back(aux);
        aux.x=x;
        aux.y=-c;
        g[y].push_back(aux);
    }

    sol[a]=3e7;
    dfs(a);

    fout<<sol[b]-sol[a]<<"\n";

    return 0;
}