#P5260. [JSOI2013] 超立方体

    ID: 5990 远端评测题 3000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2013各省省选江苏Special Judge状压 DP

[JSOI2013] 超立方体

Background

A hypercube is an extension of a cube into higher-dimensional space (it becomes a square in 2D and a line segment in 1D). In theoretical computer science, a hypercube is often related to binary encoding. Will, who has done quite a bit of research in theoretical computer science, naturally has his own thoughts about hypercubes.

qwq

The figure above shows the shapes corresponding to hypercubes in 00 to 44 dimensions. Clearly, we can view each vertex of a hypercube as a point, and each edge as a graph edge. In this way, we get an undirected graph, which we call a hypercube graph.

Problem Description

A DD-dimensional hypercube graph has 2D2^D vertices. We label these vertices from 00 to 2D12^D - 1.

There is an interesting and important necessary and sufficient conclusion: there must exist a way of labeling such that, for any two adjacent vertices in the graph, their labels’ binary codes differ in exactly one bit.

In 2D and 3D, this can be understood intuitively as follows.

For 2D, we can place the square in the first quadrant so that its four vertices, in counterclockwise order, are (0,0)(0,0), (1,0)(1,0), (1,1)(1,1), (0,1)(0,1). Then treat each coordinate as a 2-bit binary number, and label these four points as 0,1,3,20, 1, 3, 2.

For 3D, similarly, we can make one vertex of the cube coincide with the origin, and make all edges parallel to the coordinate axes. Then determine the coordinates of the 8 points, and finally treat each 3D coordinate as a 3-bit binary number. For DD dimensions, do the same, and so on.

Now, given an undirected graph with NN vertices and MM edges (vertices are labeled from 00 to N1N - 1), Will wants to know whether this graph is isomorphic to a hypercube graph.

Input Format

The first line contains an integer QQ, meaning there are QQ queries in this input.

Then follow QQ queries. For each query, the input format is:

The first line contains two integers NN and MM. The next MM lines each contain two different integers x,yx, y, indicating that there is an undirected edge between vertex xx and vertex yy in the graph (0x,y<N0 \le x, y < N).

Output Format

  1. If the graph given in a query is not isomorphic to any hypercube graph, output 1-1.

  2. If it is isomorphic to some hypercube graph, please relabel these NN vertices, and output on this line NN integers separated by spaces. The ii-th integer denotes the new label of vertex ii in the original graph, such that after relabeling, the conclusion described in the statement is satisfied.

Note: Each line of the output file must either contain only one integer 1-1, or contain a permutation of NN numbers from 00 to N1N - 1. If there are multiple solutions, output any one.

3
2 2
0 1
1 0
4 4
0 1
1 2
2 0
0 3
8 12
2 3
2 6
7 6
1 7
4 1
3 4
0 2
7 3
5 6
5 1
5 0
4 0
-1
-1
0 6 1 5 4 2 3 7

Hint

Q3,N32768,M1000000Q \leq 3, N \leq 32768, M \leq 1000000.

Translated by ChatGPT 5