spoj#CHUNK1. Help Robin!!
Help Robin!!
Ra's al Ghul has attacked Gotham city and wants to kill Batman.
Now you, being Robin, want to help Batman by killing Ra's al Ghul and his army.
Ra's al Ghul has army of soldiers commanded by certain chiefs amongst them. The soldiers are motivated by them and are geared up to follow their instructions on one say.
You have to identify chief soldiers and use them to misdirect maximum no. of soldiers. This will reduce the chance of Ra's al Ghul to kill Batman.
Chief soldiers are those who are followed by max no of soldiers.
Once, identified you can play trick(magic) on them and misdirect soldiers following them.
You are given two integers N(denoting no of soldiers) and M(No of relation between 'N' soldier) .
Further, M lines contains two integers l1 and l2.(denoting l1 follows l2)
Constraints
1<=T<=100
1<=N<=9999
1<=M<=100000
1<=l1,l2<=N
Input
The first line of the input contains a single integer T denoting number of test cases. Description of each test case are as follows:
First line contain integers N(denoting no of soldiers) and M(No of pairs) .
Further, M lines contains two integers l1 and l2.(denoting l1 follows l2)
Output:
Print the soldiers in ascending order
Example
Input:1 5 4 1 5 1 2 3 1 4 1
Output:2 5
Explanation:
1st soldier follows 5th soldier
1st soldier follows 2nd soldier
3rd soldier follows 1st soldier
4th soldier follows 1st soldier
No of soldiers following 4 - 0
No of soldiers following 3 - 0
No of soldiers following 1 - 2 (4th and 3rd soldier)
No of soldiers following 2 - 3 (4th , 3rd and 1st soldier)
No of soldiers following 5 - 3( 4th , 3rd and 1st soldier)
Ans - 2,5
</p>
Contributed by: Paras Jain