#P6844. [CEOI 2019] Building Skyscrapers
[CEOI 2019] Building Skyscrapers
Description
On a 2D plane, there are grid cells where skyscrapers are planned to be built. The planned cell of the -th skyscraper is located at .
You may choose any construction order of the skyscrapers, but it must satisfy the following rules:
- Let the construction order be .
- For any , it must hold that skyscraper shares at least one common edge or a common corner with at least one previously built skyscraper.
- For any , it must hold that from the planned cell of skyscraper to the boundary of the 2D plane, there exists a path (you can move from one cell only to a cell that shares a common edge with it), and on this path there are no other skyscrapers except .
An integer is also given, indicating the output type:
- If , you need to construct any valid construction order.
- If , you need to construct the construction order such that is lexicographically largest.
Input Format
The first line contains an integer .
The second line contains an integer .
The next lines each contain two integers . Line indicates that the planned coordinates of the -th skyscraper are .
Output Format
The first line outputs a string YES or NO, indicating whether a feasible solution exists.
If a feasible solution exists, then output lines, each with one integer describing the order you construct.
- If , you need to construct any valid construction order.
- If , you need to construct the construction order such that is lexicographically largest.
3
2
0 0
0 1
0 2
YES
1
2
3
3
1
0 0
1 1
2 2
YES
2
3
1
2
1
0 0
0 2
NO
Hint
Sample Explanation
Sample 1 Explanation
These three skyscrapers form a line, so naturally there are the following solutions:
Because , output the first one.
Sample 2 Explanation
The only difference from Sample 1 is that the three skyscrapers form a diagonal line. The solutions are the same as in Sample 1, and since , output any one solution.
Sample 3 Explanation
The two skyscrapers do not touch each other, so it is naturally impossible to build them.
Constraints
For of the testdata, it is guaranteed that , , and .
The detailed subtask constraints and scores are shown in the table below:
| Subtask ID | Constraints | Score |
|---|---|---|
| 1 | and | |
| 2 | and | |
| 3 | and | |
| 4 | and | |
| 5 | ||
| 6 | , , and | |
| 7 |
Notes
This problem is translated from Central-European Olympiad in Informatics 2019 Day 1 T1 Building Skyscrapers。
Translated by ChatGPT 5
京公网安备 11011102002149号