아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Travelling Salesperson

시간 제한7초메모리 제한512 MB

요약
각 시작 건물에서 빨간 도로와 파란 도로를 합쳐 한 번만 바꾸면서 모든 건물을 방문하는 최단 경로를 찾아 순서까지 출력한다.
난이도

보통10점 중 6점

유형
그래프, 그리디, 구현
정답자
아직 제출이 없습니다

문제

In the city of RedBlue, every pair of buildings is connected by a road, either red or blue. To switch from travelling along red roads to blue roads or vice versa costs one ticket. The length of a route is the number of buildings that are visited. For example, the following route has a length of five and costs one ticket.

1 — 2 — 3 — 4 — 3

If we wanted to travel on a blue road again after visiting vertex 3 for the second time, we would need another ticket, for a total of two tickets:

1 — 2 — 3 — 4 — 3 — 2

You are a travelling salesperson visiting the city of RedBlue, and you wish to visit each building at least once, while minimizing repeated visits of the same buildings. You have not yet decided which building you are starting your route from, so you would like to plan out all possible routes. Furthermore, you only have access to one ticket. For each building, you would like to find a route of minimum length that begins at that building, visits all the buildings at least once, and uses at most one ticket.

입력

The first line will contain a single integer N (2 ≤ N ≤ 2 000), the number of buildings in RedBlue.

Lines 2 to N each contain a string, with line i containing the string Ci, representing the colours of the roads connected to building i. The string Ci = Ci,1Ci,2...Ci,i-1 has a length of i-1 and consists only of the characters R and B. If Ci,j is R, then the road between buildings i and j is red. Otherwise, it is blue.

출력

Output 2N lines. Lines 2i-1 for 1 ≤ i ≤ N should contain a single integer Mi, representing the length of the travel plan starting at building i. Lines 2i for 1 ≤ i ≤ N should each contain Mi space separated integers, describing the order in which you visit the buildings, starting at building i.

예제1

  1. 예제 1

    입력
    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