Constructing Roads
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 21317 Accepted Submission(s): 8197
Problem Description
There are N villages, which are numbered from1to N, and you should build some roads such thatevery two villages can connect to each other. We say two village A and B are connected, ifand only if there is a road between A and B, or there exists a village C such that there is a road between A and C, and C and B are connected.
We know that there are already some roads betweensome villages and your job isthe build some roads such that all the villages are connect andthelengthof all the roads built is minimum.
Input
The first line is an integer N (3 <= N <= 100), which isthenumberof villages. Then come N lines, the i-th of which contains N integers, andthe j-th of these N integers isthe distance (the distance should be an integer within [1, 1000]) between village i and village j.
Then there is an integer Q (0 <= Q <= N * (N + 1) / 2). Then come Q lines, each line contains two integers a and b (1 <= a < b <= N), which means the road between village a and village b has been built.
Output
You should output a line contains an integer, which isthelengthof all the roads to be built such that all the villages are connected, and this value is minimum.
Sample Input
3099069299001796921790112
Sample Output
179
Source
kicc
Recommend
Eddy | We have carefully selected several similar problems for you: 12331301116212321875
Constructing RoadsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21317 Accepted Submission(s): 8197Problem DescriptionThere are N villages