RPLA - Answer the boss!

no tags 

Eloy is a hard worker man, however, he is constantly bullied by his superiors, molested by this, one day he was wondering in what “rank” you are, so you can bully the people with lower ranks, also to discover who can really bully Eloy!.

Now, given the number of employees and the number of relations between them, Eloy need you to output the “rank” which employee is in, being 1 the “boss” (not bullied by anybody) and the employee who are in these ranks

Input

There will be an integer T denoting the number of test cases, then, T test cases will follow. Each test case starts with two integers N and R, the number of employees and the number of relations between them. The next R lines consists of two integers R1 and R2, meaning that “employee R1 is lower than employee R2's rank”.

Output

You will output for each test case the string “Scenario #i:” where i is the test case you are analyzing, after that, you will print N lines, for each line you will output the rank of the employee and the employee itself, if there is the same rank for several employees, then output them lexicographically ordered (the first is the lower.)

Sample

Input:
2

5 6
2 0
2 4
1 4
1 2
3 2
4 0
 
5 4
1 0
2 0
3 2
4 2

Output:
Scenario #1:
1 0
2 4
3 2
4 1
4 3
Scenario #2:
1 0
2 1
2 2
3 3
3 4

Blank line between test cases for clarification and separation. Please note that can be more than one "boss" (not bullied by anybody.)

Constraints

1 <= N <= 1000; 1 <= R <= 10000


hide comments
without_name48: 2023-09-23 18:29:13

forgetting colon costed me 2 WA

metalavocado99: 2023-04-27 08:41:36

Who doesn't get AC in one go is an impostor
HEHEHEHEHEHEHAWWW

rituranjan: 2021-06-14 21:54:35

kahn's+bfs, use "\n" not endl and ios_base::sync_with_stdio(false);cin.tie(NULL);

kushgupta_19: 2020-11-10 13:32:03

Try this tc:
1
8 12
2 0
2 4
1 4
1 2
3 2
4 0
7 6
5 7
4 7
1 5
0 6
7 0
Output
Scenario #1:
1 6
2 0
3 7
4 4
4 5
5 2
6 1
6 3
Helped me in getting AC :)

tarkesh_9: 2020-07-23 11:37:16

Don't forget colon after "Scenario#i:", costed me 3 WA

sarthak_19: 2020-07-04 22:34:54

Tropological sort+Priority Queue=AC

aman005mishra: 2020-07-03 22:27:00

make sure to run your code on these test cases:
2
7 5
1 0
2 0
3 2
4 2
2 5
8 12
2 0
2 4
1 4
1 2
3 2
4 0
7 6
5 7
4 7
1 5
0 6
7 0

Solution:
Scenario #1:

1 0

1 5

1 6

2 1

2 2

3 3

3 4

Scenario #2:

1 6

2 0

3 7

4 4

4 5

5 1

5 2

6 3

abhishek55236: 2020-06-17 12:25:53

kahn's algo!!!

jenishmonpara: 2020-05-01 10:44:04

Just made the fastest submission with execution time 0.06 secs :)

coolio_1: 2020-03-05 17:28:25

TOPO + DP! AC in 1 go! Enjoyed solving this.


Added by:david_8k
Date:2012-04-12
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own Problem used for the RPL contest