无聊发一题。 1

无聊发一题。

Code must be ANSI Standard C.

Problem
The empire has a capitol and a number of cities. Some cities are connected to other cities. A route
connecting two cities can transport a message in both directions. All cities are reachable using some path
from the capitol city. The connections among all cities are described in an adjacency matrix with the format
shown below. At the start, a message is sent from the capitol city to all other cities, and we want to know
what’s the minimal time for a message to spread out from the capitol to the whole empire.
Input (Adjacency Matrix)
The first line of the input file will be n, the number of cities, 1 <= n <= 100. The rest of the input defines
an adjacency matrix, A. The adjacency matrix is square and of size n×n. The value of A(i, j) indicates the
time required to travel from city i to city j. A value of character ‘x’ for A(i, j) indicates that there is no route
between city i to city j. Since a message sent to itself doesn’t require time, and the route between cities is
two way, we always have A(i, i) = 0 and A(i, j) = A(j, i). Thus only the entries on the (strictly) lower
triangular portion of A will be supplied as input, and the second line of input will contain one entry, A(2, 1).
The next line will contain two entries, A(3, 1) and A(3, 2), and so on.
Output
Your program should output the minimum time required before a message sent from the capitol (city #1) is
known throughout the empire, i.e. the time it is received in the last city to get the message.
Sample Input
5
50
30 5
100 20 50
10 x x 10
Output for the Sample Input
35