#K36842. Maximum Visitable Cities
Maximum Visitable Cities
Maximum Visitable Cities
You are given n cities and an n x n distance matrix \(D\) where \(D_{ij}\) represents the distance from city \(i\) to city \(j\). A traveler, Sarah, wants to visit as many distinct cities as possible. Starting from any city, in each step she moves to the nearest unvisited city (i.e., with the minimum positive distance).
Your task is to determine the maximum number of cities Sarah can visit and output the visiting order (with 1-indexed city numbers) corresponding to that maximum tour. If there are multiple starting points leading to the same maximum count, choose the tour obtained from the smallest starting city index that achieves the maximum.
Note: The distance matrix satisfies \(D_{ii} = 0\) for all \(i\) and \(D_{ij} > 0\) for \(i \neq j\). It is guaranteed that there is at least one valid move until no unvisited city is available.
inputFormat
The first line contains an integer \(n\) \((1 \leq n \leq 1000)\), the number of cities.
The following \(n\) lines each contain \(n\) space-separated integers representing the distance matrix. The \(j\)-th integer in the \(i\)-th line denotes \(D_{ij}\).
Input is given via standard input (stdin).
outputFormat
Output two lines. The first line should contain an integer representing the maximum number of cities visited. The second line should contain the visiting order (1-indexed) of the cities, separated by spaces.
Output is to be printed to standard output (stdout).
## sample3
0 10 15
10 0 12
15 12 0
3
1 2 3
</p>