Kernel Scheduler

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

요약
작업 의존 관계를 나타내는 방향 그래프에서 적어도 절반 이상의 간선을 남기면서 모든 사이클을 제거한다.
난이도

보통10점 중 7점

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

문제

You are developing the scheduling module for the new operating system. This module takes nn tasks to be executed and the dependencies between them and then puts them in a certain order for execution.

More formally, there are nn tasks numbered from 11 to nn. You are also given mm dependencies numbered from 11 to mm; ii-th of them is described by two numbers --- a_ia\_i and b_ib\_i, meaning that the task a_ia\_i should be executed before the task b_ib\_i.

In some cases, there are cyclical dependencies --- situations when according to the dependencies given some task t_1t\_1 should be executed before t_2t\_2, t_2t\_2 before t_3t\_3, \ldots, and t_k−1t\_{k-1} before t_kt\_k and t_kt\_k before t_1t\_1. Cyclical dependencies create a problem for scheduling, so you decided to remove some of the given dependencies in such a way that the resulting set does not contain any cyclical ones.

However, you still need to keep at least m/2m/2 original dependencies to preserve some of the original information. You are to write the program performing this task.

입력

  • One line containing the numbers nn and mm (2≤n≤1052 \le n \le 10^5, 1≤m≤3⋅1051 \le m \le 3 \cdot 10^5).
  • mm further lines, each containing two numbers a_ia\_i and b_ib\_i (1≤a_i,b_i≤n1 \le a\_i, b\_i \le n, a_i≠b_ia\_i \ne b\_i), describing the corresponding dependency between two tasks a_ia\_i and b_ib\_i.

출력

The first line should should contain YES in case the desired subset of dependencies exists, and NO otherwise.

In the YES case second line should contain the number kk of the selected dependencies (please note that kk should be at least m/2m/2) and the third line should contain kk numbers --- the ids of the selected dependencies. They are numbered from 11 to mm in the order given in the input.

예제3

  1. 예제 1

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

    입력
    2 5
    1 2
    1 2
    1 2
    2 1
    2 1
    
    예상 출력
    YES
    3
    1 2 3
    
  3. 예제 3

    입력
    4 4
    1 2
    2 3
    2 4
    3 4
    
    예상 출력
    YES
    4
    1 2 3 4