Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3560
And check the set of several blocks, modified the previous one of my method (with what map), directly determine the root node ID is the number of I.
Then the judgment of the ring is a filter, first filter the degree of each node is not 2, if not the direct exclusion (root node), when checking the block, further check whether the root node is excluded.
So easy;
#include <stdio.h>#include<string.h>intfather[100010];intdegree[100010];BOOLvis[100010];intFind_set (intx) { if(x!=father[x]) father[x]=Find_set (father[x]); returnfather[x];}intMain () {intn,m; while(SCANF ("%d%d", &n,&m), n+m) {memset (Vis,true,sizeof(VIS)); memset (degree,0,sizeof(degree)); for(intI=0; i<n;i++) Father[i]=i; for(intI=0; i<m;i++) { intx, y; scanf ("%d%d",&x,&y); DEGREE[X]++; Degree[y]++; intFx,fy; FX=Find_set (x); FY=Find_set (y); if(fx!=FY) {Father[fy]=FX; } } for(intI=0; i<n;i++) { if(degree[i]!=2) Vis[find_set (i)]=false; } ints =0; inth =0; for(intI=0; i<n;i++) { if(Find_set (i) = =i) {s++; if(Vis[i]) H++; }} printf ("%d%d\n", s,h); } return 0;}
HDU (3560) into the ring, and check the set