Error
|
|
---|---|
@Ibrahim Nash | 5765 |
@blackshadows | 5715 |
@akhayrutdinov | 5111 |
@mb1973 | 4993 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 1278 |
@bt8816103042 | 739 |
@rohitanand | 495 |
@codeantik | 479 |
@shalinibhataniya1097 | 472 |
@amrutakashikar2 | 464 |
@thealchemist627 | 456 |
@akashkale117 | 453 |
@shivanandp12345678910 | 453 |
@dalwainazism125 | 453 |
@SherlockHolmes3 | 447 |
Complete Leaderboard |
Given a directed graph with n nodes. If there is an edge from u to v then u depends on v. Our task is to find out the sum of dependencies for every node.
Example:
For the graph in diagram, A depends on C and D i.e. 2, B depends on D i.e. 1, C depends on D i.e. 1
and D depends on none.
Hence answer -> 0 + 1 + 1 + 2 = 4
Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. The first line of each test case contains two integers N and E denoting the no of vertices and edges of the graph. Then in the next line are E pairs u and v denoting an edge from u to v.
Output:
For each test case in a new line print the required output.
Constraints:
1<=T<=100
2<=N<=150
1<=E<=150
Example:
Input:
2
4 4
0 2 0 3 1 3 2 3
4 3
0 2 0 1 0 3
Output:
4
3
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes