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

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

include

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

요약
N개 파일과 방향 포함 관계가 주어질 때, 모든 파일에 도달하도록 직접 포함해야 하는 파일의 최소 집합을 구하고, 크기가 같으면 번호 합이 최소인 집합을 출력한다.
난이도

보통10점 중 6점

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

문제

Short code is cool, reasonable, beautiful, and elegant. You love short code. Hence you want to make your code as short as possible. Several techniques are known to make your code shorter. Today, you focus on "includes" in your code.

There are NN files you must include to your code. The NN files are numbered as 11 through NN. Some of them also include others. If file aa includes file bb and file bb includes file cc, including aa into your code implies including bb and cc into your code. But including cc does not necessarily imply including aa or bb unless cc (indirectly) includes aa or bb.

You are given information about dependencies of NN files, ii-th of which describes file a_ia\_i includes b_ib\_i. From this information, your task is to determine the set of the minimum number of files you have to directly include in order to include all NN files indirectly, and output file numbers in the minimum set in ascending order. If such a set is not uniquely determined, output a set with the minimum sum of the file numbers in a set.

입력

The input consists of a single test case of the following format.

NN MM

a_1a\_1 b_1b\_1

⋮\vdots

a_Ma\_M b_Mb\_M

The first line consists of two integers NN and MM, where NN is the number of files (1≤N≤30,0001 ≤ N ≤ 30\\,000) and MM is the number of dependency information (0≤M≤5×1050 \le M \le 5 \times 10^5). The following MM lines represents each dependency, the ii-th of which contains two integers a_ia\_i and b_ib\_i, which means file a_ia\_i includes file b_ib\_i (1≤a_i≤N1 ≤ a\_i ≤ N, 1≤b_i≤N1 ≤ b\_i ≤ N). There is no duplicate dependency information, i.e. a_i≠a_ja\_i \ne a\_j or b_i≠b_jb\_i \ne b\_j hold for 1≤i<j≤M1 ≤ i < j ≤ M.

출력

Determine the minimum number of files that must be directly included in your code to include all files indirectly, and print file numbers in such a file set in ascending order. If there are multiple sets with the minimum size, output a set with the minimum sum of file numbers.

예제3

  1. 예제 1

    입력
    4 3
    2 1
    2 4
    3 1
    
    예상 출력
    2
    3
    
  2. 예제 2

    입력
    5 6
    2 1
    2 4
    3 1
    3 2
    5 1
    5 2
    
    예상 출력
    3
    5
    
  3. 예제 3

    입력
    9 11
    1 3
    2 4
    2 6
    4 1
    5 3
    5 6
    5 8
    6 8
    7 4
    8 1
    8 2
    
    예상 출력
    5
    7
    9