POJ 1703 Find Them, Catch them (and set)

Source: Internet
Author: User

Description

The Police OfficeinchTadu City decides to say ends to the chaos, asLaunch actions to root up the gangsinchThe city, Gang Dragon and Gang Snake. However, the police first needs to identify which gang a criminal belongs to. The present question is, given, criminals; DoThey belong to a same clan?You must give your judgment based on incomplete information. (Since The gangsters is always acting secretly.) Assume N (n<=Ten^5) Criminals is currentlyinchTadu City, numbered from 1To N. And of course, at least one of them belongs to Gang Dragon, and the same forGang Snake. You'll be given m (m <=Ten^5) messagesinchSequence, which isinchThe following-kinds:1. D [A] [b]where[A] and [b] is the numbers of the criminals, and they belong to different gangs.2. A [a] [b]where[A] and [b] is the numbers of the criminals. This requires the decide whether a and B belong to a same gang.

Input

The first line of the input contains a single integer T (1 -case as described above.

Output

" a [a] [b] " inch  Case " In the same gang. " " In different gangs. " " Not sure yet. "

Sample Input

1 5 5  121 2 1 2 2  414

Sample Output

Not sure yet. In different gangs. In the same gang.

Source

POJ monthly--2004.07.18 and check the set, use a OPP array to record the opposing opponents, and then do the merge with the check set at first init () function forgot to add, oneself always so careless ... And when judging a, consider the same and different, and finally the rest is uncertain.
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 #defineN 1000066 intn,m;7 intOpp[n],fa[n];8 voidinit () {9      for(intI=0; i<n;i++){Tenopp[i]=0; Onefa[i]=i; A     } - } - intFindintx) { the     returnfa[x]==x?x:fa[x]=find (Fa[x]); - } - voidMergeintXinty) { -     introot1=find (x); +     intRoot2=find (y); -     if(ROOT1==ROOT2)return; +fa[root1]=Root2; A } at intMain () - { -     intT; -scanf"%d",&t); -      while(t--){ - init (); inscanf"%d%d",&n,&m); -         Chars[3]; to         intx, y; +          for(intI=0; i<m;i++){ -scanf"%s", s); the             if(s[0]=='A'){ *scanf"%d%d",&x,&y); $                 if(Find (x) = =find (Y)) {Panax Notoginsengprintf"In the same gang.\n"); -}Else if(Find (x) = =find (Opp[y])) { theprintf"In different gangs.\n"); +}Else{ Aprintf"Not sure yet.\n"); the                 } +             } -             Else{ $scanf"%d%d",&x,&y); $                 if(opp[x]==0&& opp[y]==0){ -opp[x]=y; -opp[y]=x; the                 } -                 Else if(opp[x]==0){Wuyiopp[x]=y; the merge (X,opp[y]); -                 } Wu                 Else if(opp[y]==0){ -opp[y]=x; About merge (Y,opp[x]); $                 } -                 Else{ - merge (X,opp[y]); - merge (Y,opp[x]); A                 } +             } the         } -     } $     return 0; the}
View Code

POJ 1703 Find Them, Catch them (and 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.