include
시간 제한2초메모리 제한1024 MB
N개 파일과 방향 포함 관계가 주어질 때, 모든 파일에 도달하도록 직접 포함해야 하는 파일의 최소 집합을 구하고, 크기가 같으면 번호 합이 최소인 집합을 출력한다.
문제
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 files you must include to your code. The files are numbered as through . Some of them also include others. If file includes file and file includes file , including into your code implies including and into your code. But including does not necessarily imply including or unless (indirectly) includes or .
You are given information about dependencies of files, -th of which describes file includes . 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 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.
The first line consists of two integers and , where is the number of files () and is the number of dependency information (). The following lines represents each dependency, the -th of which contains two integers and , which means file includes file (, ). There is no duplicate dependency information, i.e. or hold for .
출력
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.