#P7202. [COCI 2019/2020 #1] Trobojnica
[COCI 2019/2020 #1] Trobojnica
Description
"Everything will be in flames once red, white, and blue start running through your veins." - Slaven Bilić.
In this task, we will study some polygons with colored sides (there are three colors in total). The vertices are numbered clockwise from to .
Your task is to find a triangulation of the polygon, i.e., split the polygon into triangles along diagonals, such that for every triangle in the triangulation, its three adjacent sides have three different colors, one of each color.
Input Format
The first line contains the integer as described in the statement.
The second line is an integer with exactly digits, describing the colors of the polygon sides. The first digit is the color of side , the second digit is the color of side , and so on. The -th digit is the color of side . Each digit will be one of .
Output Format
If there is no valid triangulation, output NE and terminate.
Otherwise, output DA on the first line, and then output each diagonal used in the triangulation together with its color on the next lines.
Each line should be in the format X Y C, where are the two endpoints of the diagonal and is its color index (). The order of and does not matter.
If there are multiple valid triangulations, output any one of them.
4
1212
DA
1 3 3
4
1213
NE
7
1223121
DA
1 3 3
3 5 1
5 7 3
7 3 2
Hint
Constraints
| Subtask | Points | Constraints |
|---|---|---|
Notes
The scoring for this problem follows the original COCI problem settings, with a full score of .
This problem uses an unofficial Special Judge. You are welcome to hack (you may send a private message or post directly).
Translated from COCI2019-2020 CONTEST #1 T4 Trobojnica.
Translated by ChatGPT 5
京公网安备 11011102002149号