#include<stdio.h>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
#include<stack>
#include<queue>
#include<string.h>
using namespace std;
#define N 10010
int Fa[N];
void Init()
{
for(int i=0;i<N;i++)
Fa[i]=i;
}
int Find(int x)
{
int r=x;
while(r!=Fa[r])
r=Fa[r];
int i=x,j;
while(i!=r)
{
j=Fa[i];
Fa[i]=r;
i=j;
}
return r;
}
int main()
{
Init();
int n,a,b,fa,fb;
char c;
scanf("%d",&n);
while(scanf("%c",&c))
{
if(c=='C')
{
scanf("%d%d",&a,&b);
fa=Find(a);
fb=Find(b);
if(fa!=fb)
printf("no\n");
else
printf("yes\n");
}
if(c=='I')
{
scanf("%d%d",&a,&b);
fa=Find(a);
fb=Find(b);
if(fa!=fb)
Fa[fb]=fa;
}
if(c=='S')
{
int ans=0;
for(int i=1;i<=n;i++)
{
if(Fa[i]==i)
ans++;
}
if(ans==1)
printf("The network is connected.");
else
printf("There are %d components.",ans);
return 0;
}
}
return 0;
}
File Transfer
最新推荐文章于 2024-06-11 09:42:45 发布