|
- #include<iostream>
- #include<algorithm>
- #define FOR(i,a,b) for(register int i=a;i<=b;i++)
- #define ROF(i,a,b) for(register int i=a;i>=b;i--)
- using namespace std;
- const int N=20005,M=100005;
- int n,m,f[N],d[N];
- struct node
- {
- int a,b,c;
- }e[M];
- inline bool cmp(node x,node y){return x.c>y.c;}
- int getf(int q)
- {
- if(f[q]==q)return q;
- f[q]=getf(f[q]);
- return f[q];
- }
- void Merge(int x,int y){f[getf(f[x])]=getf(f[y]);return;}
- int main()
- {
- cin>>n>>m;
- FOR(i,1,n)f[i]=i;
- FOR(i,1,m)cin>>e[i].a>>e[i].b>>e[i].c;
- sort(e+1,e+m+1,cmp);
- FOR(i,1,m+1)
- {
- if(getf(e[i].a)==getf(e[i].b)){cout<<e[i].c<<endl;return 0;}
- if(!d[e[i].a])d[e[i].a]=e[i].b;
- else Merge(d[e[i].a],e[i].b);
- if(!d[e[i].b])d[e[i].b]=e[i].a;
- else Merge(d[e[i].b],e[i].a);
- }
- return 0;
- }
复制代码 |
|