Title Description
DescriptionLittle K again playing bath fire Milky Way ... But this time his purpose was not to run the transportation to make money, butis to do the job to make money. He wanted to know if the two galaxies on a mission could be connected. Enter a description
Input Descriptionfirst line, three numbers, X,n,mX indicates the maximum number of galaxy symbols that appear;n indicates that there are n interstellar jumping gates;m indicates there is a M task. the next N lines describe each interstellar jumping gate: two numbers per action (Galaxy code),the interstellar jumping gate is connected to the two galaxies (the interstellar jumping gate can be used in both directions);the next M-line represents the galaxies that each task needs to reach, and each task needs to reach twoa galaxy. Output description
Output DescriptionA total of M rows. line I indicates whether the first task can be completed: whether two galaxies can connect. (Can →Yes; not →no)Sample input
Sample Input5 2 13 54 53 4Sample output
Sample Output
Yes
var total,n,m:longint; Father:array[1..10000000]of Longint; Used:array[1..10000000]of Boolean; I,j,k,x,y:longint; Yo:boolean;function Find (X:longint): Longint; Begin if Father[x]=x then exit (x); Father[x]:=find (Father[x]); Exit (Father[x]); End;procedure Union (A,b:longint); var i,j,k:longint; Begin Father[find (a)]:=find (Father[b]); End;begin Yo:=false; Fillchar (Father,sizeof (father), 0); Fillchar (used,sizeof (used), true); READLN (total,n,m); For I:=1 to Total do father[i]:=i; For I:=1 to n do begin READLN (x, y); If find (x) <>find (y) then Union (x, y); End; For I:=1 to M do begin READLN (x, y); If find (x) =find (y) then writeln (' Yes ') else writeln (' No '); End;end.
Beginner and check Set-3: Bath fire Galaxy Interstellar Jump