Pagini recente » Cod sursa (job #1060874) | Cod sursa (job #1776383) | minune2 | Cod sursa (job #1582765) | Cod sursa (job #536845)
Cod sursa(job #536845)
#include <cstring>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
int N, M, X, Y, K, Kmax;
vector<pair<int, int> > V[250002];
bool S[250002];
int testnow;
void Dfs(int A)
{
S[A] = true;
for (vector<pair<int, int> >::iterator it = V[A].begin(); it != V[A].end(); ++it)
if (it->second <= testnow && !S[it->first])
Dfs(it->first);
}
bool Test(int value)
{
testnow = value;
memset(S, 0, sizeof(S));
Dfs(X);
return S[Y];
}
int main()
{
ifstream fin("pscnv.in");
ofstream fout("pscnv.out");
fin >> N >> M >> X >> Y;
for (int i = 1, nod1, nod2, cost; i <= M; ++i)
{
fin >> nod1 >> nod2 >> cost;
V[nod1].push_back(make_pair(nod2, cost));
Kmax = max(Kmax, cost);
}
int step;
for (step = 1; (step << 1) <= Kmax; step <<= 1);
for (K = Kmax + 1; step; step >>= 1)
if (K - step >= 1 && Test(K - step))
K -= step;
fout << K;
fin.close();
fout.close();
}