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$ 还有连一条边出去,那么 ...
随机推荐
- 关于time_wait状态的理解
TIME_WAIT状态之所以存在,是为了保证网络的可靠性 有以下原因: 1.为实现TCP全双工连接的可靠释放 当服务器先关闭连接,如果不在一定时间内维护一个这样的TIME_WAIT状态,那么当被 ...
- CTeX error saving the project file
「Options -> ConfigurationWizard -> User Profiles > 点击 Create/Update User Profile 按钮」 重启WinE ...
- CSS样式三种形式
CSS基本表现形式只有三种:标签样式.Class类样式.ID样式 标签样式: 必须与HTML标签同名.仅仅影响同名标签 Class样式:可以在任何标签中使用: class="样式名" ...
- 使用Docker搭建svn服务器教程
svn简介 SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.互联网上很多版本控制服务已从CVS迁移到Subv ...
- vs2017环境下python包的安装
1)---vs已经下载了的才适用 1,鼠标放在右侧窗口python环境那里(如没有窗口,可点击最上方的“窗口”-“重置窗口”) 2,右键然后点击“查看所有python环境”,会弹出当前默认的环境(高亮 ...
- Spring AOP日志实现(四)--Bean的设计
日志Bean的设计: 类名及方法名:
- Angular Material 学习笔记 Chips
依据 material guidelines, chips 可以用来做 filter https://material.io/design/components/chips.html#filter-c ...
- 1.VBA Excel宏
Excel VBA宏 在这一章中,让我们了解如何编写一个简单的宏.让我们一步一步来. 第1步:首先,让我们能够在Excel20XX'开发'菜单.做同样的,点击 File >> Option ...
- Spring Cloud Alibaba学习笔记(8) - RocketMQ术语与概念
Topic 一类消息的集合,RocketMQ的基本订阅单位 部署结构 Name Server Name Server 为 producer 和 consumer 提供路由信息. 相对来说,namese ...
- 第二次用map23333
度熊所居住的 D 国,是一个完全尊重人权的国度.以至于这个国家的所有人命名自己的名字都非常奇怪.一个人的名字由若干个字符组成,同样的,这些字符的全排列的结果中的每一个字符串,也都是这个人的名字.例如, ...