ZOJ Problem Set - 1655
来源:互联网 发布:js 圆形进度条 编辑:程序博客网 时间:2024/06/04 19:09
The HERO country is attacked by other country. The intruder is attacking the capital so other cities must send supports to the capital. There are some roads between the cities and the goods must be transported along the roads.
According the length of a road and the weight of the goods, there will be some cost during transporting. The cost rate of each road is the ratio of the cost to the weight of the goods transporting on the road. It is guaranteed that the cost rate is less than 1.
On the other hand, every city must wait till all the goods arrive, and then transport the arriving goods together with its own goods to the next city. One city can only transport the goods to one city.
Your task is find the maximum weight of goods which can arrive at the capital.
Input
There are several cases.
For each case, there are two integers N (2 <= N <= 100) and M in the first line, where N is the number of cities including the capital (the capital is marked by N, and the other cities are marked from 1 to N-1), and M is the number of roads.
Then N-1 lines follow. The i-th (1 <= i <= N - 1) line contains a positive integer (<= 5000) which represents the weight of goods which the i-th city will transport to the capital.
The following M lines represent M roads. There are three numbers A, B, and C in each line which represent that there is a road between city A and city B, and the cost rate of this road is C.
Process to the end of the file.
Output
For each case, output in one line the maximum weight which can be transported to the capital, accurate up to 2 demical places.
Sample Input
5 6
10
10
10
10
1 3 0
1 4 0
2 3 0
2 4 0
3 5 0
4 5 0
Sample Output
40.00
#include<cstdio>#include<iostream>#define Maxn 510using namespace std;double adj[Maxn][Maxn],dist[Maxn];int x[Maxn],vis[Maxn];const double inf=10000000;void dijkstra(int u,int n){ for(int i=1;i<=n;i++) dist[i]=adj[u][i],vis[i]=0; vis[u]=1; for(int i=1;i<n;i++){ double maxx=-0.5; int v=u; for(int j=1;j<=n;j++) if(!vis[j]&&dist[j]>maxx) maxx=dist[j],v=j; vis[v]=1; for(int j=1;j<=n;j++) if(!vis[j]&&adj[v][j]!=-1&&dist[v]*adj[v][j]>dist[j]) dist[j]=dist[v]*adj[v][j]; } double ans=0; for(int i=1;i<n;i++) ans+=((dist[i]==-1)?0:dist[i])*x[i]; printf("%.2f\n",ans);}int main(){ int n,m,a,b; double c; while(~scanf("%d%d",&n,&m)){ for(int i=1;i<n;i++) scanf("%d",x+i); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) adj[i][j]=-1; while(m--){ scanf("%d%d%lf",&a,&b,&c); adj[a][b]=adj[b][a]=max(adj[a][b],1-c); } dijkstra(n,n); }return 0;}
- ZOJ Problem Set - 1655
- ZOJ Problem Set - 2060
- ZOJ Problem Set - 2972
- ZOJ Problem Set - 1037
- ZOJ Problem Set - 1048
- ZOJ Problem Set - 1049
- ZOJ Problem Set - 1051
- ZOJ Problem Set - 1067
- ZOJ Problem Set - 1115
- ZOJ Problem Set - 1151
- ZOJ Problem Set - 1205
- ZOJ Problem Set - 1025
- ZOJ Problem Set - 1029
- ZOJ Problem Set - 1076
- ZOJ Problem Set - 1117
- ZOJ Problem Set - 1041
- ZOJ Problem Set - 1004
- ZOJ Problem Set - 1005
- EasyUI 使用DataGrid并使用分页及复选框,支持格式化数据
- (!!)Integration of Polynomial
- UVA The most distant state
- ubuntu下共享文件夹的实现方式
- iOS 拍照
- ZOJ Problem Set - 1655
- fork() && fork() || fork()
- Eclispe4.4 TomcatPlugin 安装
- Python学习
- ios网络状态监听
- Python选择数据结构部分练习
- 业务流程:外来人员请求门岗士兵放行
- Python手册学习(一):数字
- hdu 1228 这种水题最烦人了