Cheat
시간 제한2초메모리 제한512 MB
정점 i에서 i+1로 가는 간선이 항상 있는 방향 그래프에서 모든 사이클에 포함되는 정점을 나열하고, 사이클이 없으면 모든 정점을 나열합니다.
문제
Eryk with his partner called "Synek" are planning next spoof. Usually they swindle foreingers by offering false banknotes on low exchange rate, so they have to drive a lot around country to avoid recognition.
But to do this, they need to find a city where they can build a base. Cities and roads in their homeland can be viewed as a directed graph with vertices numbered with integers from to and specific property -- there is a directed edge from vertex to vertex for each valid .
Since they want to get back to base after each "trip" so they finds cycles really attractive. They decided to build a base in a city which lies on all cycles in their country. Because there can be multiple such cities, they asked you to write down all of them. If there is no cycle in the graph, they can build a base in any city.
Formally a cycle is a path starting and ending in the same city and visiting at least one other city (possibly multiple times).
입력
In the first line one integer is given, denoting number of testcases described in following lines.
The first line of the test case contains two integers and , denoting the number of cities and roads. Each of the following lines two integers (), denoting that there is a directed road from to . There can exist more than one road from to .
출력
For each test case your program should write the number of cities where Eryk and "Synek" can build base, followed by indices of those cities in ascending order.
제한
- sum of and sum of over all testcases does not exceed .