#P6644. [CCO 2020] Travelling Salesperson

[CCO 2020] Travelling Salesperson

Description

There is a complete graph with NN vertices. Every edge has weight 11, 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 NN.

The next NN lines each contain a string. The string on line ii is Ci=Ci,1,Ci,2Ci,i1C_i=C_{i,1},C_{i,2}\ldots C_{i,i-1}. If Ci,jC_{i,j} is R, then the edge from ii to jj is red; otherwise, it is blue.

Output Format

Output a total of 2×N2\times N lines.

On line 2×i12\times i-1 (1iN)(1\le i\le N), output an integer MiM_i, which is the length of the route you constructed that starts from ii and visits every vertex.

On line 2×i2\times i (1iN)(1\le i\le N), output MiM_i 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 33, an optimal route is 31243\to 1\to 2\to 4, with length 44. 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 ii-th route, let its length be MiM_i, and let the length of the official solution’s ii-th route be KiK_i.

If Mi>2×KiM_i>2\times K_i or your route is invalid, you will get 00 points.

If Mi=KiM_i=K_i and your route is valid, you will get 2525 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 100100 points, and all scores in the scoring strategy will be scaled proportionally.

Constraints and Limits

For 100%100\% of the data, it is guaranteed that 1N2×1031\le N\le 2\times 10^3, and Ci,jC_{i,j} is R or B.

Notes

This problem is translated from Canadian Computing Olympiad 2020 Day 2 T1 Travelling Salesperson.

Thanks to

https://www.luogu.com.cn/user/60864
ing the SPJ.

Translated by ChatGPT 5