Povjerenstvo | 프로그래밍의 벗 PivotOJ
PivotOJ

Povjerenstvo

시간 제한: 3000ms메모리 제한: 512MB출처: CHC 2022 Croatian Olympiad in InformaticsBOJ 25446

문제

Do you know how hard it is to choose a set of people for the problem selection committee? No? Well do you know who does? Mr. Malnar, of course. By observing human interactions, the all-knowing Mr. Malnar has decided what the ideal choice should look like.

A total of NN people are being considered for the committee and MM relations between them have been recorded. A relation is described by an ordered pair (a,b)(a, b) representing the fact that person aa dislikes person bb. Mr. Malnar defines a dislike circle to be a sequence of distinct people x1,x2,,xkx_1, x_2, \dots , x_k such that person xix_i dislikes person xi+1x_{i+1}, for each 1 ≤ i ≤ k (it is assumed that xk+1=x1x_{k+1} = x_1). Mr. Malnar noticed a peculiar property regarding the set of people in question: there is no dislike circle consisting of an odd number of people.

To minimize dissatisfaction with the choice of committee, Mr. Malnar is looking for a committee such that everyone within the committee agrees with each other and everyone outside of the committee is glad not to be in it. More precisely:

  • There must not be two people within the committee such that one person dislikes the other.
  • For each person outside the committee there should be someone in the committee who they dislike.

Can you find such a set of people?

입력

The first line contains positive integers NN and MM, the number of people and number of relations between them, respectively.

The ii-th of the following MM lines contains an ordered pair of positive integers aia_i and bib_i (1 ≤ a_i , b_i ≤ N), representing the fact that person aia_i dislikes the person bib_i. It holds that a_i ≠ b_i for all i=1,2,,Mi = 1, 2, \dots , M and no ordered pair is listed twice.

The given relations will be such that there is no dislike circle consisting of an odd number of people.

출력

If it is not possible to choose a set of people satisfying the given conditions, in the only line print -1.

Otherwise, in the first line print a positive integer KK (1 ≤ K ≤ N), the number of people in the committee. In the next line print KK distinct positive integers p1,p2,,pKp_1, p_2, \dots , p_K (1 ≤ p_i ≤ N), the indices of the people which make up the committee.

If there is more than one solution, output any one of them.

힌트

The set of chosen people is shown in the output of each test case.

The first example is a valid test case for the first subtask and for the second subtask.

The second example is not a valid test case for the first subtask, but it is valid for the second subtask.

The third example is not a valid test case for the first subtask nor for the second subtask.

예제

예제 1

입력
4 4
1 2
1 3
2 4
3 4
출력
2
4 1

예제 2

입력
4 4
1 2
2 3
3 4
4 1
출력
2
1 3

예제 3

입력
8 11
1 2
2 1
3 4
4 5
5 6
6 3
7 8
8 7
3 2
7 3
8 1
출력
3
1 3 5
코드를 제출하려면 로그인하세요.