Pagini recente » Cod sursa (job #2522002) | Cod sursa (job #3038374) | Cod sursa (job #2607026) | Cod sursa (job #2666380) | Cod sursa (job #778400)
Cod sursa(job #778400)
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;
#define from first
#define to second
#define pb push_back
#define mp make_pair
#define max 250010
#define Kmax 1001
int N, M, X, Y, a, b, c, T[max];
vector<pair<int, int> > G[Kmax];
void Unite(int X, int Y)
{
T[X] = Y;
}
int Search(int X)
{
if(X != T[X]) T[X] = Search(T[X]);
return T[X];
}
int main()
{
freopen("pscnv.in", "r", stdin);
freopen("pscnv.out", "w", stdout);
int i;
vector<pair<int, int> > :: iterator it;
scanf("%i %i %i %i", &N, &M, &X, &Y);
for(i = 1; i <= N; ++i) T[i] = i;
for(i = 1; i <= M; i++)
{
scanf("%i %i %i", &a, &b, &c);
G[c].pb(mp(a, b));
}
for(i = 1; i < Kmax; i++)
{
for(it = G[i].begin(); it != G[i].end(); ++it)
if(Search(it -> from) != Search(it -> to))
Unite(Search(it -> from), Search(it -> to));
if(Search(X) == Search(Y))
{
printf("%i\n", i);
return 0;
}
}
return 0;
}