Question:To give you n stock brokers, you need to find the shortest time to contact everyone. If yes, output a string. If no, output a string.
Next there are N groups of data. Each group of data starts with M contacts for the I broker, next, M indicates the first contact of the data. The second number indicates the time required to contact the contact.
Ideas:The main purpose of this question is to understand the meaning of the question. After understanding it, it will be very simple,You only need to first find the shortest distance of each two points, and then find the shortest distance required to reach the J point using the I vertex as the vertex, you can contact all the people. Because we can find the shortest distance of every two points, we can use the Floyd algorithm, which is the easiest to understand!
So the AC code:
# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; # define INF 100int d [120] [120]; int main () {int I, j, N, K; while (scanf ("% d", & N )! = EOF) {If (n = 0) break; for (I = 1; I <= N; I ++) for (j = 1; j <= N; j ++) {d [I] [J] = inf ;}for (I = 1; I <= N; I ++) {int U; scanf ("% d", & U); For (j = 1; j <= u; j ++) {int V, W; scanf ("% d", & V, & W); D [I] [v] = W ;}} for (I = 1; I <= N; I ++) // obtain the shortest distance for (j = 1; j <= N; j ++) for (k = 1; k <= N; k ++) {If (J! = K & D [J] [k]> d [J] [I] + d [I] [k]) d [J] [k] = d [J] [I] + d [I] [k];} int temp, Maxx, Minn = inf; for (I = 1; I <= N; I ++) // The vertex with I as the graph every time {Maxx = 0; For (j = 1; j <= N; j ++) // find the maximum distance from vertex I if (I! = J & Maxx <D [I] [J]) Maxx = d [I] [J]; If (Maxx <Minn) // replace {Minn = Maxx; temp = I ;}} if (Minn <inf) printf ("% d \ n", temp, Minn); else printf ("disjoint \ n ");} return 0 ;}