A: Hero's capital needs goods and needs to deliver goods from other cities to the capital. Each road consumes a certain proportion of goods and asks how many goods can be delivered to the capital.
Idea: if the ratio of each vertex is 1, the proportion to the capital is the product of the path (1-consumption ratio) that passes through. It is undirected, so it can be pushed in turn, the cargo ratio of the capital is 1, and the arrival of each seat
The goods in a city are the product of the path (1-consumption ratio). Therefore, we can calculate the maximum ratio between the capital and any city; at last, multiply the maximum ratio of each vertex by the goods of each vertex.
That is the result.
# Include <stdio. h> # include <string. h> const int maxn = 150; const double LEP = 1e-8; double map [maxn] [maxn]; int vis [maxn]; double dis [maxn]; int W [maxn]; int n, m; void Init () {memset (VIS, 0, sizeof (VIS); memset (DIS, 0, sizeof (DIS )); for (INT I = 0; I <= N; I ++) {for (Int J = 0; j <= N; j ++) map [I] [J] =-1 ;}} double dij () // returns the maximum ratio of materials delivered to each city. {int I, j; int u = N; dis [u] = 1; vis [u] = 1; for (I = 1; I <= N; I ++) {for (j = 1; j <N; j ++ ){ If (! Vis [J] & dis [J] <dis [u] * map [u] [J]) {dis [J] = dis [u] * map [u] [J] ;}} double max = 0; For (j = 1; j <n; j ++) {If (! Vis [J] & dis [J]-Max> LEP) {max = dis [J]; u = J ;}} vis [u] = 1 ;} double ans = 0; for (I = 1; I <n; I ++) ans + = W [I] * Dis [I]; return ans;} int main () {int I; while (~ Scanf ("% d", & N, & M) {Init (); for (I = 1; I <n; I ++) scanf ("% d", & W [I]); W [N] = 0; for (I = 0; I <m; I ++) {int, b; double C; scanf ("% d % lf", & A, & B, & C ); if (Map [a] [B] <(1-C) {map [a] [B] = map [B] [a] = 1-C; // printf ("% lf \ n", map [a] [B]) ;}} printf ("%. 2lf \ n ", dij ();} return 0 ;}/ * 5 6101010101 3 01 4 02 3 02 4 03 5 04 5 0 */