#P6644. [CCO 2020] Travelling Salesperson
[CCO 2020] Travelling Salesperson
Description
There is a complete graph with vertices. Every edge has weight , and each edge is either red or blue.
For each vertex, you need to construct a path that starts from that vertex, visits every vertex at least once, and has the minimum possible total edge weight.
To make it harder, switching from one edge to another edge of a different color costs one ticket, and you only have one ticket.
Input Format
The first line contains an integer .
The next lines each contain a string. The string on line is . If is R, then the edge from to is red; otherwise, it is blue.
Output Format
Output a total of lines.
On line , output an integer , which is the length of the route you constructed that starts from and visits every vertex.
On line , output integers, which describe the order of vertices visited by your route.
4
R
RR
BRB
5
1 4 2 1 3
6
2 3 1 2 3 4
5
3 1 2 3 4
4
4 3 1 2
Hint
Sample Explanation

You should notice that the sample output is not optimal.
If starting from , an optimal route is , with length . Therefore, this route gets $\lfloor 8+8\times \frac{2\times 4-5}{4-1}\rfloor=16$ points.
SPJ Scoring Strategy
Each testdata case in this problem is scored based on the routes you design.
For your -th route, let its length be , and let the length of the official solution’s -th route be .
If or your route is invalid, you will get points.
If and your route is valid, you will get points.
Otherwise, if your route is valid, you will get $\lfloor 8+8\times \frac{2\times K_i-M_i}{K_i-1}\rfloor$ points.
The score of this testdata case is the minimum score among all routes.
Your submission score is the minimum score among all testdata cases.
Translator’s note: To make SPJ implementation and per-testdata scoring easier, each testdata case is worth points, and all scores in the scoring strategy will be scaled proportionally.
Constraints and Limits
For of the data, it is guaranteed that , and is R or B.
Notes
This problem is translated from Canadian Computing Olympiad 2020 Day 2 T1 Travelling Salesperson.
Thanks to
Translated by ChatGPT 5
京公网安备 11011102002149号