原题链接
求一条能运多重货物路上的最小值
代码
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int map[1002][1002],dis[1002],way[1002];
int n,inf=99999999999;
void dijkstra()
{
int book[1002],i,j;memset(book,0,sizeof(book));memset(dis,0,sizeof(dis));for(i=1;i<=n;i++)dis[i]=map[1][i];dis[1]=0;book[1]=1;for(i=1;i<n;i++){
int minn=0,u;for(j=1;j<=n;j++){
if(!book[j]&&dis[j]>minn){
u=j;minn=dis[j];}}book[u]=1;for(j=1;j<=n;j++){
if(dis[j]<min(dis[u],map[u][j]))dis[j]=min(dis[u],map[u][j]);//求该路径上最小承重}}
}
int main()
{
int t,m,a,b,x,q=0;scanf("%d",&t);while(t--){
memset(map,0,sizeof(map));scanf("%d%d",&n,&m);for(int i=0;i<m;i++){
scanf("%d%d%d",&a,&b,&x);map[a][b]=map[b][a]=x;}dijkstra();printf("Scenario #%d:\n",++q);printf("%d\n\n",dis[n]);}return 0;
}