具体代码#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e4+10;
int fa[N];
void init(int n){
for(int i=1;i<=n;i++)
fa[i]=i;
}
int find(int x){
if(x==fa[x])return x;
else return fa[x]=find(fa[x]);
}
void merge(int a,int b){
int faA=find(a),faB=find(b);
if(faA!=faB)fa[faA]=faB;
}
int main(){
int n,a,b;
char c;
cin>>n;
init(n);
while(1){
cin>>c;
if(c=='S')break;
cin>>a>>b;
if(c=='I')merge(a,b);
else{
if(find(a)==find(b))cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
}
int cn=0;
for(int i=1;i<=n;i++){
if(fa[i]==i)cn++;
}
if(cn==1)cout<<"The network is connected.";
else cout<<"There are "<<cn<<" components.";
return 0;
}