The maze of HDU 1272 xiaoxi

Source: Internet
Author: User

 

Question Analysis

Query set Problems

 

Notes

1. the requirements in the questions are relatively broad, which leads to the conclusion that there is only a loop as an error. However, there are more than one error, it is also wrong if there are two trees or multiple trees (from A to B );

2. The connection between itself and itself is also incorrect.

 

Possible test data

 

1 1 0 00 01 2 3 4 0 01 2 2 3 3 4 0 01 3 5 3 0 0-1 -1

Answer:

 

NoYesNoYesYes

Reference Code

 

 

# Include
 
  
Int fa [100005]; // parent array int visit [100005]; // indicates whether int load () {int I; for (I = 0; I <100005; I ++) fa [I] = I;} int find (int x) {if (x! = Fa [x]) fa [x] = find (fa [x]); return fa [x];} int main () {int m, n; int x, y, fx, fy; int I, flag, flag1, count; while (scanf (% d, & m, & n) {flag = 0; count = 0; flag1 = 0; if (m =-1 & n =-1) break; else if (m = 0 & n = 0 ); else {load (); memset (visit, 0, sizeof (visit); fa [m] = n; visit [m] = 1; visit [n] = 1; if (m = n) flag = 1; while (scanf (% d, & x, & y), x & y) {fx = find (x ); fy = find (y); visit [x] = 1; visit [Y] = 1; if (fx = fy) flag = 1; else fa [fx] = fy ;}} for (I = 0; I <100005; I ++) {if (visit [I] & fa [I] = I) flag1 ++; if (visit [I]) count ++ ;}if (count = 0) printf (Yes); // test data else if (! Flag & flag1 = 1) printf (Yes); // No loop and only one else printf (No);} return 0 ;}
 

 

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.