Pagini recente » Cod sursa (job #392533) | Cod sursa (job #101653) | Cod sursa (job #2970984) | Cod sursa (job #822567) | Cod sursa (job #950916)
Cod sursa(job #950916)
#include <cstdio>
#include <vector>
#include <cstring>
#define dim 8192
using namespace std;
const char iname[] = "pscnv.in";
const char oname[] = "pscnv.out";
struct nod{
int y, c; nod(){}; nod(int m, int n){ y = m; c = n;};
};
vector <nod> v[250004];
bool viz[250004];
int x;
char ax[dim];
int pz;
inline void cit(int &x){
x = 0;
while (ax[pz] < '0' || ax[pz] > '9')
if (++pz == dim)
fread (ax, 1, dim, stdin), pz = 0;
while (ax[pz] >= '0' && ax[pz] <= '9'){
x = x * 10 + ax[pz] - '0';
if (++pz == dim)
fread (ax, 1, dim, stdin), pz = 0;
}
}
int N, M, A, B, i, j, g, h, mv, ANS;
inline void DFS(int node, int X)
{
vector <nod> :: iterator it, fin;
viz[node] = true;
it = v[node].begin();
fin = v[node].end();
for (; it != fin; ++it)
{
if (!viz[it -> y] && it -> c <= X)
DFS(it -> y, X);
}
}
inline int BS(){
int Mij, St = 1, Dr = mv;
while (St <= Dr){
Mij = (St + Dr) / 2;
DFS(A, Mij);
if (!viz[B]) St = Mij + 1;
else{
Dr = Mij - 1;
ANS = Mij;
}
memset(viz, 0, sizeof(viz));
}
return ANS;
}
int main()
{
freopen(iname,"r",stdin);
freopen(oname,"w",stdout);
cit(N); cit(M); cit(A); cit(B);
while (M--){
cit(g); cit(h); cit(i);
if (i > mv) mv = i;
v[g].push_back(nod(h, i));
}
printf("%d\n", BS());
return 0;
}