Beginner and find -4:6 a friend

Source: Internet
Author: User

Title Description Description

There is a saying: Know 6 people, you know people all over the world.

Aiden now has a diagram of the situation in which n people know each other. Aiden wants to know if he can only know 6 people and indirectly know these n individuals?

Enter a description Input Description

The first line, two numbers n,m, indicates that there are n individuals, M pairs of cognitive relationships.

The next M-line, which is two ai,bi per line, indicates that AI and bi are aware of each other.

There is no guarantee that the cognition relationship does not recur and ai≠bi.

n the number of individuals is 1 ... N.

Output description Output Description

If you know only 6 people can indirectly know this n person, then output "^_^".

If not, then the first line output "t_t", the second row of the output of the 6 people can know the most indirect number of people.

The output does not include quotation marks.

Sample input Sample Input

6 7

1 2

1 3

2 4

3 5

4 6

5 6

3 2

Sample output Sample Output

^_^

Data range and Tips Data Size & Hint

For 30% of data, ensure 0

For 50% of data, ensure 0

For 100% of data, ensure 0

Type R=record num,v:longint;    End;var I,j,k,l:longint;    Father:array[1..10000]of Longint;    N,m:longint;    X,y:longint;    Cost:array[1..10000]of R;    Num:array[1..10000]of integer;         Used:array[1..10000]of 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 (X,y:longint);          Begin Father[find (x)]:=find (Father[y]);          End;procedure Choose;              var i,j,k:longint;          Max,maxx:longint;                          Begin for I:=1 to 6 does begin max:=0;  For J:=1 to N does if (Cost[j].num>max) and (not USED[J]) then                                            Begin Max:=cost[j].num;                                      Maxx:=j;                          End                          Used[maxx]:=true;            L:=l+max;        End      End;begin readln (n,m);      Fillchar (Father,sizeof (father), 0);      For I:=1 to n do father[i]:=i;                For I:=1 to M do begin READLN (x, y);          If find (x) <>find (Y) then union (x, y);      End      Fillchar (cost,sizeof (cost), 0);      Fillchar (num,sizeof (num), 0);      Fillchar (used,sizeof (used), false);      For I:=1 to N Do Inc (Num[find (i)]);      k:=0;                        For I:=1 to N does if Num[i]<>0 then BEGIN Inc (K);                        Cost[k].v:=i;                  Cost[k].num:=num[i];      End      l:=0;                    If K<=6 then begin Writeln (' ^_^ ');              Halt                    end else begin choose;                    Writeln (' t_t ');              Writeln (l); End;end.

Beginner and check -4:6 a friend

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.