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$ 还有连一条边出去,那么 ...
随机推荐
- [WCF] - Odata Service 访问失败,查看具体错误信息的方法
Issue 解决 为 Data Service 配置属性如下:[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = ...
- 剑指offer22:从上往下打印出二叉树的每个节点,同层节点从左至右打印。
1 题目描述 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 2 思路和方法 使用一个队列存放节点.先将根节点加入到队列中,然后循环遍历队列中的元素,遍历过程中,访问该节点的左右子节点,再将左 ...
- 机器学习支持向量机SVM笔记
SVM简述: SVM是一个线性二类分类器,当然通过选取特定的核函数也可也建立一个非线性支持向量机.SVM也可以做一些回归任务,但是它预测的时效性不是太长,他通过训练只能预测比较近的数据变化,至于再往后 ...
- C语言的关键字和数据类型
C语言关键字 C语言数据类型
- Android--圆角背景style
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...
- SPA项目首页导航+左侧菜单
Mock.js是个啥 前后端分离之后,前端迫切需要一种机制,不再需要依赖后端接口开发,而今天的主角mockjs就可以做到这一点 Mock.js是一个模拟数据的生成器,用来帮助前端调试开发.进行前后端的 ...
- Thread interrupted() 线程的中断
问题: 1.线程的中断方式. 2.为什么中断阻塞中的线程,会抛出异常. 代码示例: package com.hdwl.netty; public class ThreadInterrupted { p ...
- css文字截断
通过css将文字进行截断,截断部分使用省略号代替 .impleName{ max-width: 100%; /*最大宽度为当前元素的100%*/ display: inline-block; whit ...
- JavaDoc工具和Ideade javadoc工具
命令参考: javadoc -locale zh_CN -protected -notree -nonavbar -noindex -use -author -version -encoding UT ...
- 1.MVC基础-初识MVC,与WebForm比较
1.Net WebForm的开发模式