TORONTO KIDS COMPUTER CLUB | Aurora Saturday 14:30 Python Practice 22.04.30.
20596
post-template-default,single,single-post,postid-20596,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Aurora Saturday 14:30 Python Practice 22.04.30.

05 May Aurora Saturday 14:30 Python Practice 22.04.30.

Question: (floyd-warshall)

There are N players in Dota team.
This year’s The Weekend Battle Cup is coming, and Jack want to select some excellent player to attend the contest. There have been M matches since the last few days(No two players will meet each other at two matches, means between two players there will be at most one match). Jack also asks “Who is the winner between A and B?” But sometimes you can’t answer Jack’s query, for example, there are 3 people, named A, B, C. and 1 match was held between A and B, in the match A is the winner, then if Jack asks “Who is the winner between A and B”, of course you can answer “A”, but if Jack ask “Who is the winner between A and C”, you can’t tell him the answer.

As Jack’s assistant, you want to know how many queries at most you can’t tell Jack (ask A B, and ask B A is the same; and Jack won’t ask the same question twice).

Input
The input contains multiple test cases.
The first line has one integer, represent the number of test cases.
Each case first contains two integers N and M(N , M <= 500), N is the number of player in Dota team, and M is the number of matches have been held. The following M lines, each line means a match and it contains two integers A and B, means A wins the match between A and B. And we define that if A wins B, and B wins C, then A wins C.

Output
For each test case, output a integer which represent the max possible number of queries that you can’t tell Jack.

Sample Input
3
3 3
1 2
1 3
2 3
3 2
1 2
2 3
4 2
1 2
3 4

Sample Output
0
0
4
 

No Comments

Sorry, the comment form is closed at this time.