Alice challenges Bob to a puzzle! Alice is situated on an undirected graph consisting of
Suppose Alice is at node
. If , she stops. Otherwise, she considers the set of all edges connected to node , excluding the edge she just travelled on, if any. If is empty, she stops. Otherwise, she can choose to walk along the lowest or highest weight edge in . Note that all edge weights are distinct so there are no ties.
Alice claims that no matter how the edges are weighted, she always has a strategy to never reach node
Constraints
Subtask 1 [10%]
The graph is a tree.
Subtask 2 [20%]
Every node has degree at least
Subtask 3 [70%]
No additional constraints.
Input Specification
The first line contains two integers
The next
Output Specification
On the first line, output either YES
or NO
, indicating whether or not there exists an assignment of edge weights that forces Alice to always reach node
If such an assignment exists, output
Scoring
For each test file:
If you do not correctly determine if an assignment of edge weights exists, you will receive a score of Wrong Answer
verdict.
Otherwise, on each test case where an assignment is possible, your score for the test file is determined as follows:
You will receive full points if you output an valid assignment of edge weights that is fully correct and
Your final score within a subtask will be the minimum score over all tests in that subtask.
Sample Input 1
5 5
1 2
1 3
1 4
2 5
3 5
Sample Output 1
YES
1
8
4
2
6
Explanation for Sample 1
We can weight the edges to obtain the following graph:
Starting from node
Sample Input 2
5 7
1 2
2 3
3 4
4 2
4 2
2 5
5 1
Sample Output 2
YES
1
2
3
4
5
6
7
Explanation for Sample 2
We can weight the edges to obtain the following graph:
It can be shown that Alice must always reach node
Sample Input 3
4 5
1 2
1 3
2 4
3 4
3 2
Sample Output 3
NO
Explanation for Sample 3
It can be proven that no matter how we weight the edges, there exists a strategy for Alice to never reach node
Comments