CF1188A1.Add on a Tree

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

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.

注意:这是两个相似问题中的第一个。仅当您同时解决了这两个问题时,才可以对本题进行 Hack。

给定一棵包含 nn 个节点的树。初始时,所有边上均写有数字 00。在一次操作中,您可以任选两个不同的叶子节点 uu、vv,以及任意一个实数 xx,并将 xx 加到 uu 与 vv 之间唯一简单路径上的所有边所写的数值上。

例如,在下方图中,展示了对该图执行两次操作后的结果:第一次操作将 22 加到从节点 77 到节点 66 的路径上;第二次操作将 −0.5-0.5 加到从节点 44 到节点 55 的路径上。

请问:对于边上任意一组实数配置,是否总能通过有限次操作达到该配置?

叶子节点是指度数为 11 的树节点。简单路径是指不重复经过任何节点的路径。

输入格式

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

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

第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5)—— 节点的数量。

接下来的 n−1n-1 行,每行包含两个整数 uu 和 vv(1≤u,v≤n1 \le u, v \le n,且 u≠vu \neq v),表示节点 uu 与节点 vv 之间存在一条边。保证这些边构成一棵树。

输出格式

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

如果存在一种树的边上实数的配置,使得我们无法通过执行这些操作来实现,则输出 "NO"。

否则,输出 "YES"。

你可以以任意大小写(大写或小写)输出每个字母。

输入输出样例

  • 输入#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:

在第一个例子中,我们可以将任意实数 xx 加到唯一一条边 (1,2)(1, 2) 上所写的数值上。

在第二个例子中,我们无法达到的构型之一是:边 (1,2)(1, 2) 上写有 00,边 (2,3)(2, 3) 上写有 11。

下面展示了第 33、44 个例子中的图:

输入解题思路,AI测评打分。不知道怎么写?

首页