6471: Travel Cost
[Creator : ]
Description
AC country is a famous and beautiful place. There are $N$ cities in the country, numbered as $1,2,3,...,N$.
The first city is the capital of AC, so it is the greatest and best place all over the country. Many travelers often get a travel in AC.
ACMer and his girl friends like the fine view and beautiful scenery in AC, so they plan to get a travel in AC recently. AC and his $N-1$ girl friends go to the AC by plane land at the capital airport. They wants to get a travel to every city of AC but independently. in other words, the first girl friend goes to the first city, the second girl friend goes to the second city,the rest can be done in the same manner.
In AC country, there maybe at most one road between every two different cities. One girl will spend some money if she passes one road correspondingly. ACMer must offer all the travel cost of all his girl friends. He wants to known what is the minimum total cost if evry girl gets her travel by the most economic strategy?
The first city is the capital of AC, so it is the greatest and best place all over the country. Many travelers often get a travel in AC.
ACMer and his girl friends like the fine view and beautiful scenery in AC, so they plan to get a travel in AC recently. AC and his $N-1$ girl friends go to the AC by plane land at the capital airport. They wants to get a travel to every city of AC but independently. in other words, the first girl friend goes to the first city, the second girl friend goes to the second city,the rest can be done in the same manner.
In AC country, there maybe at most one road between every two different cities. One girl will spend some money if she passes one road correspondingly. ACMer must offer all the travel cost of all his girl friends. He wants to known what is the minimum total cost if evry girl gets her travel by the most economic strategy?
Input
There are many test case waiting for your program code!
In every case, the first line of the input will be $N\ (1 \leq N \leq 100)$, the number of cites.
The rest of the input defines an $N*N$ adjacency matrix. Each of its entries will be either an integer or the character $x$. The value of $\text{MAT}(i,j)$ indicates the expense of sending a travel directly from city $i$ to city $j$. A value of $x$ for $\text{MAT}(i,j)$ indicates that there is no directly road from city to city $j$.
Note that for a city to itself does not require any cost, so $\text{MAT}(i,i) = 0$ for all integer $i$ in range $(1,N)$. Also, you may assume that the road is undirected, so that $\text{MAT}(i,j) = \text{MAT}(j,i)$. Thus the imput data only supply the entries on the lower triangular portion of adjacency matrix strictly.
The input of your program will be the lower triangular section of matrix . That is, the second line of input will contain only, $\text{MAT}(2,1)$. The next line will contain two entries, $\text{MAT}(3,1)$ and $\text{MAT}(3,2)$, and so on. All $\text{MAT}(i,j)$ will not greater than $1,000$.
In every case, the first line of the input will be $N\ (1 \leq N \leq 100)$, the number of cites.
The rest of the input defines an $N*N$ adjacency matrix. Each of its entries will be either an integer or the character $x$. The value of $\text{MAT}(i,j)$ indicates the expense of sending a travel directly from city $i$ to city $j$. A value of $x$ for $\text{MAT}(i,j)$ indicates that there is no directly road from city to city $j$.
Note that for a city to itself does not require any cost, so $\text{MAT}(i,i) = 0$ for all integer $i$ in range $(1,N)$. Also, you may assume that the road is undirected, so that $\text{MAT}(i,j) = \text{MAT}(j,i)$. Thus the imput data only supply the entries on the lower triangular portion of adjacency matrix strictly.
The input of your program will be the lower triangular section of matrix . That is, the second line of input will contain only, $\text{MAT}(2,1)$. The next line will contain two entries, $\text{MAT}(3,1)$ and $\text{MAT}(3,2)$, and so on. All $\text{MAT}(i,j)$ will not greater than $1,000$.
Output
for every case, output the minimum total cost of all ACMer's all girl friends, one per line.
Sample 1 Input
5
40
30 6
99 24 36
25 x x 25
Sample 1 Output
141