QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#9074. 二叉树

統計

有一个包含 $N$ 个节点的二叉树。 作为一名“树木杀手”,你昨天从那棵树上摘取了一些子树! 现在你后悔了。 你可能记得 $M$ 个具有不同根节点的子树的高度,但你能重建那棵树吗? 好吧,由于节点数量巨大,这可能对你来说很难。 你只需要检查你是否能做到! 顺便说一句,猜猜原来的树是否也是一棵完全二叉树!

输入格式

输入文件的第一行包含一个整数 $T$ ($1 \le T \le 100$),表示测试用例的数量。 接下来有 $2 \times T$ 行,每两行代表一个测试用例。 每个测试用例的第一行包含两个整数 $N, M$ ($1 \le N \le 10^9, 1 \le M \le 10^5$),含义如上所述。 第二行包含 $M$ 个数字,表示高度,范围在 $[1, 10^9]$。

输出格式

请准确打印 $T$ 行,每行对应一个测试用例的答案。 对于每个答案,首先打印 Case d: ($d$ 表示测试用例的序号),然后写出你的答案: 如果你的记忆无法构成一棵二叉树,打印 INVALID; 如果它可以构成一棵二叉树,那么检查它是否可能是一棵完全二叉树:IMPOSSIBLE(它一定不是一棵完全二叉树),POSSIBLE(它可能是一棵完全二叉树),DEFINITELY(它一定是一棵完全二叉树)。

样例

输入 1

5
1 1
1
1 1
2
2 1
2
2 2
1 2
15 3
3 3 3

输出 1

Case 1: DEFINITELY
Case 2: INVALID
Case 3: POSSIBLE
Case 4: POSSIBLE
Case 5: IMPOSSIBLE

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.