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 v.
For example, on the picture below you can see the result of applying two operations to the graph: adding 5.
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.
The first line contains a single integer 2≤n≤105) — the number of nodes.
Each of the next v. 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).
2 1 2
YES
3 1 2 2 3
NO
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<map> #include<set> #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #define fuck(x) cout<<#x<<" = "<<x<<endl; #define debug(a, x) cout<<#a<<"["<<x<<"] = "<<a[x]<<endl; #define ls (t<<1) #define rs ((t<<1)|1) using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn = 100086; const int maxm = 100086; const int inf = 0x3f3f3f3f; const ll Inf = 999999999999999999; const int mod = 1000000007; const double eps = 1e-6; const double pi = acos(-1); int n; int num[maxn]; int main() { scanf("%d",&n); for(int i=1;i<n;i++){ int x; scanf("%d",&x); num[x]++; scanf("%d",&x); num[x]++; } bool flag = true; for(int i=0;i<maxn;i++){ if(num[i]==2){ flag=false; } } if(flag){ printf("YES\n"); } else{ printf("NO\n"); } return 0; }