

#include <stdio.h>
#include <stdlib.h>
#define MaxSize 10000
typedef int ElementType;
typedef int SetName;
typedef ElementType SetType[MaxSize];
SetName Find(SetType S, ElementType X);
void Union(SetType S, SetName Root1, SetName Root2);
void Check(SetType S);
void Link(SetType S);
void Stop(SetType S, int N);
int main()
{
int N;
SetType S;
char op;
scanf("%d\n",&N);
for(int i=0; i<N; i++)
S[i]=-1;
do{
scanf("%c",&op);
switch(op){
case 'I': Link(S);break;
case 'C': Check(S);break;
case 'S': Stop(S,N);break;
}
}while(op != 'S');
return 0;
}
SetName Find(SetType S, ElementType X){
if(S[X]<0)
return X;
else
return S[X]=Find(S,S[X]);
}
void Union(SetType S,SetName Root1, SetName Root2){
if(S[Root1]>S[Root2]){
S[Root2]+=S[Root1];
S[Root1]=Root2;
}else{
S[Root1]+=S[Root2];
S[Root2]=Root1;
}
}
void Check(SetType S){
ElementType x,y;
SetName R1,R2;
scanf("%d %d\n",&x,&y);
R1=Find(S,x-1);
R2=Find(S,y-1);
if(R1==R2)
printf("yes\n");
else
printf("no\n");
}
void Link(SetType S){
ElementType x,y;
SetName R1,R2;
scanf("%d %d\n",&x,&y);
R1=Find(S,x-1);
R2=Find(S,y-1);
if(R1!=R2)
Union(S,R1,R2);
}
void Stop(SetType S, int N){
int num=0;
for(int i=0;i<N;i++){
if(S[i]<0)
num++;
}
if(num>1)
printf("There are %d components.\n",num);
else
printf("The network is connected.\n");
}
