CodeForce - 1189 D1. Add on a Tree (思维题)
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, vvand 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.
The first line contains a single integer nn (2≤n≤1052≤n≤105) — the number of nodes.
Each of the next n−1n−1 lines contains two integers uu and vv (1≤u,v≤n1≤u,v≤n, u≠vu≠v), meaning that there is an edge between nodes uu and vv. 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 = ;
const int maxm = ;
const int inf = 0x3f3f3f3f;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); int n;
int num[maxn]; int main() { scanf("%d",&n); for(int i=;i<n;i++){
int x;
scanf("%d",&x);
num[x]++;
scanf("%d",&x);
num[x]++;
}
bool flag = true;
for(int i=;i<maxn;i++){
if(num[i]==){
flag=false;
}
} if(flag){
printf("YES\n");
}
else{
printf("NO\n");
} return ;
}
最新文章
- pc/app 项目/功能设计
- 20135220谈愈敏Blog7_可执行程序的装载
- vs2015发现一个字符串拼接 bug
- 控件ListView
- 关于linux上pdf阅读器
- careercup-栈与队列 3.4
- UIAlertView与UIActionSheet
- 怎样让你的安卓手机瞬间变Firefox os 畅玩firefox os 应用
- hdu 5035 概率论
- STS安装
- [Linux] 关闭防火墙以及开放端口
- How to disable Microsoft Compatibility Telemetry
- Go语言判断if else语句
- whmcs之全民idc
- python之demo2----改编自python官方提供的turtle_yinyang.py画阴阳的demo
- virtualbox+vagrant学习-2(command cli)-23-vagrant version命令
- hdu 4559 涂色游戏(SG)
- C#获取picturebox图片路径
- 【lightoj-1024】Eid (高精度)
- ibatis源码学习4_参数和结果的映射原理