Beginner and check Set-3: Bath fire Galaxy Interstellar Jump

Source: Internet
Author: User

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

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.