#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
const int INF = 1000000000;
int n;
int pa[maxn];
int findset(int x) {return pa[x]==x ? x : pa[x]=findset(pa[x]);}
struct Edge{
int u, v, d;
Edge(int u, int v, int d):u(u),v(v),d(d) {}
bool operator< (const Edge& rhs) const{
return d < rhs.d;
}
};
vector<Edge> e;
int solve(){
int m = e.size();
sort(e.begin(), e.end());
for(int i=0; i<n; ++i) pa[i] = i;
int ans = -1;
for(int i=0; i<m; ++i){
int x = findset(e[i].u), y = findset(e[i].v);
if(x!=y){
pa[x] = y;
ans = max(ans, e[i].d);
}
}
return ans;
}
int main(){
int m, u, v, d, root;
scanf("%d%d%d", &n, &m, &root);
for(int i=0; i<m; ++i){
scanf("%d%d%d", &u, &v, &d); u--; v--;
e.push_back(Edge(u,v,d));
}
printf("%d\n", solve());
return 0;
}
04-19
1783