## I am coming！

Fighting~ || http://weibo.com/ibattle

# zoj 1655

/*
zoj_1655    最短路

5 6
10
10
10
10
1 3 0.01
1 4 0.002
2 3 0.0003
2 4 0.00004
3 5 0.000005
4 5 0.0000006

5 6
10
10
10
10
1 3 0.99
1 4 0.998
2 3 0.9997
2 4 0.99996
3 5 0.999995
4 5 0.9999994

*/
#include <iostream>
#include <cstdio>
#include <limits.h>
#include <string.h>
using namespace std;
double map[110][110];
double weight[110];
double dist[110];

void dijkstra( int sta,int n )
{
int i,j,mark;
double maxi;
bool flag[110];
memset( flag,0,sizeof(flag) );
memset( dist,0,sizeof(dist) ); //注意初始不能为1因为rate存在0的数据
flag[sta]=1;
dist[sta]=1;
for( i=1;i<=n;i++ )
{
maxi=-1;
for( j=1;j<=n;j++ )
{
if( !flag[j] )
{
if( map[sta][j]!=-1 && dist[j]<dist[sta]*map[sta][j] )
dist[j]=dist[sta]*map[sta][j];
else if( map[sta][j]!=-1 && dist[j]==0 )
dist[j]=dist[sta]*map[sta][j];
if( maxi<dist[j] && dist[j]!=0 )
{
mark=j;
maxi=dist[j];
}
}
}
if( maxi==-1 ) break;
sta=mark;
flag[sta]=1;
}
}

void output( int n )
{
int i;
double sum;
sum=0.0;
for( i=1;i<n;i++ )
{
//printf( "%lf %lf\n",dist[i],weight[i] );
sum+=dist[i]*weight[i];
}
printf( "%.2f\n",sum );
}

int main()
{
//freopen( "a.txt","r",stdin );
int n,m,a,b,i,j;
double rate;
while( scanf( "%d%d",&n,&m )!=EOF )
{
for( i=0;i<=n;i++ )
for( j=0;j<=n;j++ )
map[i][j]=-1;
for( i=1;i<n;i++ )
scanf( "%lf",&weight[i] );
for( i=1;i<=m;i++ )
{
scanf( "%d%d%lf",&a,&b,&rate );
if( 1-rate>map[a][b] )
map[b][a]=map[a][b]=1-rate;
}
dijkstra( n,n );
output( n );
}
return 0;
}

//错误代码
#include <iostream>
#include <cstdio>
#include <limits.h>
#include <string.h>
#define inf 999999.0
using namespace std;
double weight[110];
double map[110][110];
double dist[110];
double sum;

void dijkstra( int sta,int n )
{
int i,j,mark;
double mini;
bool flag[110];
memset( flag,0,sizeof(flag) );
for( i=0;i<=n;i++ )
dist[i]=1;
flag[sta]=1;
for( i=1;i<=n;i++ )
{
mini=inf;
for( j=1;j<=n;j++ )
{
if( !flag[j] )
{
if( map[sta][j]!=-1 && dist[j]>dist[sta]*map[sta][j] )
dist[j]=dist[sta]*map[sta][j];
else if( map[sta][j]!=-1 && dist[j]==1 )
dist[j]=dist[sta]*map[sta][j];
if( mini>dist[j] && dist[j]!=1 )
{
mark=j;
mini=dist[j];
}
}
}
if( mini==inf ) break;
sta=mark;
flag[sta]=1;
}
}

void output( int n )
{
int i;
for( i=1;i<n;i++ )
sum-=dist[i]*weight[i];
printf( "%.2f\n",sum );
}

int main()
{
freopen( "a.txt","r",stdin );
int n,m,a,b,i,j;
double rate;
while( scanf( "%d%d",&n,&m )!=EOF )
{
for( i=0;i<=n;i++ )
for( j=0;j<=n;j++ )
map[i][j]=-1;
sum=0;
for( i=1;i<n;i++ )
{
scanf( "%lf",&weight[i] );
sum+=weight[i];
}
for( i=1;i<=m;i++ )
{
scanf( "%d%d%lf",&a,&b,&rate );
if( map[a][b]==-1 || map[a][b]>1-rate )
{
map[a][b]=rate;
map[b][a]=rate;
}
}
dijkstra( n,n );
output( n );
}
return 0;
}


#### ZOJ 3785

2015-07-25 10:48:57

#### 1004 zoj

2014-08-19 16:04:30

#### zoj 3326

2015-03-21 11:51:56

#### zoj--1025

2014-08-12 20:23:00

#### ZOJ 2886

2015-09-29 21:36:24

#### zoj 1655 单源最短路 改为比例+最长路

2014-06-28 20:05:40

#### ZOJ-1655-Transport Goods

2013-05-27 21:23:00

#### zoj 1655 Transport Goods （最短路变形）

2014-08-21 20:29:02

#### ZOJ1655-Transport Goods-greedy,dijkstra

2016-09-25 19:22:22

#### zoj 1655 Transport Goods（最短路径）

2014-09-28 00:10:20