Cod sursa(job #1581154)

Utilizator atatomirTatomir Alex atatomir Data 26 ianuarie 2016 17:08:58
Problema PScNv Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back

#define maxN 250011
#define maxK 1024

int n, m, x, y, i, s, d, c;
vector< pair<int, int> > list[maxN];
bool unlocked[maxN];
vector<int> work[maxK];

int main()
{
    freopen("pscnv.in","r",stdin);
    freopen("pscnv.out","w",stdout);

    scanf("%d%d%d%d", &n, &m, &s, &d);
    for (i = 1; i <= m; i++) {
        scanf("%d%d%d", &x, &y, &c);
        list[x].pb(mp(y, c));
        list[y].pb(mp(x, c));
    }

    work[0] = {s};
    for (i = 0; unlocked[d] == false; ) {
        while (work[i].empty()) i++;

        int node = work[i][ work[i].size() - 1 ];
        work[i].pop_back();

        if (node == d) {
            printf("%d", i);
            return 0;
        }

        if (unlocked[node]) continue;
        unlocked[node] = true;
        for (auto to : list[node])
            if (!unlocked[to.first])
                work[ max(i, to.second) ].pb(to.first);
    }


    return 0;
}