codeforces#572Div2 D1---Add On A Tree【思维】
题目: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【思维】的更多相关文章
- 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 ...
- Codeforces Add on a Tree
Add on a Tree time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- codeforces 1065F Up and Down the Tree
题目链接:codeforces 1065F Up and Down the Tree 题意:给出一棵树的节点数\(n\)以及一次移动的最大距离\(k\),现在有一个标记在根节点1处,每一次可以进行一下 ...
- Codeforces 914H Ember and Storm's Tree Game 【DP】*
Codeforces 914H Ember and Storm's Tree Game 题目链接 ORZ佬 果然出了一套自闭题 这题让你算出第一个人有必胜策略的方案数 然后我们就发现必胜的条件就是树上 ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- D. Minimum Diameter Tree 思维+猜结论
D. Minimum Diameter Tree 思维+猜结论 题意 给出一颗树 和一个值v 把该值任意分配到任意边上 使得\(\sum\limits_{i,j}p_{ij}=v\) 使得 这颗树任意 ...
- codeforces 764 C. Timofey and a tree(dfs+思维)
题目链接:http://codeforces.com/contest/764/problem/C 题意:给出一个树,然后各个节点有对应的颜色,问是否存在以一个点为根节点子树的颜色都一样. 这里的子树颜 ...
- Codeforces 1189D2. Add on a Tree: Revolution
传送门 首先可以证明一颗树合法的充分必要条件是不存在某个节点的度数为 $2$ 首先它是必要的,考虑任意一条边连接的两点如果存在某一点 $x$ 度数为 $2$ ,那么说明 $x$ 还有连一条边出去,那么 ...
随机推荐
- [SQL] - Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 问题之解决
场景: 使用 Oracle.DataAccess.dll 访问数据库时,OracleDataAdapter 执行失败. 异常: System.AccessViolationException was ...
- JDBC ORM(Object Relationship Database Mapping)
ORM=Object Relationship Database Mapping 对象和关系数据库的映射 简单说,一个对象,对应数据库里的一条记录 示例:根据id返回一个Hero对象 提供方法get( ...
- nginx与PHP编译configure
configure参数nginx和php是编译安装的关键.记录下来备用: php: ./configure --prefix=/usr/local/php --with-config-file-pat ...
- redis哈希表数据类型键的查询和删除命令
一.查询 命令名称:hget 语法:hget key field 功能:返回哈希表key中给定域field的值 返回值: 给定域的值. 当给定域不存在或是给定key不存在时,返回nil 命令名称:hg ...
- logback的使用和配置
参考:https://www.cnblogs.com/warking/p/5710303.html https://www.cnblogs.com 一.logback简介 1.logback: Log ...
- winfrom 集成krpano 项目 添加折线
C#.NET WinFrom开发之嵌入Google浏览器 (CefSharp) 引入静态页面 CefWebBrowser = new ChromiumWebBrowser("http://& ...
- 【转载】C#中使用OrderBy和ThenBy等方法对List集合进行排序
在C#的List操作中,针对List对象集合的排序我们可以使用OrderBy.OrderByDescending.ThenBy.ThenByDescending等方法按照特定的对象属性进行排序,其中O ...
- SQL SERVER-Login搬迁脚本
USE master GO IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL DROP PROCEDURE sp_hexadecimal GO CREATE PR ...
- TestNG并发执行用例详解和范例
前言 TestNG有多种并发方式支持,方法的并发,class级的并发,test级的并发等:根据实际应用可以灵活的配置和使用,下面分别对几种并发方法进行说明: 一.方法级并发 方法级并发即method级 ...
- 【DRF框架】序列化组件——字段验证
单个字段的验证 1.在序列化器里定义校验字段的钩子方法 validate_字段 2.获取字段的数据 3.验证不通过,抛出异常 raise serializers.ValidationError( ...