luogu#P7929. [COCI 2021/2022 #1] Logičari
[COCI 2021/2022 #1] Logičari
Problem Description
Given a unicyclic graph with vertices, you now need to color some vertices so that every vertex has exactly one adjacent vertex (excluding itself) that is colored. Find the minimum number of colored vertices, or report that there is no solution.
Input Format
The first line contains an integer .
The next lines each contain two integers , meaning there is an edge between and .
Output Format
Output the minimum number of colored vertices, or report that there is no solution. If there is no solution, output -1.
4
1 2
2 3
3 4
4 1
2
3
1 2
2 3
3 1
-1
7
1 2
2 3
3 4
4 5
5 6
6 7
2 4
4
Hint
Sample Explanation
Sample 1 Explanation
You can color vertices and .
Sample 2 Explanation
If there is one colored vertex, then the colored vertex will have no colored adjacent vertex.
If there are two colored vertices, then an uncolored vertex will have two colored adjacent vertices.
Constraints
For all testdata, , .
| Subtask | Special Constraints | Score |
|---|---|---|
| The degree of every vertex is | ||
| No special constraints |
Notes
The total score for this problem is points.
This problem is translated from T3 Logičari of Croatian Open Competition in Informatics 2021/2022 Contest #1.
Translated by ChatGPT 5