@fuheimao
2014-10-16T14:59:03.000000Z
字数 597
阅读 627
腹黑猫
#include<iostream>
#include<cstdio>
using namespace std;
int f[1001];
int e[1001];
int a[1001]={0};
bool vis[1001];
int find(int x){
return (f[x]==x?x:f[x]=find(f[x]));
}
int setfather(int x,int y){
f[find(x)]=find(y);
}
int main (){
freopen("gangs.in","r",stdin);
freopen("gangs.out","w",stdout);
int n,m;
cin>>n>>m;
for (int i=1;i<=n;i++){
f[i]=i;
e[i]=0;
}
for (int i=1;i<=m;i++){
char a;
int x,y;
cin>>a>>x>>y;
if (a=='E'){ //敌人
if (e[x]==0){
e[x]=y;
}else{
setfather(e[x],y);
}
if (e[y]==0){
e[y]=x;
}else{
setfather(e[y],x);
}
}else{//朋友
setfather(x,y);
}
}
int ans=0;
for (int i=1;i<=n;i++){
if (!vis[find(i)]){
ans++;
vis[find(i)]=true;
}
}
cout<<ans<<endl;
}