QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#14073. 求根

统计

有一个大小为 $n > 1$ 的满二叉树 $T$。需要注意的是,满二叉树是指每个节点都有 0 个或 2 个子节点的二叉树。

设 $r$ 表示 $T$ 的根节点。注意,当且仅当以 $r$ 为根时,$T$ 才满足满二叉树的定义。

设 $f$ 为一个函数,它接受一个节点 $u$,并返回若将 $T$ 的根改为 $u$ 时,$u$ 的所有子树大小的中位数。需要注意的是,偶数个元素的列表的中位数是中间两个元素的平均值。

满二叉树示例

例如,在图示的例子中,$r = 1$。$f(1) = 3$,因为以 1 为根时,它有两个大小分别为 1 和 5 的子树,其中位数为 3。$f(5) = 1$,因为若以节点 5 为根,它有 3 个子树,大小分别为 1、1 和 4。

选择 $T$ 的节点的一个子集 $S = \{u_1, u_2, \dots, u_m\}$,满足 $n/2 < m \le n$。给你列表 $[f(u_1), f(u_2), \dots, f(u_m)]$,你必须确定 $r$ 是否在 $S$ 中。

输入格式

第一行包含一个整数 $m$($2 \le m \le 2 \cdot 10^5$),表示 $S$ 的大小。

第二行包含 $m$ 个整数,表示 $S$ 中每个节点上 $f$ 的输出值。

保证生成测试数据时使用的是一棵合法的满二叉树 $T$。

输出格式

如果 $r$ 在 $S$ 中,输出 "yes";如果 $r$ 不在 $S$ 中,输出 "no"。如果根据给定信息无法确定 $r$ 是否在 $S$ 中,输出 "impossible"。

样例

输入样例 1

2
1 2

输出样例 1

yes

输入样例 2

4
1 2 6 6

输出样例 2

no

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.