Hangzhou Electric 1272 and check the collection to find the ring + to determine connectivity

Source: Internet
Author: User

Hangzhou electric 1272 and find ring + judge connected E-eTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64 U SubmitStatusPracticeHDU 1272

Description

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

Input contains multiple sets of data, each set of data is a list of integers ending in 0 0, representing the number of two rooms connected by a channel. 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

For each set of data entered, the output includes only one row. If the maze conforms to Xiaoxi's idea, then output "Yes", otherwise output "No".

Sample Input

6 8 5 3 5 2 6 45 6 0 08 1 7 3 6 2 8 9 7 57 4 7 8 7 6 0 03 8 6 8 6 45 3 5 6 5 2 0 0-1-1

Sample Output

Yesyesno idea: Use and check set to find the ring and determine connectivity. The two vertices of the joined edges are already in the same set, indicating a ring. Judging connectivity directly depends on whether a bit is in the same set. This problem input data a pit, recursive burst stack a pit.
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<vector>#include<stack>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<cctype>#definell Long Long#defineREP (I,A,B) for (int (i) = (a);(i) <= (b);(i) + +)#defineRepp (i,a,b,t) for (int (i) = (a);(i) <= (b);(i) + = (t))#defineRep (i,a,b) for (int (i) = (a);(i) >= (b);(i)--)#defineRepp (i,a,b,t) for (int (i) = (a);(i) >= (b);(i)-= (t))#definePII pair<int,int>#defineFST First#defineSND second#defineMP Make_pair#definePB push_back#defineRI (x) scanf ("%d",& (x))#defineRII (x, y) scanf ("%d%d",& (×),& (y))#defineRIII (x, Y, z) scanf ("%d%d%d",& (×),& (y),& (z))#defineDRI (x) int (x); scanf ("%d",& (x))#defineDrii (x, y), scanf ("%d%d",& (x),& (y))#defineDRIII (x, y), (z), scanf ("%d%d%d",& (x),& (y),& (z))#defineRS (x) scanf ("%s", X)#defineRSS (x, y) scanf ("%s%s", X, y)#defineDRS (x) char x[maxn];scanf ("%s", X)#defineDrss (x, y) char x[maxn],y[maxn];scanf ("%s%s", X, y)#defineMS0 (a) memset ((a), 0,sizeof ((a)))#defineMS1 (a) memset ((a), -1,sizeof ((a)))#defineMS (b) memset ((a), (b), sizeof ((a)))#defineAll (v) v.begin (), V.end ()#defineSZ (v) (int) (v). Size ()using namespacestd;Const intmaxn=1000100;Const intInf= (1<< in);Const Doubleeps=0.0000000001;Const DoublePi=acos (-1.0);intu,v;intFA[MAXN];BOOLFlag;vector<int>V;BOOLVIS[MAXN];voidInit () {flag=1; REP (i,1, maxn-1) fa[i]=i;    MS0 (VIS); V.clear ();}/*int find (int x) {return fa[x]==x?x:fa[x]=find (fa[x]);}*/intFindintx) {    intp=x,t;  while(fa[p]!=p) p=Fa[p];  while(x!=p) {T=Fa[x]; FA[X]=p; X=T; }    returnx;}voidsolve () {if(flag&&SZ (V)) {        intX=find (v[0]); REP (i,0, SZ (V)-1){            inty=find (V[i]); if(x!=y) {Flag=0; Break; }}} puts (flag?"Yes":"No");}intMain () {Freopen ("In.txt","R", stdin);    Init ();  while(~RII (u,v)) {        if(u==-1&&v==-1)return 0; if(u==0&&v==0) {solve ();            Init (); Continue; }        if(!vis[u]) V.PB (u), vis[u]=1; if(!vis[v]) V.PB (v), vis[v]=1; intX=find (u), y=Find (v); if(x==y) flag=0; Elsefa[x]=y; }    return 0;}
View Code

Hangzhou Electric 1272 and check the collection to find the ring + to determine connectivity

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.