這個題沒什麼復雜的地方,就是一個關於最短路徑的實現,可以用floyd算法,也可以用Dijkstra算法實現,下面是用Dijsktra算法實現的
題目:
Since the satellite of HIT has been sent to space successfully, HIT needs more electric power. Shuguo Wang has decided to build a new powerstation in HIT.
e.g. The graph of HIT is:
""" where vertexes denotes electricity consumers, and edges denotes wires with their length between consumers. The powerstation will locate at one vertex, and the loss is the sum of the shortest paths from other vertexes to the powerstation. Can you calculate
the minimal loss of HIT's graph?
Input
Output
Sample Input
There are multiple test cases.(We can be Lei Feng to help other brother universities) The first line, an integer n(0
For each test case, output the powerstation's location(the vertex number) and the minimal loss seperated by a space character in a line. Choose the smallest vertex number if there are more than 1 locations.
1
9 11
0 1 1
1 2 3
0 3 4
0 4 7
2 4 6
3 6 3
3 7 8
2 7 9
2 5 2
5 8 5
7 8 3
#include