QOJ.ac

QOJ

حد الوقت: 3.5 s حد الذاكرة: 256 MB مجموع النقاط: 10

#6049. Counter-demonstration [B]

الإحصائيات

Every year, the $P = NP$ Equality Parade takes place in Bitowice. It is an event where people who believe that for every language $L$ for which there exists a non-deterministic Turing machine recognizing $L$ in a polynomial number of steps, there also exists a deterministic Turing machine recognizing that language in a polynomial number of steps*, manifest their views to society.

Previous editions of the Parade were peaceful—participants at most shouted "3-SAT is easy!" or held banners with pseudocode for the latest polynomial "algorithms" finding a Hamiltonian cycle, without attracting much interest from passersby. This year, the organizers of the Parade decided to draw the attention of Bitowice residents and plan to chant more shocking slogans (somewhat true if $P = NP$), including "Our money is not safe!" and "Our privacy is at risk!".

Officers of the Bitowice Security Agency (ABB) fear that the content proclaimed by the Parade participants might cause residents to massively withdraw their money from banks and delete their accounts from social media portals, which the ABB uses for surveillance of the population. In short, there is a suspicion that the situation in Bitowice will be destabilized.

To prevent this destabilization, ABB officers intend to organize a counter-manifestation promoting the belief in the inequality $P \neq NP$. At the same time, they plan to peacefully prevent the Parade from passing. The ABB intends to start the counter-manifestation suddenly at one of the intersections located on the Parade's route. Unfortunately, the exact route of the $P = NP$ Equality Parade is kept secret until the very end, and the agency needs to prepare the counter-manifestation site in advance. The ABB only received a tip that the Parade will start at a certain intersection, will run along a certain non-zero number of roads, and will eventually return to the starting point. Your first task is to perform a preliminary verification of this information, i.e., to check whether the Bitowice road infrastructure allows for the existence of such a route. Furthermore, the agents are wondering if there are any intersections through which the Parade's route must pass if the information is confirmed. They have asked you to find all such intersections—from them, they will choose the most convenient location for the counter-manifestation (if no such intersections exist, the ABB will proceed to plan B).

There are $n$ intersections in Bitowice connected by one-way roads. Since motor vehicles are also part of the Parade, we assume that the Parade can only move along the roads in accordance with their direction.

Input

The first line of the input contains two integers $n$ and $m$ ($2 \le n \le 500\,000$, $1 \le m \le 1\,000\,000$), denoting the number of intersections and the number of roads in Bitowice, respectively. The intersections are numbered with integers from $1$ to $n$. The next $m$ lines describe the Bitowice roads. The $i$-th of these lines contains two integers $a_i$ and $b_i$ ($1 \le a_i, b_i \le n, a_i \neq b_i$), meaning that the $i$-th road leads from the intersection numbered $a_i$ to the intersection numbered $b_i$. No ordered pair $(a_i, b_i)$ will repeat.

Output

If it is not possible to organize the Parade so that it follows a route consistent with the information in the possession of the ABB, output a single line containing the word NIE. Otherwise, output two lines. The first line should contain the number $k$ denoting the number of intersections through which the Parade's route will certainly pass. The second line should contain $k$ numbers which are the identifiers of these intersections in increasing order (if $k = 0$, the second line should be left empty).

Examples

Input 1

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

Output 1

2
2 3

Input 2

3 2
1 2
2 3

Output 2

NIE

*More information on the problem concerning the $P = NP$ equality can be found at http://en.wikipedia.org/wiki/P_versus_NP_problem.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 1
IDTypeStatusTitlePosted ByLast UpdatedActions
#439General DiscussionOpen翻译Kevin53072025-12-22 16:42:13View

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.