Zoj1655 transient Deformation

Source: Internet
Author: User

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 */

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.