标签:一个 多少 for 需要 pre out class 位置 ==
题意简述:
给定一个 n×m的矩阵,其中 q 个位置已经被填充。
有一条规则,如果 (r1,c1) ,(r1,c2),(r2,c1) 均被填充,则 (r2,c2) 也被填充。任何被其他三个位置生成的位置,也可以继续生成其他位置。问最少需要再人为填充多少元素,使矩阵被填满。
这个题思维真的强
int fa[maxn];
int Find(int x){
return fa[x]==x?x:fa[x]=Find(fa[x]);
}
int main(){
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=n+m;i++)
fa[i]=i;
int ans=n+m-1;
for(int i=1;i<=k;i++){
int R,C;
cin>>R>>C;
int px=Find(R);
int py=Find(C+n);
if(px!=py){
ans--;
fa[px]=py;
}
}
cout<<ans<<endl;
}
标签:一个 多少 for 需要 pre out class 位置 ==
原文地址:https://www.cnblogs.com/033000-/p/12343589.html