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 countries, numbered from to .
In the document, there is a list of different pairs of adjacent countries: For each (), the document states that country was adjacent to country 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 . Then, he draws the map as a grid of square cells, with rows numbered from to (top to bottom) and columns numbered from to (left to right).
He wants to color each cell of the map using one of colors. The colors are numbered from to , and country () is represented by color . The coloring must satisfy all of the following conditions:
- For each (), there is at least one cell with color .
- For each pair of adjacent countries , there is at least one pair of adjacent cells such that one of them is colored and the other is colored . 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 , and the pairs of adjacent countries are and , then the pair was not adjacent, and the following map of dimension 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 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 , and lower values of may result in a better score. However, finding the minimum possible value of is not required.