#P8176. [CEOI 2021] Wells
[CEOI 2021] Wells
Background
Translated from CEOI 2021 Day 2 T3. Wells.
Abusing the judging resources will result in your account being banned.
Problem Description
Given a tree with nodes and a positive integer , determine whether there exists a subset of vertices such that every path containing exactly vertices has exactly one vertex from this subset. Also, you need to find the number of such subsets modulo (output if none exist).
Input Format
The first line contains two integers and .
The next lines each contain two integers and , indicating that there is an undirected edge between node and node .
Output Format
The first line contains a string: output YES if it exists, otherwise output NO.
The second line contains an integer, the number of subsets that satisfy the condition. If none exist, output .
4 2
3 4
3 1
2 3
YES
2
8 3
7 3
1 3
7 8
5 1
4 6
7 2
3 6
NO
0
6 5
4 1
4 2
3 6
5 2
4 6
YES
10
Hint
Sample Explanation 1

The subsets that satisfy the condition are: , .
Sample Explanation 2

Sample Explanation 3

There is only one path of length , which contains nodes . Among these nodes, there must be exactly one in the subset, and whether node is in the subset makes no difference.
Therefore, all subsets that satisfy the condition are: , , , , , , , , , .
Constraints and Notes
For of the testdata: .
| Subtask | Score | Constraints |
|---|---|---|
Translated by ChatGPT 5