题目http://codeforces.com/contest/1189/problem/D1

题意:给定一棵树,可以选择任意两个叶子节点对他们的路径增加一定的权值。

问对于给定的这棵树,是否可以得到任意形式的权值。

思路

只要有一个节点的度是2,那么这个节点连接的某一条边一定受到另一条边的控制。

 #include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<iostream> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef pair<int, int> pr; int n;
const int maxn = 1e5 + ;
int deg[maxn]; int main()
{
scanf("%d", &n);;
for(int i = ; i < n; i++){
int u, v;
scanf("%d%d", &u, &v);
deg[u]++;
deg[v]++;
}
int ans = true;
for(int i = ; i <= n; i++){
if(deg[i] == ){
ans = false;
break;
}
}
if(ans){
printf("YES\n");
}
else{
printf("NO\n");
}
return ;
}

codeforces#572Div2 D1---Add On A Tree【思维】的更多相关文章

  1. 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 y ...

  2. Codeforces Add on a Tree

    Add on a Tree time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. codeforces 1065F Up and Down the Tree

    题目链接:codeforces 1065F Up and Down the Tree 题意:给出一棵树的节点数\(n\)以及一次移动的最大距离\(k\),现在有一个标记在根节点1处,每一次可以进行一下 ...

  4. Codeforces 914H Ember and Storm's Tree Game 【DP】*

    Codeforces 914H Ember and Storm's Tree Game 题目链接 ORZ佬 果然出了一套自闭题 这题让你算出第一个人有必胜策略的方案数 然后我们就发现必胜的条件就是树上 ...

  5. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  6. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  7. D. Minimum Diameter Tree 思维+猜结论

    D. Minimum Diameter Tree 思维+猜结论 题意 给出一颗树 和一个值v 把该值任意分配到任意边上 使得\(\sum\limits_{i,j}p_{ij}=v\) 使得 这颗树任意 ...

  8. codeforces 764 C. Timofey and a tree(dfs+思维)

    题目链接:http://codeforces.com/contest/764/problem/C 题意:给出一个树,然后各个节点有对应的颜色,问是否存在以一个点为根节点子树的颜色都一样. 这里的子树颜 ...

  9. Codeforces 1189D2. Add on a Tree: Revolution

    传送门 首先可以证明一颗树合法的充分必要条件是不存在某个节点的度数为 $2$ 首先它是必要的,考虑任意一条边连接的两点如果存在某一点 $x$ 度数为 $2$ ,那么说明 $x$ 还有连一条边出去,那么 ...

随机推荐

  1. ubuntu下安装chrome浏览器和flash插件

    chrome浏览器可在Ubuntu软件中心里搜索并安装 falsh插件首先去官网下载合适的包然后,按照readme安装,执行sudo cp -r usr/* /usr 和sudo cp libflas ...

  2. 消息中间件——RabbitMQ(十)RabbitMQ整合SpringBoot实战!(全)

    前言 1. SpringBoot整合配置详解 publisher-confirms,实现一个监听器用于监听Broker端给我们返回的确认请求:RabbitTemplate.ConfirmCallbac ...

  3. STM32之串口波特率计算

    1.1 波特率结构框图 1.2 波特率寄存器示意图 1.3 波特率计算公式示意图 两图看出,串口波特率寄存器是一个32位,只用低16位,低16位又划分,低4位用来装小数,其他用来装整数. 波特率计算公 ...

  4. Python函数基础学习(定义、函数参数、递归函数)

    1.本程序是测试函数的基础.函数的参数.递归函数的测试. 函数的参数有: 必选参数.默认参数.可变参数.命名关键字参数和关键字参数 #!/usr/bin/python # -*- coding: ut ...

  5. OpenCV学习笔记3

    OpenCV学习笔记3 图像平滑(低通滤波) 使用低通滤波器可以达到图像模糊的目的.这对与去除噪音很有帮助.其实就是去除图像中的高频成分(比如:噪音,边界).所以边界也会被模糊一点.(当然,也有一些模 ...

  6. 网络地址转换(NAT)

    NAT是解决ipv4地址短缺的方案之一 NAT是将位于子网中的主机与外网连通,子网中所有的主机都可以通过路由器的网络地址转换访问外网.对于外网来说该路由器相当于一台完整的主机,子网内所有主机对外网的访 ...

  7. protobuf的使用(netty传输多种对象类型)

    重点是: 1.枚举DataType的定义 2.oneof的使用

  8. Angular Material 学习笔记 Chips

    依据 material guidelines, chips 可以用来做 filter https://material.io/design/components/chips.html#filter-c ...

  9. shellexecute的使用和X64判断

    bool RunConsoleAsAdmin(std::string appPath, std::string param, bool wait) { LOG_INFO << " ...

  10. C++ 去掉字符串的首尾空格和全部空格

    #include <iostream>#include <string>using namespace std; //去掉收尾空格string& ClearHeadTa ...