Cod sursa(job #2275394)

Utilizator ikogamesIon Ceaun ikogames Data 3 noiembrie 2018 10:30:40
Problema Sate Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin ("sate.in");
ofstream fout ("sate.out");
           /// xi d
vector < pair<int,int> > h[30001];
queue <int> q;
int d[30001], X, Y;
/// d[i] = dist de la X la i

int main()
{
    int i, j, m, n, x, y, dist;
    fin >> n >> m >> X >> Y;
    for (i = 1; i <= m; i++)
    {
        fin >> x >> y >> dist;
        h[x].push_back({y, dist});
        h[y].push_back({x, -dist});
    }
    for (i = 1; i <= n; i++)
        d[i] = -1;
    d[X] = 0;
    q.push(X);
    while (!q.empty() )
    {
        j = q.front();
        q.pop();
        for(auto i: h[j])
            if(d[i.first] == -1)
            {
                cout << "a";
                q.push(i.first);
                d[i.first] = d[j] + i.second;
            }
        if (d[Y] > 0)
        {
            fout << d[Y] << "\n";
            return 0;
        }
    }
    return 0;
}