AtCoder Grand Contest 052
B
Tree Edges XOR
AtCoder
⌀ 2473
原题
← AC →
翻译中…

Problem Statement

翻译中…

You are given a tree with $N$ vertices, where $N$ is odd. The vertices are numbered from $1$ through $N$ and edges from $1$ through $N-1$. The edge $i$ connects vertices $u_i$ and $v_i$ and its initial weight is $w^1_i$.

翻译中…

You can perform the following operation any number of times:

翻译中…
  • Choose an edge $(u, v)$ of the tree, and suppose that its weight now is $w$. For every edge, which is incident to exactly one of $u$ and $v$, we XOR the weight of that edge with $w$ (if it was $w_1$, replace it with $w_1 \oplus w$).
翻译中…

Your goal is to reach the state where each edge $i$ has weight $w^2_i$. Determine if you can get to the goal by performing the operation above any number of times.

翻译中…

Constraints

翻译中…
  • $1 \le N \le 10^5$
  • $N$ is odd.
  • $1\le u_i, v_i \le N$
  • $u_i \neq v_i$
  • $0\le w^1_i, w^2_i < 2^{30}$
  • All values in input are integers.
  • The input represents a valid tree.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
u_1 v_1 w^1_1 w^2_1
u_2 v_2 w^1_2 w^2_2
\vdots
u_{N-1} v_{N-1} w^1_{N-1} w^2_{N-1}

翻译中…

Output

翻译中…

If you can get the goal weight assignment from the initial state, output YES. Otherwise, output NO. Note that the checker is case-insensitive: you can print letters in both uppercase and lowercase.

翻译中…

样例

Input #1
3
1 2 1 1
2 3 8 9
Output #1
YES
If you perform the operation on the edge $1$, the weight of the edge $2$ becomes $8 \oplus 1=9$.
Input #2
5
1 2 0 3
1 3 1 0
1 4 2 1
1 5 0 0
Output #2
NO
题目信息
题号
agc052_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。