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 ;
}
CodeForce - 1189 D1. Add on a Tree (思维题)的更多相关文章
- codeforce 266c Below the Diagonal 矩阵变换 (思维题)
C. Below the Diagonal You are given a square matrix consisting of n rows and n columns. We assume th ...
- D. Minimum Diameter Tree 思维+猜结论
D. Minimum Diameter Tree 思维+猜结论 题意 给出一颗树 和一个值v 把该值任意分配到任意边上 使得\(\sum\limits_{i,j}p_{ij}=v\) 使得 这颗树任意 ...
- Codeforces Add on a Tree
Add on a Tree time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- UVA.699 The Falling Leaves (二叉树 思维题)
UVA.699 The Falling Leaves (二叉树 思维题) 题意分析 理解题意花了好半天,其实就是求建完树后再一条竖线上的所有节点的权值之和,如果按照普通的建树然后在计算的方法,是不方便 ...
- UVA.679 Dropping Balls (二叉树 思维题)
UVA.679 Dropping Balls (二叉树 思维题) 题意分析 给出深度为D的完全二叉树,按照以下规则,求第I个小球下落在那个叶子节点. 1. 默认所有节点的开关均处于关闭状态. 2. 若 ...
- hdu5325 树的思维题
pid=5325">http://acm.hdu.edu.cn/showproblem.php? pid=5325 Problem Description Bobo has a tre ...
- ACM思维题训练 Section A
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
随机推荐
- Leetcode784.Letter Case Permutation字母大小写全排列
给定一个字符串S,通过将字符串S中的每个字母转变大小写,我们可以获得一个新的字符串.返回所有可能得到的字符串集合. 示例: 输入: S = "a1b2" 输出: ["a1 ...
- PHPCMS快速建站系列之 pc标签where中如何使用变量
{pc:content action="lists" catid="$catid" where="typeid='$t'" order=&q ...
- CSS面试题总结2(转)
1.你最喜欢的图片替换方法是什么,你如何选择使用. 图像替代,就是像我们在平时将文本添加到文本中,然后通过css隐藏文本并在它的位置上显示一个背景图片,这样,搜索引擎仍然可以搜到HTML文本,即使我们 ...
- Git同步Python代码
之前我们都是将代码保存到本地目录, 然后再上传到Git中,但如果针对在pycharm中的代码,就要换另一种方式了,下面简单介绍一下. 1.打开pycharm主界面,选择菜单栏VCS---checkou ...
- 自定义属性 —— data-*
一.基本概念 在HTML5中添加了data-*的方式来自定义属性,所谓data-*实际上上就是data-前缀加上自定义的属性名,使用这样的结构可以进行数据存放.使用data-*可以解决自定义属性混乱无 ...
- Win10系统使用Docker安装oracle并通过Navicat for oracle进行登录
一.安装Docker Linux系统可以直接采用命令进行Docker安装: Win7系统安装Dokcer实际通过Boot2Docker在Windows下安装一个VirtualBox来实现: Boot2 ...
- 前端基础☞CSS
css的四种引入方式 1.行内式 行内式是在标记的style属性中设定CSS样式.这种方式没有体现出CSS的优势,不推荐使用. <p style="background-color: ...
- Jmeter非命令行执行脚本
这次我们可以清晰地看到每个线程的执行情况. 这里是我们使用非 GUI 模式运行测试脚本时可以使用的一些命令: -h 帮助 -> 打印出有用的信息并退出 -n 非 GUI 模式 -& ...
- 00docker安装和简介
Docker是用于开发.装载和运行应用的开放平台.Docker项目的目标是实现轻量的操作系统级虚拟化解决方案,它提供了一种在容器中安全隔离地运行应用程序的方式.可以在宿主机上运行多个容器. Docke ...
- hihoCoder#1239 Fibonacci
#1239 : Fibonacci 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given a sequence {an}, how many non-empty s ...