文章
111
粉丝
1
获赞
729
访问
21.3k
#include <bits/stdc++.h>
using namespace std;
int father[1005];
int finds(int i){
if(father[i] != i)
father[i] = finds(father[i]);
return father[i];
}
int main(){
int n,m;
while(cin >> n >> m && n != 0){
int sum = 0;
for(int i = 1;i <= n; i++) father[i] = i;
while(m--){
int x,y;
cin >> x >> y;
int tx = finds(x);
int ty = finds(y);
if(tx != ty){
father[tx] = ty;
sum++;
}
...
登录后发布评论
暂无评论,来抢沙发