社区讨论
P1525 关押罪犯 10分求调
题目总版参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mhke1za5
- 此快照首次捕获于
- 2025/11/04 17:50 4 个月前
- 此快照最后确认于
- 2025/11/04 17:50 4 个月前
CPP
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+9;
int fa[N],a[N],b[N],c[N];
struct z{
int a,b,c;
}st[N];
bool cmp(z c1,z c2){
return c1.c>c2.c;
}
int find(int x){
if(x==fa[x]) return x;
return fa[x]=find(fa[x]);
}
void bing(int x,int y){
fa[find(x)]=find(y);
}
int main()
{
int n,m;
cin>>n>>m;
for(int j=1;j<=2*n;j++){
fa[j]=j;
}
for(int i=1;i<=m;i++){
cin>>st[i].a>>st[i].b>>st[i].c;
}
sort(st+1,st+1+m,cmp);
for(int i=1;i<=m;i++){
int xx=st[i].a,yy=st[i].b;
bing(xx,2*yy);
bing(yy,2*xx);
if(find(xx)==find(2*xx) || find(yy)==find(2*yy)){
cout<<st[i].c;
return 0;
}
}
cout<<0;
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...