codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1188A1.md (2434B)


      1 Source: https://codeforces.com/problemset/problem/1188/A1
      2 
      3 A1. Add on a Tree
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems.
     22 
     23 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$.
     24 
     25 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$.
     26 
     27  ![](https://espresso.codeforces.com/9a005047cef808e8f768fec21c602f015eb7d1e9.png) 
     28 
     29 Is it true that for any configuration of real numbers written on edges, we can achieve it with a finite number of operations?
     30 
     31 Leaf is a node of a tree of degree $1$. Simple path is a path that doesn't contain any node twice.
     32 
     33 Input
     34 
     35 The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the number of nodes.
     36 
     37 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.
     38 
     39 Output
     40 
     41 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".
     42 
     43 Otherwise, output "YES".
     44 
     45 You can print each letter in any case (upper or lower).
     46 
     47 Examples
     48 
     49 Input
     50 
     51 ```
     52 2
     53 1 2
     54 ```
     55 
     56 Output
     57 
     58 ```
     59 YES
     60 ```
     61 
     62 Input
     63 
     64 ```
     65 3
     66 1 2
     67 2 3
     68 ```
     69 
     70 Output
     71 
     72 ```
     73 NO
     74 ```
     75 
     76 Input
     77 
     78 ```
     79 5
     80 1 2
     81 1 3
     82 1 4
     83 2 5
     84 ```
     85 
     86 Output
     87 
     88 ```
     89 NO
     90 ```
     91 
     92 Input
     93 
     94 ```
     95 6
     96 1 2
     97 1 3
     98 1 4
     99 2 5
    100 2 6
    101 ```
    102 
    103 Output
    104 
    105 ```
    106 YES
    107 ```
    108 
    109 Note
    110 
    111 In the first example, we can add any real $x$ to the value written on the only edge $(1, 2)$.
    112 
    113  ![](https://espresso.codeforces.com/b4976db0f2b8a8e152f330658128695dc4aa7a85.png) 
    114 
    115 In the second example, one of configurations that we can't reach is $0$ written on $(1, 2)$ and $1$ written on $(2, 3)$.
    116 
    117  ![](https://espresso.codeforces.com/45a1243252ed862906c45cef671596818e100580.png) 
    118 
    119 Below you can see graphs from examples $3$, $4$:
    120 
    121  ![](https://espresso.codeforces.com/beef651ef33a9e54c06701abf1fdf1c595d2434c.png)  ![](https://espresso.codeforces.com/23f4d75f481429b2d5626c7930aadc7f1e874d9f.png)