Hdu1272 the maze of xiao xi (query set)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1272

Note:

1. cannot be a ring, that is, the two numbers of root nodes entered each time cannot be the same;

2. There is only one maze, that is, the number of root nodes is unique;

3. Note that "yes" must be output when only "0 0" is input ";

4. Recursive stack overflow is used for State compression.

Reference code:

#include<stdio.h>int fa[100001];int find(int u){    int s;    s=u;     while (fa[u]!=u)u=fa[u];     while (fa[s]!=s){fa[s]=u;s=fa[s];}      return u;}int main(){    int u,v,x,y,n,m,i,k;    bool bo;    scanf("%d%d",&u,&v);    while (u!=-1)    {       if (u!=0)         {          for (i=1;i<=100000;i++) fa[i]=i;           bo=true;             while (u)               {                 x=find(u);y=find(v);                if (x==y) {bo=false;}                else fa[x]=y;                scanf("%d%d",&u,&v);               }            if (!bo) printf("No\n");              int j;                if(bo)                  {                    for (i=1;i<=100000;i++)                      if (find(i)!=i) break;                    for (j=i+1;j<=100000;j++)                      if ((find(j)!=j)&&(find(j)!=find(i)))                        {                           printf("No\n");                             bo=false;                           break;                        }                  }            if (bo) printf("Yes\n");        }        else printf("Yes\n");      scanf("%d%d",&u,&v);    }   return 0;}<strong></strong>

Please refer to: http://blog.csdn.net/yzj577/article/category/2432227


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.