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



There will be an integer T denoting the 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 in two integers R1 and R2, meaning that “employee R1 is lower than employee R2's rank”.



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)







5 6

2 0

2 4

1 4

1 2

3 2

4 0


5 4

1 0

2 0

3 2

4 2

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)"


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

hide comments
ankur2409: 2019-03-24 18:35:37

Use fast I/O and watch out for output pattern

saketag007: 2018-09-19 21:11:52

easy , solved after 2 WA. Just apply level order traversal.

ameyanator: 2018-04-25 13:52:52

Had fun while solving the question! However fast io doesnt work and scanf printf works which is kind of irritating!

rraj001: 2017-07-12 14:40:38

cin,cout with fast i/o

shubham2305: 2017-01-18 17:47:53

sort first by rank then by employ number
using cin.tie(0) will not work
use scanf(),printf(),
costed me some stupid wa and tles

aspro: 2016-06-04 05:22:26

use scanf,printf...avoid TLE

vimal: 2016-03-02 15:14:36

AC guys.. o/p ? for -
6 5
1 0
2 0
5 0
3 2
4 2

Abhinandan Agarwal: 2015-08-23 17:01:43

fastest sol in C++ :-)

Rishabh: 2015-06-12 09:57:30

DP ;)

BRAIN: 2015-06-08 18:03:07

Topological sorting

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