社区讨论
为什么错了 求解
P2330[SCOI2005] 繁忙的都市参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi6y9e3c
- 此快照首次捕获于
- 2025/11/20 12:47 4 个月前
- 此快照最后确认于
- 2025/11/20 12:47 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int fa[1005];
int i;
int Max=0,s=0;
int fx,fy;
struct node{
int u,v,w;
}e[200005];
int getfather(int x){
if(fa[x]!=x)
fa[x]=getfather(fa[x]);
return fa[x];
}
int cmp(node x,node y){
if(x.w<y.w)return 1;
return 0;
}
int main(){
int m,n;
cin>>n>>m;
for(i=1;i<=m;i++)
cin>>e[i].u>>e[i].v>>e[i].w;
for(i=1;i<=n;i++)
fa[i]=i;
sort(e+1,e+1+n,cmp);
for(i=1;i<=m;i++){
fx=getfather(e[i].u);
fy=getfather(e[i].v);
if(fx!=fy){
fa[fx]=fy;
s++;
if(e[i].w>Max)
Max=e[i].w;
}
}
cout<<s<<" "<<Max;
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...