HDU Hangzhou 1272 Little Greek maze "and check set"

Source: Internet
Author: User

Problem description Last Gardon Maze Castle Little Nozomi played for a long time (see Problem B), now she also want to design a maze let Gardon to go. But she designed the maze of different ideas, first she thought all the channels should be two-way connectivity, that is, if there is a channel connected to room A and B, then can go through it from room A to room B, but also through it from Room B to room A, in order to improve the difficulty, Xiaoxi hope that any two rooms have and only one path can be connected (unless you go back). Xiao-Nozomi now gives you her design to help you determine whether her design is in line with her design ideas. For example, the first two are eligible, but the last one has two methods of reaching 8 from 5.


Input inputs contain multiple sets of data, each of which is a list of integer pairs ending in 0 0, representing the number of two rooms to which a channel is connected. The number of the room is at least 1 and no more than 100000. There is a blank line between each of the two sets of data.
The entire file ends with two-1.

Output contains only one row for each set of data that is entered. If the maze conforms to Xiaoxi's idea, then output "Yes", otherwise output "No".

Sample Input
6 8  5 3 5 2 6 6 0 1 7 3  6 2  8 9  7  4 7 8 7 6 0 8 6 8 6 4 5 3  5 6  5 2  0 0-1-1

Sample Output
Yesyesno


The first is to determine whether the tree, the tree is not ring, and then determine the number of root nodes, there can only be one root node.

This problem needs to be noted at the beginning of input 0 0 o'clock should enter Yes

So the first set of data should be processed separately

#include <stdio.h> #define MAX 100000+10int Per[max+100];int flag;//this to be defined as global variable int find (int x) {int T=x;while (per[t ]!=t) {t=per[t];} int R=t;int I=x,j;while (per[i]!=r) {j=per[i];p er[i]=r;i=j;} return r;} void join (int x,int y) {int fx=find (x); int fy=find (y); if (fx!=fy) {per[fx]=fy;} Else flag=0;//when flag=0 when the ring, do not meet the conditions}int vis[max+100]; int main () {int m,n,i;while (~scanf ("%d%d", &m,&n))//Enter the first set of data separately by entering {if (m==-1&&n==-1) break;else if (m==0 &&n==0) {printf ("yes\n"); continue;} for (i=1;i<=max;++i) {per[i]=i;vis[i]=0;} vis[m]=1;vis[n]=1; Flag=1;join (m,n); while (scanf ("%d%d", &m,&n), m+n) {vis[m]=1;vis[n]=1; join (m,n);} int Rnum=0;for (i=1;i<max;++i) {if (Vis[i]&&i==per[i])//Find the number of root nodes {++rnum;} if (rnum>=2)//When the root node is greater than 1 o'clock {flag=0;break;}} if (flag) printf ("yes\n"), Else printf ("no\n");} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdu Hangzhou 1272 Little Greek maze "and check 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.