Logo
(追記) (追記ここまで)

15203번 - Police Station 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB3221229041.860%

문제

A network of hyperspace highways is built in the galaxy. Each of the highways is a one-directional corridor which connects two planets. Galactic government wants to find a planet on which a police station will be built.

In order for the police to protect the whole galaxy, it must be possible to travel from the police station to every planet in the galaxy using the hyperspace highways network.

It is not necessary that the police can return back to the police station from any planet using the hyperspace highways. The police needs not to hurry on the way back, and so they can use slower ways than highways.

The government does not know how to deal with finding the suitable planet for the police station; therefore, they ask for your help

You are given the network of one-directional hyperspace highways. Find all planets from which it is possible to reach all other planets in the galaxy using some sequence of highways.

입력

The first line of the input contains two integers $N$ a $M$: the number of planets and the number of highways.

Then, $M$ more lines follow. Each contains two integers $A_i$ and $B_i$: the numbers of planets connected by $i$-th highway. Each of the highways is one-directional and can only be used to travel from the planet $A_i$ to the planet $B_i$.

  • It holds 1ドル \leq N, M \leq 10^6$.
  • For all $i$it holds 1ドル \leq A_i, B_i \leq N$ and $A_i \neq B_i$.
  • No two highways connect equal planets in the same direction. However, they can connect equal planets in the opposite direction.
  • Furthermore, in 30 % of the testcases $N \leq 10^3$ and $M \leq 3 \cdot 10^3$.

출력

Output two lines. The first line should contain the total number of planets which are suitable for the police station. The second line should contain a space-separated list of these planets in ascending order.

제한

예제 입력 1

5 6
1 3
1 4
4 2
2 1
2 5
5 4

예제 출력 1

4
1 2 4 5

예제 입력 2

3 2
1 3
2 3

예제 출력 2

0

힌트

출처

Camp > Czech, Polish and Slovak Preparation Camp > CPSPC 2017 1-1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /