#P13537. [IOI 2025] World Map

[IOI 2025] World Map

题目描述

Mr. Pacha, a Bolivian archeologist, discovered an ancient document near Tiwanaku that describes the world during the Tiwanaku Period (300-1000 CE). At that time, there were NN countries, numbered from 1 to NN.

In the document, there is a list of MM different pairs of adjacent countries:

$$\begin{aligned}(A[0], B[0]), (A[1], B[1]), \ldots, (A[M - 1], B[M - 1]).\end{aligned} $$

For each ii (0i<M0 \leq i < M), the document states that country A[i]A[i] was adjacent to country B[i]B[i] and vice versa. Pairs of countries not listed were not adjacent.

Mr. Pacha wants to create a map of the world such that all adjacencies between countries are exactly as they were during the Tiwanaku Period. For this purpose, he first chooses a positive integer KK. Then, he draws the map as a grid of K×KK \times K square cells, with rows numbered from 0 to K1K - 1 (top to bottom) and columns numbered from 0 to K1K - 1 (left to right).

He wants to color each cell of the map using one of NN colors. The colors are numbered from 1 to NN, and country jj (1jN1 \leq j \leq N) is represented by color jj. The coloring must satisfy all of the following conditions:

  • For each jj (1jN1 \leq j \leq N), there is at least one cell with color jj.
  • For each pair of adjacent countries (A[i],B[i])(A[i], B[i]), there is at least one pair of adjacent cells such that one of them is colored A[i]A[i] and the other is colored B[i]B[i]. Two cells are adjacent if they share a side.
  • For each pair of adjacent cells with different colors, the countries represented by these two colors were adjacent during the Tiwanaku Period.

For example, if N=3N = 3, M=2M = 2 and the pairs of adjacent countries are (1,2)(1, 2) and (2,3)(2, 3), then the pair (1,3)(1, 3) was not adjacent, and the following map of dimension K=3K = 3 satisfies all the conditions.

:::align{center} :::

In particular, a country does not need to form a connected region on the map. In the map above, country 3 forms a connected region, while countries 1 and 2 form disconnected regions.

Your task is to help Mr. Pacha choose a value of KK and create a map. The document guarantees that such a map exists. Since Mr. Pacha prefers smaller maps, in the last subtask your score depends on the value of KK, and lower values of KK may result in a better score. However, finding the minimum possible value of KK is not required.

Implementation Details

You should implement the following procedure:

std::vector<std::vector<int>> create_map(int N, int M, std::vector<int> A, std::vector<i
  • NN: the number of countries.
  • MM: the number of pairs of adjacent countries.
  • AA and BB: arrays of length MM describing adjacent countries.
  • This procedure is called up to 5050 times for each test case.

The procedure should return an array CC that represents the map. Let KK be the length of CC.

  • Each element of CC must be an array of length KK, containing integers between 11 and NN inclusive.
  • C[i][j]C[i][j] is the color of the cell at row ii and column jj (for each ii and jj such that 0i,j<K0 \leq i, j < K).
  • KK must be less than or equal to 240240.

输入格式

The first line of the input should contain a single integer TT, the number of scenarios. A description of TT scenarios should follow, each in the format specified below.

N M
A[0] B[0]
:
A[M-1] B[M-1]

输出格式

P
Q[0] Q[1] ... Q[P-1]

C[0][0] ... C[0][Q[0]-1]
:
C[P-1][0] ... C[P-1][Q[P-1]-1]

Here, PP is the length of the array CC returned by create_map, and Q[i]Q[i] (0i<P0 \leq i < P) is the length of C[i]C[i]. Note that line 3 in the output format is intentionally left blank.

2
3 2
1 2
2 3
4 4
1 2
1 3
2 4
3 4
3
3 3 3
2 3 3
2 3 2
1 2 1
7
7 7 7 7 7 7 7
2 1 3 3 4 3 4
2 1 3 3 3 3 3
2 1 1 1 3 4 4
2 2 2 1 3 4 3
1 1 1 2 4 4 4
2 2 1 2 2 4 3
2 2 1 2 2 4 4

提示

Example 1

Consider the following call:

create_map(3, 2, [1, 2], [2, 3])

This is the example from the task description, so the procedure can return the following map.

[
[2, 3, 3],
[2, 3, 2],
[1, 2, 1]
]

Example 2

Consider the following call:

create_map(4, 4, [1, 1, 2, 3], [2, 3, 4, 4])

In this example, N=4N = 4, M=4M = 4 and the country pairs (1,2)(1, 2), (1,3)(1, 3), (2,4)(2, 4), and (3,4)(3, 4) are adjacent. Consequently, the pairs (1,4)(1, 4) and (2,3)(2, 3) are not adjacent.

The procedure can return the following map of dimension K=7K = 7, which satisfies all the conditions.

[
[2, 1, 3, 3, 4, 3, 4],
[2, 1, 3, 3, 3, 3, 3],
[2, 1, 1, 1, 3, 4, 4],
[2, 2, 2, 1, 3, 4, 3],
[1, 1, 1, 2, 4, 4, 4],
[2, 2, 1, 2, 2, 4, 3],
[2, 2, 1, 2, 2, 4, 4]
]

The map could be smaller; for example, the procedure can return the following map of dimension K=2K = 2.

[
[3, 1],
[4, 2]
]

Note that both maps satisfy K/N2K / N \leq 2.

Constraints

  • 1N401 \leq N \leq 40
  • 0MN(N1)20 \leq M \leq \frac{N \cdot (N-1)}{2}
  • 1A[i]<B[i]N1 \leq A[i] < B[i] \leq N for each ii such that 0i<M0 \leq i < M.
  • The pairs (A[0],B[0]),,(A[M1],B[M1])(A[0], B[0]), \ldots, (A[M-1], B[M-1]) are distinct.
  • There exists at least one map which satisfies all the conditions.

Subtasks and Scoring

Subtask Score Additional Constraints
1 5 M=N1M = N - 1, A[i]=i+1A[i] = i + 1, B[i]=i+2B[i] = i + 2 for each 0i<M0 \leq i < M.
2 10 M=N1M = N - 1
3 7 M=N(N1)2M = \frac{N \cdot (N - 1)}{2}
4 8 Country 1 is adjacent to all other countries. Some other pairs of countries may also be adjacent.
5 14 N15N \leq 15
6 56 No additional constraints.

In subtask 6, your score depends on the value of KK.

  • If any map returned by create_map does not satisfy all the conditions, your score for the subtask will be 00.
  • Otherwise, let RR be the maximum value of K/NK/N over all calls to create_map. Then, you receive a partial score according to the following table:
Limits Score
6<R6 < R 00
4<R64 < R \leq 6 1414
3<R43 < R \leq 4 2828
2.5<R32.5 < R \leq 3 4242
2<R2.52 < R \leq 2.5 4949
R2R \leq 2 5656