CF573C.Bear and Drawing

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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?

Limak 是一只正在学习绘画的小熊。人们通常从画房子、篱笆和花朵开始,但熊为什么要画这些呢?Limak 住在森林里,他决定画一棵树。

回忆一下,树是一种连通图,由 nn 个顶点和 n−1n-1 条边组成。

Limak 选择了一棵含有 nn 个顶点的树。他有一条无限长的纸带,纸带上两行平行排列的点。小熊希望将树的 nn 个顶点分别分配给纸带上 nn 个互不相同的点,使得任意两条边仅在它们的端点处相交——即所画出的树必须是平面图。下方展示了第一个样例测试的一个正确画法:

Limak 能否成功画出他所选定的这棵树?

输入格式

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 a__i and b__i (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i) denoting an edge between vertices a__i and b__i. It's guaranteed that given description forms a tree.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)。

接下来的 n−1n-1 行描述一棵树。其中第 ii 行包含两个以空格分隔的整数 aia_i 和 bib_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n,且 ai≠bia_i \neq b_i),表示顶点 aia_i 与 bib_i 之间存在一条边。保证所给描述构成一棵树。

输出格式

Print "Yes" (without the quotes) if Limak can draw chosen tree. Otherwise, print "No" (without the quotes).

如果Limak能够画出所选的树,则输出“Yes”(不带引号);否则,输出“No”(不带引号)。

输入输出样例

  • 输入#1

    8
    1 2
    1 3
    1 6
    6 4
    6 7
    6 5
    7 8

    输出#1

    Yes
  • 输入#2

    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

    输出#2

    No

输入解题思路,AI测评打分。不知道怎么写?

首页