아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Cheat

시간 제한2초메모리 제한512 MB

요약
정점 i에서 i+1로 가는 간선이 항상 있는 방향 그래프에서 모든 사이클에 포함되는 정점을 나열하고, 사이클이 없으면 모든 정점을 나열합니다.
난이도

보통10점 중 7점

유형
그래프, DFS, 구현
정답자
아직 제출이 없습니다

문제

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 nn vertices numbered with integers from 11 to nn and specific property -- there is a directed edge from vertex ii to vertex i+1i + 1 for each valid ii.

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 Z≤50Z \le 50 is given, denoting number of testcases described in following lines. 

The first line of the test case contains two integers nn and mm, denoting the number of cities and roads. Each of the following mm lines two integers a_i,b_ia\_i, b\_i (a_i≠b_ia\_i \neq b\_i), denoting that there is a directed road from a_ia\_i to b_ib\_i. There can exist more than one road from a_ia\_i to b_ib\_i.

출력

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.

제한

  • n∈\[1,500,000],m∈\[0,500,000]n \in \[1, 500\\,000], m \in \[0, 500\\,000]
  • sum of nn and sum of mm over all testcases does not exceed 1,000,0001\\,000\\,000.

예제1

  1. 예제 1

    입력
    2
    4 4
    1 2
    2 3
    3 4
    4 2
    4 5
    1 2
    2 3
    3 4
    2 1
    4 3
    
    예상 출력
    3 2 3 4
    0