problem
solution
codes
#include<iostream>
#include<algorithm>
using namespace std;
struct Edge{ int u, v, w; }e[100010];
bool cmp(Edge a, Edge b){ return a.w>b.w; }
int fa[20010<<1];
void init(int n){ for(int i = 1; i <= n; i++)fa[i]=i; }
int find(int x){ return x==fa[x]?x:fa[x]=find(fa[x]); }
void merge(int x, int y){ x=find(x);y=find(y);if(x!=y)fa[x]=y;}
int main(){
int n, m;
cin>>n>>m;
for(int i = 1; i <= m; i++)
cin>>e[i].u>>e[i].v>>e[i].w;
sort(e+1,e+m+1,cmp);
init(n<<1);
for(int i = 1; i <= m; i++){
int u = e[i].u, v = e[i].v;
if(find(u) == find(v)){
cout<<e[i].w<<"\n"; return 0;
}
merge(u+n, v);
merge(v+n, u);
}
cout<<0<<"\n";
return 0;
}