codeforces 573C Bear and Drawing
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.
Recall that tree is a connected graph consisting of n vertices and n - 1 edges.
Limak chose a tree with n vertices. He has infinite strip of paper with two parallel rows of dots. Little bear wants to assign vertices of a tree to some n distinct dots on a paper so that edges would intersect only at their endpoints — drawn tree must be planar. Below you can see one of correct drawings for the first sample test.
Is it possible for Limak to draw chosen tree?
The first line contains single integer n (1 ≤ n ≤ 105).
Next n - 1 lines contain description of a tree. i-th of them contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) denoting an edge between vertices ai and bi. It's guaranteed that given description forms a tree.
Print "Yes" (without the quotes) if Limak can draw chosen tree. Otherwise, print "No" (without the quotes).
8
1 2
1 3
1 6
6 4
6 7
6 5
7 8
Yes
13
1 2
1 3
1 4
2 5
2 6
2 7
3 8
3 9
3 10
4 11
4 12
4 13
No 题解:
codeforces 573C Bear and Drawing的更多相关文章
- Codeforces 385C Bear and Prime Numbers
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...
- Codeforces 385B Bear and Strings
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...
- E. Bear and Drawing
E. Bear and Drawing time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces 680D Bear and Tower of Cubes 贪心 DFS
链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...
- Codeforces 385C Bear and Prime Numbers(素数预处理)
Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...
- [Codeforces 639F] Bear and Chemistry (Tarjan+虚树)(有详细注释)
[Codeforces 639F] Bear and Chemistry(Tarjan+虚树) 题面 给出一个n个点,m条边的无向图(不保证连通,可能有自环和重边),有q次询问,每次询问给出p个点和q ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) C. Bear and Drawing
题目链接:http://codeforces.com/contest/573/problem/C题目大意:在两行无限长的点列上面画n个点以及n-1条边使得构成一棵树,并且要求边都在同一平面上且除了节点 ...
- Codeforces 791B Bear and Friendship Condition(DFS,有向图)
B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes in ...
- Codeforces 791A Bear and Big Brother(暴力枚举,模拟)
A. Bear and Big Brother time limit per test:1 second memory limit per test:256 megabytes input:stand ...
随机推荐
- enigma机的原理
注:本文修改自三思科学<ENIGMA的兴亡> ENIGMA ENIGMA看起来是一个装满了复杂而精致的元件的盒子.不过要是我们把它打开来,就可以看到它可以被分解成相当 ...
- winscp自动执行脚本
我们经常使用WinSCP工具通过sftp协议上传获取文件,本文描述通过bat批量处理文件. 首先,我们打开dos命令窗口使用 cd \d :D\WinSCP 打开WinSCP安装目录 上传文件: wi ...
- cookie操作大全
JavaScript中的另一个机制:cookie,则可以达到真正全局变量的要求. cookie是浏览器 提供的一种机制,它将document 对象的cookie属性提供给JavaScript.可以由J ...
- flumeng-kafka-plugin
github 参考地址:https://github.com/beyondj2ee/flumeng-kafka-plugin/tree/master/flumeng-kafka-plugin /* * ...
- 只对safari起作用的css hack
下面的css代码只对safari browser 起作用: .test { width: 200px; height:50px; background-color:red; padding-top: ...
- git上解决代码冲突
1.切换到master: git co master 2.拉最新代码:git pull origin master 3.删掉多余符号 4.切换到提交的分支:git br Txxxx 5.合并:git ...
- [HDU 2049] 不容易系列之(4)——考新郎 (错排问题)
不容易系列之(4)——考新郎 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2049 题目大意: 有N对新婚夫妇,其中所有的新娘站成一列,都盖上了红布. ...
- HDU-3473Minimum Sum
Problem Description You are given N positive integers, denoted as x0, x1 ... xN-1. Then give you som ...
- 利用NIO建立Socket服务器
传统的Java 的IO,利用Socket建立服务器,接收客户端连接,一般都是为每一个连接建立一个线程,如果连接数巨大,那么服务器开销也将巨大..NIO的原理,可以参照图:http://new.51ct ...
- htaccess 正则规则整理(转)
为了方便 htaccess 编写正则,这里整理了一下 htaccess 的正则规则. # —— 位于行首时表示注释. [F] —— Forbidden(禁止): 命令服务器返回 403 Forbidd ...