Constructing RoadsTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 15475 Accepted Submission (s): 5907
Problem Descriptionthere is N villages, which is numbered from 1 to N, and we should build some roads such that every t Wo villages can connect to each of the other. We say village A and B are connected, if and only if there is a road between A and B, or there exists a village C such That there was a road between A and C, and C and B are connected.
We know that there be already some roads between some villages and your job is the build some roads such so all the Vil Lages is connect and the length of the roads built is minimum.
Inputthe first line is a integer n (3 <= N <=), which is the number of villages. Then come n lines, the i-th of which contains n integers, and the j-th of these n integers are the distance (the distance s Hould is an integer within [1, +]) between village I and village J.
Then there was an integer q (0 <= q <= n * (n + 1)/2). Then come Q lines, each line contains the integers a and B (1 <= a < b <= N), which means the road between Villag e A and village B has been built.
Outputyou should output a line contains an integer, which is the length of the "All the roads" to be built such Lages is connected, and this value is minimum.
Sample Input
30 990 692990 0 179692 179 011 2
Sample Output
179
Sourcekicc
Kruskal algorithm has Tai Hang Hdu 1102