大佬帮忙看看为什么爆0了
查看原帖
大佬帮忙看看为什么爆0了
1395165
xywuyu楼主2024/10/20 18:32
#include<bits/stdc++.h>
using namespace std;
int fa[1000001];
int find(int x){
if(fa[x]!=x)fa[x]=find(fa[x]);
return fa[x];
}
void Union(int x,int y){
x=find(x);y=find(y);
fa[y]=x;
}
int main(){
  int n,m,k,x,y,e=0;
  cin>>n>>m>>k;
for(int i=1;i<=n*m;i++)fa[i]=i;
for(int i=1;i<=k;i++){
  cin>>x>>y;
  Union(x,y);}
for (int i=1;i<=n*m;i++)
{if (fa[i]=i)
e+=1;}
cout<<e;
  return 0;
}

2024/10/20 18:32
加载中...