CF1879E Interactive Game with Coloring

题目描述

**这是一个交互题。** 给你一棵有 $n$ 个顶点的树;顶点 $1$ 是树的根。对于每一个 $i \in [2, n]$,$i$ 的父顶点是 $p_i$(满足 $p_i

输入格式

**输入** 第一行包含一个整数 $n$($3 \le n \le 100$)表示数的顶点。 第二行包含 $n-1$ 个整数 $p_2, p_3, \dots, p_n$ ( $1 \le p_i

输出格式

First, you have to print the coloring of the edges you've chosen as follows: - in the first line, print one integer $ k $ ( $ 1 \le k \le n - 1 $ ) — the number of colors you are using; - in the second line, print $ n-1 $ integers $ c_2, c_3, \dots, c_n $ ( $ 1 \le c_i \le k $ ), where $ c_i $ should be the color of the edge connecting $ p_i $ with $ i $ . Then, the game begins. At the start of each move, the jury program prints one of the following: - one integer $ 1 $ on a separate line, indicating that the chip has reached the root and you won; - one integer $ -1 $ on a separate line, indicating that either you didn't reach the root in $ d $ moves and lost, or you have done something incorrect (either the coloring you provided didn't meet the constraints, or your previous move is impossible); - or one integer $ 0 $ on a separate line, followed by a line containing $ k $ integers $ e_1, e_2, \dots, e_k $ , where $ e_i $ is the number of edges with color $ i $ incident to the current vertex. If you receive $ 1 $ or $ -1 $ , your program should terminate immediately, otherwise the verdict for your submission may be undefined. If you receive $ 0 $ followed by $ k $ integers $ e_1, e_2, \dots, e_k $ , you have to print one integer indicating the color you choose during the move (of course, $ e_i $ for that color should not be equal to $ 0 $ ). Don't forget to flush the output every time you print something!

说明/提示

在第一个示例中,从 $2$ 到 $n$ 的每个顶点都与根相连。因此,我们可以将所有边涂成相同的颜色 $1$ ,当游戏开始时,只有一条边与当前顶点相连(它将通向根)。 在第二个示例中,树是一条由 $4$ 个顶点组成的路径。我们必须把它的边涂成不同的颜色,因为我们可以证明只有两种颜色的策略是无法取胜的。