#C4126. Mystical Cut
Mystical Cut
Mystical Cut
You are given a tree with n vertices numbered from 1 to n and n − 1 edges. A Mystical Cut is defined as the removal of an edge such that one of the resulting connected components (a subtree) has an even number of vertices (i.e., its size is even), while not being the entire tree. Formally, if we denote the number of vertices in a subtree by s, a valid mystical cut exists if there is a subtree with s even and s ≠ n.
If the tree itself has an odd number of nodes, then it is impossible to obtain an even-sized subtree. Your task is to determine whether it is possible to perform a mystical cut. Output "YES" if such a cut exists, otherwise output "NO".
Note: The problem can be formally expressed by checking if there exists a node (other than the root) whose subtree has an even number of nodes. In LaTeX, the condition for a valid subtree rooted at node i is: \( subtree\_size(i) \equiv 0 \pmod{2} \) with \( subtree\_size(i) \neq n \).
inputFormat
The input is read from standard input (stdin) and has the following format:
n u1 v1 u2 v2 ... u(n-1) v(n-1)
Here, n (\(1 \leq n \leq 10^5\)) is the number of vertices in the tree, and each of the following n − 1 lines contains two integers u and v (1-indexed) representing an edge between vertices u and v.
outputFormat
Output a single line to standard output (stdout) containing either "YES" if a mystical cut is possible, or "NO" otherwise.
## sample4
1 2
1 3
1 4
YES