Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Problem H:
Sightseeing Tour

KM city has $N$ sightseeing areas. Currently every pair of area is connected by a bidirectional road.

However for some reason, Mr. KM, the mayor of this city, decided to make all of these roads one-way . It costs $C_{i, j}$ dollars to renovate the road between area $i$ and area $j$ to a one-way road from area $i$ to area $j$. Of course, Mr. KM is economic and wants to minimize the total cost of the renovation.

On the other hand, because tourism is the most important industry for KM city, there must exists a tour that goes through all the sightseeing areas, visiting each area exactly once. The first and last area of the path need not to be the same. Can you calculate the minimum total cost required for the renovation, given this situation?

Input

The first line contains the number of sightseeing area $N$ ($1 \leq N \leq 100$). Next $N$ lines describe the integer matrix $C$, where the $j$-th element of the $i$-th row of the input describes $C_{i,j}$ ($0 \leq C_{i,j} \leq 1,000,000$). For each $i$, you can assume $C_{i,i}$ is always zero.

Output

Output the minimum cost in a line.

Sample Input 1

3
0 2 7
2 0 4
5 8 0

Sample Output 1

11

Solution in JAVA (judge verdict: Wrong Answer)

import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[][] costs = new int[N][N];
		for (int i = 0; i < costs.length; i++) {
			for (int j = 0; j < costs.length; j++) {
				costs[i][j] = sc.nextInt();
			}
		}
		sc.close();

		boolean[] used = new boolean[N];
		used[0] = true;
		int now = 0;
		int cost = 0;
		while (true) {
			int j = -1;
			int min = Integer.MAX_VALUE;
			for (int i = 0; i < costs[now].length; i++) {
				if (min > costs[now][i] && !used[i]) {
					j = i;
					min = costs[now][i];
				}
			}
			if (j == -1) {
				break;
			}
			used[j] = true;
			cost += costs[now][j];
			now = j;
		}
		System.out.println(cost + costs[now][0]);

	}

	static int swap(int[] clone, int[] run, int now) {
		int swapNum = 0;
		int k = 0;
		for (int i = 0; i < run.length; i++) {
			for (int j = 0; j < run[i]; j++) {
				if (clone[k] != now) {
					if (k == clone.length - 1) {
						return Integer.MAX_VALUE;
					}
					for (int l = k + 1; l < clone.length; l++) {
						if (clone[l] == now) {
							int tmp = clone[l];
							clone[l] = clone[k];
							clone[k] = tmp;

							swapNum += l - k;
							break;
						}
						if (l == clone.length - 1) {
							return Integer.MAX_VALUE;
						}
					}
				}

				k++;
			}
			now = (now + 1) % 2;
		}
		return swapNum;
	}
}