luogu#P8173. [CEOI 2021] Newspapers

    ID: 7294 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2021Special JudgeCEOI(中欧)构造Ad-hoc

[CEOI 2021] Newspapers

Background

Translated from CEOI 2021 Day 1 T3. Newspapers.

Problem Description

Ankica and Branko play a chasing game on an undirected connected graph. The game consists of several rounds, and each round has the following two steps:

  • Ankica guesses which vertex Branko is currently at. Specifically, she guesses that Branko is at some fixed vertex. If she is correct, Branko is caught and the game ends. Otherwise:
  • Branko moves across one edge. In other words, Branko moves to an adjacent vertex. Note that he cannot stay in place.

Given the graph, determine whether Ankica can always catch Branko in a finite number of steps, no matter where Branko starts and how he moves.

More formally, denote Ankica’s guessing strategy by A=(a1,a2,,ak)A=(a_1,a_2,\dots,a_k), where aia_i is the vertex she guesses in her ii-th guess.

Similarly, denote Branko’s movement by B=(b1,b2,,bk)B=(b_1,b_2,\dots,b_k), where bib_i is his position before round ii. Moreover, for any two adjacent elements bib_i and bi+1b_{i+1} in BB (1i<k1\leq i<k), there must be an edge between bib_i and bi+1b_{i+1}. Note that AA has no such restriction.

We say Ankica’s strategy AA is successful if and only if for any valid BB, there exists i[1,k]i\in[1,k] such that ai=bia_i=b_i.

If such a strategy exists, output one with the minimum possible kk.

Input Format

The first line contains two integers NN and MM, representing the number of vertices and edges in the graph.

The next MM lines each contain two integers uiu_i, viv_i, indicating that there is an edge connecting uiu_i and viv_i.

The input guarantees that the graph has no multiple edges and no self-loops.

Output Format

If there is no successful strategy AA, output a single line containing the string NO.

Otherwise, the first line should output the string YES.

The second line should output the minimum kk for such a strategy.

The third line should contain kk integers, where the ii-th integer is aia_i.

7 6
1 2
1 3
1 4
1 5
1 6
1 7

YES
2
1 1

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

NO

Hint

Sample Explanation 1

捕获1.PNG

If Branko initially is at vertex 11, then he will be caught. Otherwise, he must move to vertex 11, and then he will be caught.

Sample Explanation 2

捕获2.PNG

If Branko initially is on the cycle (1,2,3)(1,2,3) and is not equal to a1a_1, then according to the subsequent aa, it is always possible to construct a BB that makes AA unsuccessful.

Subtasks

All testdata satisfy 1N10001\leq N\leq 1000, N1MN×(N1)2N-1\leq M\leq \frac{N\times (N-1)}{2}.

The Constraints for each subtask are as follows:

Subtask ID Points Constraint
11 1212 1N201\leq N\leq 20
22 88 1N10001\leq N\leq 1000, M=N1M=N-1, and every vertex u[1N1]u\in[1,N-1] has an edge to u+1u+1
33 8080 1N10001\leq N\leq 1000

Scoring

If you can only answer the first line correctly, you will get 50%50\% of the points for that test.

If for all tests where the answer is YES, you provide a correct strategy that is not necessarily minimal in kk, you will get 75%75\% of the points for that test. Note that the strategy you provide cannot exceed 5N5N rounds. It can be proven that any optimal strategy will not exceed this limit.

The score for each subtask equals the minimum score among the tests in that subtask.

Translated by ChatGPT 5