QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100

#442. Surreal Tree

Estadísticas

The input is read from the file surreal.in.

The first line contains a positive integer $N$, representing the number of test cases. Each test case is formatted as follows:

The first line is a positive integer $m$, representing the number of trees in the set. The $m$ trees are then provided in the following format:

  • A positive integer $n$, representing the number of nodes in the tree, with nodes labeled $1, 2, \dots, n$.
  • The next $n$ lines each contain two non-negative integers $l_i$ and $r_i$, separated by a space, representing the labels of the left and right children of node $i$, respectively. If a left (or right) child does not exist, $l_i$ (or $r_i$) is $0$. Leaf nodes satisfy $l_i = r_i = 0$.

The input is guaranteed to form a tree with node $1$ as the root. Note: Node labels are only for input convenience; any isomorphic trees are considered identical.

The $m$ input trees may contain isomorphic trees. If these duplicates are removed (keeping only one of each isomorphic type), they form a set of trees $\mathcal{T}$. You need to determine whether the set $\text{grow}(\mathcal{T})$ is almost complete.

Output

The output is written to the file surreal.out.

The output contains $N$ lines, each representing the answer to the corresponding test case. The $i$-th line should contain the string Almost Complete if the set $\text{grow}(\mathcal{T})$ is almost complete (i.e., only a finite number of trees cannot be generated by it), or No otherwise. Please pay attention to the spelling and capitalization of the output string.

Examples

Input 1

1
1
1
0 0

Output 1

Almost Complete

Note 1

This example contains only one test case, where the set $\mathcal{T}$ contains only a single tree consisting of a single node. Since a single node can have its only leaf node replaced to generate any tree, $\text{grow}(\mathcal{T})$ contains all trees and is naturally almost complete.

Input 2

1
3
3
2 3
0 0
0 0
2
2 0
0 0
2
0 2
0 0

Output 2

Almost Complete

Note 2

This example contains one test case where the set $\mathcal{T}$ contains three trees. It is easy to see that only the tree consisting of a single node is not in $\text{grow}(\mathcal{T})$, so it contains almost all trees and is therefore almost complete.

Input 3

1
2
2
2 3
0 0
0 0
2
2 0
0 0

Output 3

No

Note 3

This example contains one test case where the set $\mathcal{T}$ contains two trees. It is easy to see that for all $n \ge 2$, chain-like trees with $n$ nodes where every non-leaf node has only a right child are not in $\text{grow}(\mathcal{T})$. Thus, there are infinitely many trees not in $\text{grow}(\mathcal{T})$, and $\mathcal{T}$ is not almost complete.

Input 4

See surreal/surreal4.in and surreal/surreal4.ans in the contestant directory.

Output 4

See surreal/surreal4.in and surreal/surreal4.ans in the contestant directory.

Input 5

See surreal/surreal5.in and surreal/surreal5.ans in the contestant directory.

Output 5

See surreal/surreal5.in and surreal/surreal5.ans in the contestant directory.

Input 6

See surreal/surreal6.in and surreal/surreal6.ans in the contestant directory.

Output 6

See surreal/surreal6.in and surreal/surreal6.ans in the contestant directory.

Constraints

All data satisfies: $\sum n \le 2 \times 10^6$, $\sum m \le 2 \times 10^6$, $\max h \le 2 \times 10^6$, $T \le 10^2$. Here, $\sum n$ is the sum of the number of nodes of all trees in all test cases for a given test point; $\sum m$ is the total number of trees in all test cases; $\max h$ is the maximum height of all trees appearing in the test point (a tree with a single node has height 1).

Special properties:

  • Property 1: For every test case in this test point, $m \le 4$.
  • Property 2: For every test case in this test point, all trees in the set have the same height.
  • Property 3: For every test case in this test point, the set contains only chains (every non-leaf node has only one child).
  • Property 4: For every test case in this test point, the set contains only trees satisfying one of the following two conditions:
    • Every non-leaf node has only one child;
    • There are exactly two leaf nodes, they have the same parent, and all other nodes have exactly one child.
Test Point ID $N$ $\sum n$ $\sum m$ $\max h$ Special Property
1 100 $\le 1000$ $\le 1000$ $\le 1$ None
2 $\le 2$ Property 1
3
4 $\le 1000000$ $\le 1000000$ $\le 4$ None
5 $\le 5$ Property 2
6 $\le 8$ None
7 $\le 9$ Property 2
8 $\le 10$ None
9 $\le 1000000$ Property 3
10 20 $\le 1000$ $\le 100$ $\le 1000$ Property 4
11 $\le 2000$ $\le 2000$ $\le 2000$ Property 4
12 $\le 100000$ $\le 100000$ $\le 100000$ Property 4
13 $\le 200000$ $\le 200000$ $\le 200000$ Property 4
14 $\le 800$ $\le 200$ $\le 800$ None
15 $\le 1000$ $\le 100$ $\le 1000$ None
16 $\le 2000$ $\le 2000$ $\le 2000$ None
17 40 $\le 300000$ $\le 300000$ $\le 300000$ None
18 $\le 600000$ $\le 600000$ $\le 600000$ None
19 $\le 900000$ $\le 900000$ $\le 900000$ None
20 $\le 1200000$ $\le 1200000$ $\le 1200000$ None
21 $\le 1500000$ $\le 1500000$ $\le 1500000$ None
22 $\le 2000000$ $\le 2000000$ $\le 2000000$ None
23
24
25

Figure 1. Illustration of tree substitution

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.