Pagini recente » Cod sursa (job #3249375) | Cod sursa (job #2844734) | Cod sursa (job #2919340) | Cod sursa (job #3285498) | Cod sursa (job #2229927)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("pscnv.in");
ofstream fout ("pscnv.out");
const int NMAX = 250005;
const int MMAX = 500005;
int t[NMAX], node1, node2, n, m;
struct T
{
int x, y, val;
};
T a[MMAX];
inline bool CMP(const T A, const T B)
{
return A . val < B . val;
}
inline void Union(int x, int y)
{
t[y] = x;
}
inline int Find(int x)
{
int rad, y;
rad = x;
while(t[rad])
rad = t[rad];
while(x != rad)
{
y = t[x];
t[x] = rad;
x = y;
}
return x;
}
int main()
{
int x, y;
fin >> n >> m >> node1 >> node2;
for(int i = 1 ; i <= m ; i++)
fin >> a[i] . x >> a[i] . y >> a[i] . val;
sort(a + 1, a + m + 1, CMP);
for(int i = 1 ; i <= m ; i++)
{
x = Find(a[i] . x);
y = Find(a[i] . y);
if(x != y)
Union(x, y);
x = Find(node1);
y = Find(node2);
if(x == y)
{
fout << a[i] . val << "\n";
return 0;
}
}
fin.close();
fout.close();
return 0;
}