标签:bool end 最优 out 并查集 最大 时间 name sort
merge(a[i].x,a[i].y + n);
merge(a[i].y,a[i].x + n)
#include <bits/stdc++.h>
using namespace std;
struct node{
int x,y;
int w;
}a[100010];
bool cmp(node c,node d){
return c.w > d.w;
}
int fa[200010];
int get(int x){
if(fa[x] == x)return x;
return fa[x] = get(fa[x]);
}
void merge(int x,int y){
fa[get(x)] = get(y);
return;
}
int main(){
int n,m;
cin>>n>>m;
for(int i = 1;i <= 2 * n;i++)fa[i] = i;
for(int i = 1;i <= m;i++){
cin>>a[i].x>>a[i].y>>a[i].w;
}
sort(a + 1,a + m + 1,cmp);
for(int i = 1;i <= m;i++){
if(get(a[i].x) == get(a[i].y)){cout<<a[i].w<<endl;exit(0);}
merge(a[i].x,a[i].y + n);
if(get(a[i].y) == get(a[i].x)){cout<<a[i].w<<endl;exit(0);}
merge(a[i].y,a[i].x + n);
}
cout<<0<<endl;
return 0;
}
标签:bool end 最优 out 并查集 最大 时间 name sort
原文地址:https://www.cnblogs.com/czy--blog/p/11741843.html