Problem: This is an interactive problem.
Given a simple undirected graph with vertices numbered from to , your task is to color all the vertices such that for every color , the following conditions hold:
- The set of vertices with color is connected;
- , where is the number of vertices with color , and is the sum of degrees of vertices with color .
Initially, you are only given the number of vertices and the degree of each vertex.
In each query, you can choose a vertex . As a response, you will be given the -th edge incident to , if this is the -th query on vertex .
You are allowed to make at most queries.
An undirected graph is simple if it does not contain multiple edges or self-loops.
The degree of a vertex is the number of edges incident to it.
A set of vertices is connected if for every two different vertices , there is a path, which only passes through vertices in , that connects and . That is, there is a sequence of edges with such that
- , , and for every ; and
- and for every .
Note: In the example, there is only one test case.
In the test case, there are vertices with vertices of degree and vertex of degree . It is obvious that vertex is isolated, i.e., it does not connect to any other vertices.
A possible interaction is shown in the sample input and output, where "?" queries are made on vertex twice and vertex twice. According to the responses to these queries, we know that each of vertex and vertex connects to two vertices and .
A possible solution is shown in the sample output, where vertex and vertex are colored by , vertex and vertex are colored by , and vertex is colored by . It can be seen that this solution satisfies the required conditions as follows.
- For color , vertex and vertex are connected. Moreover, and ;
- For color , vertex and vertex are connected. Moreover, and ;
- For color , there is only one vertex (vertex ) colored by . Moreover, and .