HDU (3560) into the ring, and check the set

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.