Cod sursa(job #2246897)

Utilizator radugheoRadu Mihai Gheorghe radugheo Data 27 septembrie 2018 17:59:09
Problema Sate Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <vector>
#define DIM 30005

using namespace std;

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

int n, m, x, y, t, i, j, d, p, u, nod;
int c[DIM], v[DIM], l[DIM];

vector < pair <int, int> > L[DIM];

pair <int, int> vecin;

int main()
{
    fin >> n >> m >> x >> y;
    for (t=1; t<=m; t++){
        fin >> i >> j >> d;
        L[i].push_back({j, d});
        L[j].push_back({i, -d});
    }
    p = u = 1;
    c[1] = x;
    v[x] = 1;
    while (p <= u){
        nod = c[p];
        for (i=0; i<L[nod].size(); i++){
            vecin = L[nod][i];
            if (v[vecin.first] == 0){
                v[vecin.first] = 1;
                c[++u] = vecin.first;
                l[vecin.first] = l[nod] + vecin.second;
            }
        }
        p++;
    }
    fout << l[y];
    return 0;
}