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


-----Examples-----
Input
2
1 2

Output
YES
Input
3
1 2
2 3

Output
NO
Input
5
1 2
1 3
1 4
2 5

Output
NO
Input
6
1 2
1 3
1 4
2 5
2 6

Output
YES


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

 $8$ 

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

 [Image] 

 [Image]

Difficulty: competition

Starter code:

Solutions:
import getpass
import sys

if getpass.getuser() != 'frohenk':
    filename = 'half'
    # sys.stdin = open('input.txt')
    # sys.stdout = open('output.txt', 'w')
else:
    sys.stdin = open('input.txt')
    # sys.stdin.close()

import math
import string
import re
import random
from decimal import Decimal, getcontext
from collections import deque

mod = 10 ** 9 + 7


def ria():
    return [int(i) for i in input().split()]


n=ria()[0]
ar=[0]*n
for i in range(n-1):
    a,b=ria()
    a-=1
    b-=1
    ar[a]+=1
    ar[b]+=1
print('NO' if ar.count(2) else 'YES')

import sys
input = sys.stdin.readline

N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = list(map(int, input().split()))
    X[x-1].append(y-1)
    X[y-1].append(x-1)

for x in X:
    if len(x) == 2:
        print("NO")
        break
else:
    print("YES")




import sys
input = sys.stdin.readline

n=int(input())
E=[list(map(int,input().split())) for i in range(n-1)]

D=[0]*n

for x,y in E:
    D[x-1]+=1
    D[y-1]+=1

if 2 in D:
    print("NO")
else:
    print("YES")


import collections
def add_on_tree():
    n = int(input())
    edges = []
    for i in range(n-1): edges.append([int(x) for x in input().split()])
    graph = collections.defaultdict(set)
    for u, v in edges:
        graph[u].add(v)
        graph[v].add(u)
    ans = 'YES'
    for node in graph:
        if len(graph[node]) == 2:
            ans = 'NO'
            break
    print(ans)

add_on_tree()
return

n=int(input())
l=[0 for a in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split(' '))
    l[a-1]+=1
    l[b-1]+=1
for i in range(n):
    if l[i]==2:
        print('NO')
        return
print('YES')

from collections import defaultdict

n = int(input())
d = defaultdict(int)


for i in range(n-1):
    sa = input().split()
    d[sa[0]] += 1
    d[sa[1]] += 1

for v in list(d.values()):
    if v == 2:
        print('NO')
        return

print('YES')



n = int(input())

degrees = [0 for _ in range(n)]

for _ in range(n-1):
    u, v = tuple(map(int, input().rstrip().split()))
    degrees[u-1] += 1
    degrees[v-1] += 1

res = 'YES'

for d in degrees:
    if d == 2:
        res = 'NO'

print(res)


from collections import defaultdict

n = int(input())
edges = defaultdict(int)
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    edges[a] += 1
    edges[b] += 1

for key in edges:
    if edges[key] == 2:
        print('NO')
        return

print('YES')


n = input()
n = int(n)

edges = []
for i in range(n-1):
    edges.append(input())

graph = {}
for i in range(1,n+1):
    graph[i] = []

for edge in edges:
    x = edge.split(' ')
    x = [int(y) for y in x]
    x = list(x)

    graph[x[0]].append(x[1])
    graph[x[1]].append(x[0])

q = 0
for key, value in list(graph.items()):
    if len(value) == 2:
        q = 1
        break

if q == 1:
    print("NO")

if q == 0:
    print("YES")


n = int(input())
Graph = [0]*n
for i in range(1,n):
    data = [int(s) for s in input().split()]
    Graph[data[0]-1] += 1
    Graph[data[-1]-1] += 1
flag = True
for i in Graph:
    if i == 2:
        flag = False
if flag == True:
    print("YES")
else:
    print("NO")


n = int(input())

nodes = [0]*n

for i in range (0,n-1):
    for x in map(int,input().split()):
        nodes[x-1] += 1

if 2 in nodes:
    print("NO")

else:
    print("YES")


n = int(input())
d = [0] * (n + 1)
for i in range(n - 1):
    u, v = list(map(int, input().split()))
    d[u] += 1
    d[v] += 1
ans = 0
for i in range(n):
    if d[i + 1] == 2:
        ans += 1
if ans == 0:
    print("YES")
else:
    print("NO")


n=int(input())
t={}
class node(object):
	"""docstring for node"""
	def __init__(self):
		self.vois = []
	
	def insv(self,voi):
		self.vois.append(voi)

for i in range(1,n+1):
	t[i]=node()
for i in range(n-1):
	u,v=map(int,input().split())
	t[u].insv(v)
	t[v].insv(u)
for i in range(1,n+1):
	if len(t[i].vois)==2:
		print("NO")
		break
else:
	print("YES")

n=int(input())
List=[]
vertecies=[0]*n
for i in range(0,n-1):
  OP=[]
  OP=list(map(int, input().split()))
  List.append(OP)
  vertecies[OP[0]-1]=vertecies[OP[0]-1]+1
  vertecies[OP[1]-1]=vertecies[OP[1]-1]+1
#print(vertecies)
k=0
for i in range (0,n):
  if vertecies[i]==2:
    k=k+1
if k>0:
  print("NO")
else:
  print("YES")

n = int(input())
a, flag = [0] * (n + 1), False
for i in range(n - 1):
    u, v = [int(x) for x in input().split()]
    a[u] += 1
    a[v] += 1
for j in range(1, n + 1):
    if a[j] == 2:
        flag = True
if flag:
    print("NO")
else:
    print("YES")


import sys
N = int(input())
Edge = [[] for _ in range(N)]
Dim = [0]*N
for _ in range(N-1):
    a, b = map(int, sys.stdin.readline().split())
    a -= 1
    b -= 1
    Edge[a].append(b)
    Edge[b].append(a)
    Dim[a] += 1
    Dim[b] += 1
Leaf = [d for d in Dim if d == 1]
if [d for d in Dim if d == 2]:
    print('NO')
elif len(Leaf)*(len(Leaf) - 1)//2 < N - 1:
    print('NO')
else:
    print('YES')

from collections import Counter

n = int(input())

d = Counter()

for _ in range(n - 1):
    u, v = list(map(int, input().split()))
    d[u] += 1
    d[v] += 1

if any(x == 2 for x in list(d.values())):
    print("NO")
else:
    print("YES")


I = lambda : map(int,input().split())
n = int(input())
#li = list(I())
if n == 1 or n==2 :
    print("YES");return
if n==3 :
    print("NO");return
lii = [ [] for i in range (n+1)]
for i in range (n-1) :
    x , y = I()
    lii[x] += [y]
    lii[y] += [x]
pp = 0 
for i in range (1,n+1) :
    if len(lii[i]) == 1 :
        continue
    elif len(lii[i]) == 2 :
        pp = 1
        break
if pp == 1 :
    print("NO");return
print("YES");return        

t=int(input())
lst=[[] for c in range(t+1)]
for c in range(t-1):
    m,n=map(int,input().split())
    lst[m].append(n)
    lst[n].append(m)
for c in range(len(lst)):
    if len(lst[c])==2:
        print("NO")
        return
print("YES")

from collections import Counter
n = int(input())
counter = Counter()
for i in range(n - 1):
    a, b = map(int, input().split())
    counter.update([a, b])
if 2 in counter.values():
    print("NO")
else:
    print("YES")

n = int(input())
adj = [[] for i in range(n)]
for _ in range(n-1):
  u, v = map(int, input().split())
  adj[u-1].append(v)
  adj[v-1].append(u)

for v in adj:
  if len(v) == 2:
    print('NO')
    break
else:
  print('YES')

n=int(input())
l=[0]*(n+1)
for i in range(n-1):
    u,v=input().split()
    u,v=[int(u),int(v)]
    l[u]+=1
    l[v]+=1
l=list(set(l))
#print(l)
if len(l)<=2:
    print("YES")
elif l[2]==2:
    print("NO")
else:
    print("YES")


n = int(input())
counts = [0] * n

for _ in range(n-1):
	u, v = map(int, input().split())
	u -= 1
	v -= 1
	counts[u] += 1
	counts[v] += 1

all_possible = all(count != 2 for count in counts)

if all_possible:
	print("YES")
else:
	print("NO")

from collections import defaultdict
n = int(input())
graph = defaultdict(list)
flag=0
for i in range(n-1):
    a,b = list(map(int,input().split()))
    graph[a].append(b)
    graph[b].append(a)
for j in range(1,n+1):
    if(len(graph[j])==2):
        flag=1
        break
if(flag==1):
    print("NO")
else:
    print("YES")
    


n = int(input())
a = []
for i in range(n):
  a.append(0)
for i in range(n - 1):
  b, c = input().split()
  a[int(b) - 1] += 1
  a[int(c) - 1] += 1
if2 = False
for i in range(n):
  if a[i] == 2:
    if2 = True
if if2:
  print("NO")
else:
  print("YES")