CF1188A1.Add on a Tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn nodes. In the beginning, 00 is written on all edges. In one operation, you can choose any 22 distinct leaves uu , vv and any real number xx and add xx to values written on all edges on the simple path between uu and vv .

For example, on the picture below you can see the result of applying two operations to the graph: adding 22 on the path from 77 to 66 , and then adding 0.5-0.5 on the path from 44 to 55 .

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 11 . Simple path is a path that doesn't contain any node twice.

输入格式

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

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

输出格式

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).

输入输出样例

  • 输入#1

    2
    1 2
    

    输出#1

    YES
  • 输入#2

    3
    1 2
    2 3
    

    输出#2

    NO
  • 输入#3

    5
    1 2
    1 3
    1 4
    2 5
    

    输出#3

    NO
  • 输入#4

    6
    1 2
    1 3
    1 4
    2 5
    2 6
    

    输出#4

    YES

说明/提示

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

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

Below you can see graphs from examples 33 , 44 :

首页