欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

图论水题但是没想到

程序员文章站 2022-06-23 23:38:26
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  ......

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.

input

the first line contains a single integer nn (2n1052≤n≤105) — the number of nodes.

each of the next n1n−1 lines contains two integers uu and vv (1u,vn1≤u,v≤n, uvu≠v), meaning that there is an edge between nodes uu and vv. 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 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:

图论水题但是没想到
图论水题但是没想到
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long ll;

ll in[200001]; 

int main(){
	ll n;
	while(cin>>n){
		memset(in,0,sizeof(in));
		for(ll i=1;i<=n-1;i++){
			ll x,y;
			cin>>x>>y;
			in[x]++;
			in[y]++;
		}
		ll sign=0;
		for(ll i=1;i<=n;i++){
			if(in[i]==2){
				sign=1;
				break;
			}
		}
		if(sign==1){
			cout<<"no"<<endl;
		}
		else cout<<"yes"<<endl;
	}
	return 0;
}