Since the input is the damage rate, that 1-x is the remaining. Last as long as the remaining maximum.
#include <stdio.h>#include<string.h>#defineMax 99999999Const intmaxn=1003;DoubleDIS[MAXN],MAP[MAXN][MAXN];intVIS[MAXN],N,VAL[MAXN];voidinit () {inti,j; for(i=1; i<=n;i++) for(j=1; j<=n;j++) if(i==j) Map[i][j]=0; Elsemap[i][j]=0;}voidDij () {intI,j,pos; POS=N; memset (Vis,0,sizeof(VIS)); for(i=1; i<=n;i++) Dis[i]=0; Dis[pos]=1;//vis[pos]=1; for(i=1; i<=n;i++) { Doublemin=-Max; for(j=1; j<=n;j++) { if(!vis[j]&&min<Dis[j]) {POS=J; Min=Dis[j]; }} Vis[pos]=1; for(j=1; j<=n;j++) { if(!vis[j]&&dis[j]<map[pos][j]*Dis[pos]) dis[j]=map[pos][j]*Dis[pos]; } }}intMain () {inti,j,m; DoubleCost ; while(SCANF ("%d%d", &n,&m)! =EOF) {init (); for(i=1; i<n;i++) scanf ("%d",&Val[i]); for(i=1; i<=m;i++) { intx, y; scanf ("%D%D%LF",&x,&y,&Cost ); if(map[x][y]<1-Cost ) Map[x][y]=map[y][x]=1-Cost ; } /*for (i=1;i<=n;i++) {for (j=1;j<=n;j++) {printf ("%.2lf", Map[i][j]); } printf ("\ n"); }*/ Doubleans=0; Dij (); /*for (i=1;i<=n;i++) printf ("%d", dis[i]); printf ("\ n");*/ for(i=1; i<n;i++) ans+=val[i]*Dis[i]; printf ("%.2lf\n", ans); }}
zoj1665 Dij Deformation