# HDU 1829 A Bug & #39; s Life (parallel query set), hdu1829

Source: Internet
Author: User

HDU 1829 A Bug's Life (query set), hdu1829

Question and idea: Given the relationship between n Bugs (shen me gui) and m-to-Bugs, assuming the relationship is the relationship between men and women of the two Bugs, the question storage does not exist.Homosexuality.

So if a and B are men and women, and B and c are men and women, then we can think that the gender of a and c is the same. We can establish two sets and check the relationship between male and female.

If there is a ring in the male relationship (that is, there is a common root), then there will be a gay relationship.

`# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # define N 2000 + 10 using namespace std; int OK; int f [N], p [N]; // p [] indicates the relationship between men and women. Void Init (int n) {for (int I = 1; I <= n; I ++) {f [I] = I; p [I] = 0 ;}} int Find (int x) {return x = f [x]? X: f [x] = Find (f [x]);} void Merge (int a, int B) // a has a male relationship with B. {Int ra = Find (a), rb = Find (B); if (ra = rb) {// gay. OK = 0; return;} if (p [ra]) f [p [ra] = rb; // p [ra] and rb are in the same relationship (male) if (p [rb]) f [p [rb] = ra; // p [rb] And ra are in the same relationship (female) p [ra] = rb; p [rb] = ra;} int main () {int T, C = 0; scanf ("% d", & T); while (T --) {int n, m; scanf ("% d", & n, & m); Init (n); OK = 1; for (int I = 0; I <m; I ++) {int a, B; scanf ("% d", & a, & B); Merge (a, B );} printf ("Scenario # % d: \ n", ++ C); if (OK) puts ("No suspicious bugs found! "); Else puts (" Suspicious bugs found! "); Puts (" ");} return 0 ;}`

Related Keywords:

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.