Surreal

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

In this problem, a tree is defined recursively: a single node gives rise to a tree, letting a tree to be the left (or right) child (of the root node) gives rise to a tree, and letting two trees to be left and right children (of the root node) gives rise to a tree. All structures generated using the above three rules in finite steps are called treesIn other words, the "tree" here refers to a non-empty, rooted binary tree that distinguishes left children and right children.

Two trees TTTT' are said to be isomorphic (TTT \equiv T') if they meet one of the following four conditions: (1) trees that are formed by one node are isomorphic; (2) if the root nodes of TT and TT' have only the left child, and their left subtrees are isomorphic, then TT and TT' are isomorphic; (3) if the root nodes of TT and TT' have only the right child, and their right subtrees are isomorphic, then TT and TT' are isomorphic; (4) if the root nodes of TT and TT' have both the left and right children, their left subtrees are isomorphic, and their right subtrees are also isomorphic, then TT and TT' are isomorphic. In other words, two trees are isomorphic if and only if they are the same when the nodes are unlabeled but we are distinguishing left children and right children.

It is obvious that the isomorphism of trees forms an equivalence relation over all trees, and we treat isomorphic trees as the same. We say two trees are different if and only if they are not isomorphic.

leaf of a tree is defined in the usual way: a leaf is a node without any children.

We say TT may be converted to TT' using a single-step substitution if we may replace a leaf node of TT with another tree T"T" and the resulting tree is isomorphic to TT', and we use TTT \to T' to denote TT may be converted to TT' using a single-step substitution. We say TT may be converted to TT' by substitution if there exists a natural number n1n \ge 1 and trees T_1,T_2,,T_nT\_1, T\_2, \dots, T\_n such that TT_1T_2T_nTT \equiv T\_1 \to T\_2 \to \dots \to T\_n \equiv T'. We use T\*TT \to^\* T' to denote TT may be converted to TT' by substitution.

In other words, a single-step substitution means we are deleting a leaf of the tree and putting a new tree at the corresponding position, just like a larger subtree growing at the original leaf node. If a tree TT may be converted to another tree TT' by substitution, then it just means we may use zero, one, or multiple rounds of single-step substitutions to convert TT into TT'. For example, any tree may be converted to itself by substitution, or in other words, for any tree TT, we have T\*TT \to^\* T. This figure shall help understand the meaning of substitution and single-step substitution:

In particular, we can convert any tree into infinitely many different trees by substitution, and a tree formed by a single node can be converted to any other tree by substitution. For a tree TT, we define grow(T)\operatorname{grow}(T) to be the set of trees that we may convert TT into by substitution, or in other words, grow(T)=TT\*T\operatorname{grow}(T) = \\{T' \mid T \to^\* T'\\}. Moreover, if T=T_1,T_2,,T_n\mathscr{T} = \\{T\_1, T\_2, \dots, T\_n\\} is a finite set of trees, then grow(T)\operatorname{grow}(\mathscr{T}) is defined to be the union of grow(T_i)\operatorname{grow}(T\_i) where i=1,2,,ni = 1, 2, \dots, n. So we have grow(T)=_T_iTgrow(T_i)\operatorname{grow}(\mathscr{T}) = \bigcup\limits\_{T\_i \in \mathscr{T}}\operatorname{grow}(T\_i).

We may treat grow(T)\operatorname{grow}(\mathscr{T}) as the set of trees the trees in set T\mathscr{T} can grow into. In other words, the set of trees that trees in T\mathscr{T} can grow into includes all trees that may be converted into from some TTT \in \mathscr{T} by substitution. We may call a set of trees a forest. Not rigorously speaking, the new forest that a given forest can grow into are all the trees in the given forest and all possible trees that a tree in the given forest may grow into. It is obvious that the forest a non-empty forest can grow into is an infinite forest, but the infinite forest, or in other words, grow(T)\operatorname{grow}(\mathscr{T}), does not necessarily contain all the trees. Moreover, it does not have to contain "nearly all" trees.

We say a forest is almost complete (or in other words, contains almost all trees) if there are only finitely many trees are not in the forest. For a finite forest T\mathscr{T}grow(T)\operatorname{grow}(\mathscr{T}) may contain all trees, contain almost all trees, or there are infinitely many trees not in the forest. For a given finite set of trees T\mathscr{T}, there exists an efficient algorithm to decide whether grow(T)\operatorname{grow}(\mathscr{T}) is almost complete, i.e., there are only finitely many trees that trees in T\mathscr{T} cannot grow into.

The problem asks given a finite set of trees T\mathscr{T}, whether there exists only finitely many trees TT satisfying Tgrow(T)T \notin\operatorname{grow}(\mathscr{T})Tgrow(T)T \notin\operatorname{grow}(\mathscr{T}) simply means there does not exist a TTT' \in \mathscr{T} such that T\*TT' \to^\* T.

입력

Each test case contains multiple instances. The first line contains a positive integer TT. There are TT instances following, and each instance is specified in the following format: the first line is an integer mm denoting the number of trees in the set. We will specify the mm trees using the following format: the first line is an integer nn denoting the number of nodes in the tree. The nodes are numbered 1,2,,n1, 2, \dots, n. The following nn lines contain two non-negative integers each, and the ii-th line contains l_i,r_il\_i,r\_i separated by a space denoting the left child and the right child of node ii. If the left or the right child does not exist, then l_il\_i or r_ir\_i is equal to

  1. Of course, the leaf nodes satisfy l_i=r_i=0l\_i = r\_i = 0. The input guarantees that it will be a tree with node 1 being the root. Please note that the labels of the nodes are for convenience only, and isomorphic trees are considered to be the same.

There may be isomorphic trees in the mm trees of an instance. If we remove the duplicate trees (i.e. we only keep one tree for each isomorphism class), they shall form a set T\mathscr{T}. You need to decide whether grow(T)\operatorname{grow}(\mathscr{T}) is almost complete.

출력

The output contains TT lines specifying the answers to the TT instances. The ii-th line contains a string: if in the ii-th instance, the mm trees in the input grow into an almost complete forest (or in other words, there are only finitely many trees the trees specified in the instance cannot grow into), output Almost Complete. Otherwise, output No. Please pay attention to spelling and capitalization.

제한

For all test cases, n2×106\sum n \le 2 \times 10^6m2×106\sum m \le 2 \times 10^6maxh2×106\max h \le 2 \times 10^6T102T \le 10^2. Here, n\sum n denotes the sum of numbers of nodes of the trees in the instances occurring in a test case, m\sum m denotes the sum of number of trees occurring in the instances in a test case, maxh\max h denotes the maximum height of trees occurring in the particular test case (a tree with only one node has height 1).