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个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
随机推荐
- 微服务开源生态报告 No.4
「微服务开源生态报告」,汇集各个开源项目近期的社区动态,帮助开发者们更高效的了解到各开源项目的最新进展. 社区动态包括,但不限于:版本发布.人员动态.项目动态和规划.培训和活动. 非常欢迎国内其他微服 ...
- VIM中空格和TAB的替换
在.vimrc中添加以下代码后,重启vim即可实现按TAB产生4个空格:set ts=4 (注:ts是tabstop的缩写,设TAB宽4个空格)set expandtab 对于已保存的文件,可以使用 ...
- python开发资源链接
1.docker docker Windows版下载:https://oomake.com/download/docker-windows docker 英文官网:https://www.docker ...
- hdu1403 后缀数组
比较简单的应用. #include <stdio.h> #include <string.h> #define maxn 200002 int wa[maxn],wb[maxn ...
- hdu1536 sg打表
标记数组用bool型防止超时.输入的f[ ]要排序. #include<stdio.h> #include<string.h> #include<algorithm> ...
- ps学习教程
1.通道抠图:http://www.16xx8.com/photoshop/tongdaokoutu/
- JAVA高级特性--内部类
内部类概念 public class Outer{ class inner{ } } 特点 可以很好的实现隐藏,可以使用procted,private 可以直接访问外部类的所有成员 ,包括私有成员. ...
- 2019-8-31-cmd-如何跨驱动器移动文件夹
title author date CreateTime categories cmd 如何跨驱动器移动文件夹 lindexi 2019-08-31 16:55:58 +0800 2019-02-27 ...
- spring配置文件各个属性详解
一.引用外部属性文件 <bean id="propertyConfigurer" class="org.springframework.beans.factory. ...
- Logtail提升采集性能
默认性能限制 为防止滥用消耗过多机器资源,我们对默认安装的Logtail进行了一系列的资源限制.默认安装的Logtail最多日志采集速度为20M/s,20个并发发送. 其他资源限制请参考:启动参数 h ...