题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
usingnamespacestd; typedeflonglongll; constintmaxn=10001; unordered_set<int>ust; intpre[maxn]; voidinit() { for(inti=0;i<maxn;i++) pre[i]=i; } intfind(intx) { returnpre[x]==x?x:pre[x]=find(pre[x]); } voidjoin(intx,inty) { intfx=find(x), fy=find(y); if(fx!=fy) pre[fx]=fy; } intmain() { intn,a,b; charop; scanf("%d",&n); init(); while(~scanf(" %c",&op) &&op!='S') { scanf("%d%d",&a,&b); if(op=='C') { if(find(a)==find(b)) puts("yes"); elseputs("no"); } elseif(op=='I') join(a,b); } for(inti=1;i<=n;i++) ust.insert(find(i)); if(ust.size()==1) puts("The network is connected."); elseprintf("There are %d components.\n",ust.size()); return0; }