#C7056. Optimal Scientist Collaboration Order
Optimal Scientist Collaboration Order
Optimal Scientist Collaboration Order
You are given an M×M matrix A where Aij represents the effectiveness of the collaboration between scientist i and scientist j when they work together. The total effectiveness of an ordering π = (π0, π1, …, πM-1) is defined by the formula:
$$ E(\pi) = \sum_{i=0}^{M-1} \sum_{j=0}^{M-1} A_{\pi_i\pi_j} $$
Your task is to choose an ordering of scientists that maximizes the total effectiveness. In the case of ties, choose the lexicographically smallest ordering.
Note: Since the ordering is a permutation of {0, 1, …, M-1} and the formula sums over all pairs, the sum will be invariant. Hence, the answer is always the lexicographically smallest permutation, i.e. 0 1 ... M-1. However, you are required to implement the solution according to the provided specifications.
inputFormat
The input is read from standard input and has the following format:
- The first line contains an integer
T
indicating the number of test cases. - For each test case:
- The first line contains an integer
M
, denoting the number of scientists. - The next
M
lines each containM
space-separated integers, representing the matrix A.
- The first line contains an integer
outputFormat
For each test case, print one line with the optimal order of scientists as space separated indices. Since all orders yield the same total effectiveness, it will always be the lexicographically smallest order 0 1 ... M-1
.
1
3
1 2 3
4 5 6
7 8 9
0 1 2
</p>