Cod sursa(job #1401387)

Utilizator Ionut228Ionut Calofir Ionut228 Data 25 martie 2015 20:32:00
Problema PScNv Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

const int INF = 0x3f3f3f3f;

int N, M, x, y;
int sol;
vector<pair<int, int> > V[250005];

void dfs(int nod, int know)
{
    if (nod == y)
    {
        sol = min(sol, know);
        return;
    }

    while (!V[nod].empty())
    {
        pair<int, int> next = V[nod][V[nod].size() - 1];
        V[nod].pop_back();
        dfs(next.first, max(know, next.second));
    }
}

int main()
{
    fin >> N >> M >> x >> y;
    for (int i = 1, nod1, nod2, k; i <= M; ++i)
    {
        fin >> nod1 >> nod2 >> k;
        if (nod1 == nod2)
            continue;
        V[nod1].push_back(make_pair(nod2, k));
    }

    sol = INF;
    if (x == y)
        sol = 0;
    else
        dfs(x, 0);

    fout << sol << '\n';

    fin.close();
    fout.close();
    return 0;
}