luogu#P8173. [CEOI 2021] Newspapers
[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 , where is the vertex she guesses in her -th guess.
Similarly, denote Branko’s movement by , where is his position before round . Moreover, for any two adjacent elements and in (), there must be an edge between and . Note that has no such restriction.
We say Ankica’s strategy is successful if and only if for any valid , there exists such that .
If such a strategy exists, output one with the minimum possible .
Input Format
The first line contains two integers and , representing the number of vertices and edges in the graph.
The next lines each contain two integers , , indicating that there is an edge connecting and .
The input guarantees that the graph has no multiple edges and no self-loops.
Output Format
If there is no successful strategy , output a single line containing the string NO.
Otherwise, the first line should output the string YES.
The second line should output the minimum for such a strategy.
The third line should contain integers, where the -th integer is .
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

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

If Branko initially is on the cycle and is not equal to , then according to the subsequent , it is always possible to construct a that makes unsuccessful.
Subtasks
All testdata satisfy , .
The Constraints for each subtask are as follows:
| Subtask ID | Points | Constraint |
|---|---|---|
| , , and every vertex has an edge to | ||
Scoring
If you can only answer the first line correctly, you will get 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 , you will get of the points for that test. Note that the strategy you provide cannot exceed 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