QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#12375. VERTeX

統計

You are given a tree with $n$ nodes, labeled $1, 2, \dots, n$. Each node $i$ ($1 \le i \le n$) has a positive integer weight $b_i > 0$. For every tree edge connecting nodes $u$ and $v$, the edge weight is $w_{uv} = b_u + b_v$.

Given the structure of the tree and the weight of each edge, you need to determine whether there exists a set of node weights that satisfies the conditions. If they exist, output any such set of node weights.

Input

The first line contains a positive integer $n$ ($1 \le n \le 2 \times 10^5$), representing the number of nodes.

The next $n-1$ lines each contain three integers $u, v, w_{uv}$ ($1 \le u, v \le n$, $1 \le w_{uv} \le 10^9$), representing a tree edge connecting nodes $u$ and $v$ with weight $w_{uv}$.

Output

If no such set of node weights exists, output a single line containing the string NO.

Otherwise, first output a single line containing the string YES, then output $n$ positive integers $b_1, \dots, b_n$ on the second line, representing the set of node weights you found. You must ensure that for all $1 \le i \le n$, $b_i \le 10^9$.

If there are multiple sets of weights that satisfy the conditions, you may output any one of them.

Examples

Input 1

5
1 2 5
1 3 4
2 5 7
3 4 2

Output 1

YES
3 2 1 1 5

Input 2

4
1 2 5
2 3 9
3 4 4

Output 2

NO

Note

For the first example, it can be verified that the given weights satisfy the conditions. Note that $w_{34} = b_3 + b_4 = 2$, so $b_3$ and $b_4$ must both be $1$, which then allows the weights of the other nodes to be determined.

For the second example, note that $b_2 + b_3 = w_{23} = 9 = w_{12} + w_{34} = b_1 + b_2 + b_3 + b_4$, which implies $b_1 + b_4 = 0$. This contradicts $b_1 > 0$ and $b_4 > 0$, therefore no such set of node weights exists.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.