Hdoj 1272 The maze of little Nozomi

Source: Internet
Author: User

The last time 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 INPUT6 8 5 3 5 2 6 4 5 6 0 0 8 1 7 3 6 2 8 9 7 57 4 7 8 7 6 0 0 3 8 6 8 6 4 5 3 5 6 5 2 0 0-1-1

Sample outputyes Yes No Note: The problem has a total of looping and a number of trees two kinds of things can not be the case I just started the code is always unable to pass, and later the calculation data with the other code comparison, found that the first input is 0 0 should be output yes, but do not know why, So I added two lines of code to output the first time I entered 0 0 results
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 #defineN 1000105 using namespacestd;6 intPer[n], h[n];7 voidInit ()8 {9      for(inti =1; I <= N; i++)TenPer[i] =i; One } A intFindintx) - { -     returnX==PER[X]?X:find (per[x]); the }  - intJoinintXintY//Judging whether it is a ring - { -     intFX =find (x); +     intFY =find (y); -     if(FX = = FY)//because the two points given are inherently connected, if the root node is the same, it becomes a ring. +         return 0; A     Else at     { -PER[FX] =fy; -         return 1; -     }  - } - intMain () in { -     intN, M; to      while(~SCANF ("%d%d", &n, &m), n!=-1&& m!=-1) +     { -memset (H,0,sizeof(h)); the         if(n = =0&& m = =0) *         { $printf"yes\n");Panax Notoginseng             Continue; -         } the         intFlag =1; +H[n] =1; AH[M] =1; the init (); + join (n, m); -          while(~SCANF ("%d%d", &n, &m), n&&m) $         { $             intt = Join (n, m);//use T to record whether or not to ring -             if(!H[n]) -H[n] =1; the             if(!H[m]) -H[M] =1;Wuyi             if(T = =0) theFlag =0; -         } Wu         intRoot =0; -          for(inti =1; I <= N; i++)//determine the number of root nodes About         { $             if(H[i] && per[i] = =i) -root++; -         } -         if(Flag = =0|| Root >1) Aprintf"no\n"); +         Else theprintf"yes\n"); -          $     } the     return 0; the}

Hdoj 1272 The maze of little Nozomi

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.