Codeforces Round 572 (Div. 2)
D1
Add on a Tree
Codeforces
未评级
原题
← CD2 →
翻译中…

Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems.

翻译中…

You are given a tree with $n$ nodes. In the beginning, $0$ is written on all edges. In one operation, you can choose any $2$ distinct leaves $u$, $v$ and any real number $x$ and add $x$ to values written on all edges on the simple path between $u$ and $v$.

翻译中…

For example, on the picture below you can see the result of applying two operations to the graph: adding $2$ on the path from $7$ to $6$, and then adding $-0.5$ on the path from $4$ to $5$.

翻译中…

image

翻译中…

Is it true that for any configuration of real numbers written on edges, we can achieve it with a finite number of operations?

翻译中…

Leaf is a node of a tree of degree $1$. Simple path is a path that doesn't contain any node twice.

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the number of nodes.

翻译中…

Each of the next $n-1$ lines contains two integers $u$ and $v$ ($1 \le u, v \le n$, $u \neq v$), meaning that there is an edge between nodes $u$ and $v$. It is guaranteed that these edges form a tree.

翻译中…

Output

翻译中…

If there is a configuration of real numbers written on edges of the tree that we can't achieve by performing the operations, output "NO".

翻译中…

Otherwise, output "YES".

翻译中…

You can print each letter in any case (upper or lower).

翻译中…

Note

翻译中…

In the first example, we can add any real $x$ to the value written on the only edge $(1, 2)$.

翻译中…

image

翻译中…

In the second example, one of configurations that we can't reach is $0$ written on $(1, 2)$ and $1$ written on $(2, 3)$.

翻译中…

image

翻译中…

Below you can see graphs from examples $3$, $4$:

翻译中…

image

翻译中…

image

翻译中…

样例

Input #1
2
1 2
Output #1
YES
InputCopy OutputCopy
Input #2
3
1 2
2 3
Output #2
NO
InputCopy OutputCopy
Input #3
5
1 2
1 3
1 4
2 5
Output #3
NO
InputCopy OutputCopy
Input #4
6
1 2
1 3
1 4
2 5
2 6
Output #4
YES
InputCopy OutputCopy
题目信息
题号
1189D1
时间限制
1 s
内存限制
256 MB

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