本机上数据全过,交上去就只有10pts啊啊(鬼知道我为什么要打那么丑)
Code
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,f[101000],i,e[101000],ans;
char c;
int finds(int x){
if (f[x]==-1) return x;
return f[x]=finds(f[x]);
}
void ins(int x,int y){
int fx=finds(x),fy=finds(y);
if (fx!=fy) f[fx]=fy;
}
int main(){
memset(f,-1,sizeof(f));
scanf("%d%d",&n,&m);
for (i=1;i<=m;i++){
getchar();c=getchar();
scanf("%d%d",&x,&y);
if (c=='F') ins(x,y);
else ins(x+n,y),ins(x,y+n);
}
for (i=1;i<=n;i++)
if (!e[finds(i)]) ans++,e[finds(i)]=1;
printf("%d\n",ans);
return 0;
}