World Map

시간 제한1초메모리 제한2048 MB

요약
국가가 40개 이하인 그래프가 주어질 때, 같은 색 영역과 서로 다른 색의 인접 관계가 주어진 인접 그래프와 정확히 일치하도록 K x K 격자 색칠을 만든다. 모든 국가는 최소 한 칸을 차지한다.
난이도

어려움10점 중 8점

유형
그래프, 구현, 그리디, 완전 탐색
정답자
아직 제출이 없습니다

문제

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 11 to NN.

In the document, there is a list of MM different pairs of adjacent countries: (A\[0],B\[0]),(A\[1],B\[1]),…,(A\[M−1],B\[M−1]).(A\[0], B\[0]), (A\[1], B\[1]), \ldots, (A\[M-1], B\[M-1]). For each ii (0≤i<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 00 to K−1K - 1 (top to bottom) and columns numbered from 00 to K−1K - 1 (left to right).

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

  • For each jj (1≤j≤N1 \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.

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.

제한

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

예제

이 문제는 공개된 예제가 없습니다.