F-heavy TransportationTime
limit:3000MS
Memory Limit:30000KB
64bit IO Format:%i64d &%i6 4u Submit Status Practice POJ 1797
Description
Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever mans tells him whether there really is a-a-a-from-the-place his customer have build his giant stee L Crane to the place where it's needed on which all streets can carry the weight.
Fortunately he already have a plan of the city with all streets and bridges and all the allowed weights. Unfortunately he have no idea how to find the the the maximum weight capacity in order to tell him customer how heavy the crane May become. But you surely know.
Problem
You is given the plan of the city, described by the streets (with weight limits) between the crossings, which is numbere D from 1 to N. Your task is to find the maximum weight, can be transported from crossing 1 (Hugo's place) to crossing N (the customer ' s place). You are assume that there are at least one path. All streets can is travelled in both directions.
Input
The first line contains the number of scenarios (city plans). For each city the number N of the street crossings (1 <= n <=) and number M of streets is given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed Weight, which is positive and not larger than 1000000. There'll is at the most one street between each pair of crossings.
Output
The output for every scenario begins with a line containing "scenario #i:", where I am the number of the scenario starting at 1. Then print a, containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.
Sample Input
13 31 2 31 3 42 3 5
Sample Output
Scenario #1:4 Each road has a limited weight
The maximum number of goods that can be loaded from 1 to n
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;//const int INF=0X7FFFFFFF;Const intmaxn=1010;//#define TYPEC intConst intinf=0x3f3f3f3f;//prevent back overflow, this can't be too bigBOOLVIS[MAXN];intDIS[MAXN];intMAP[MAXN][MAXN];intN;voidDijkstra (intBeg) { for(intI=1; i<=n; i++) {Dis[i]=Map[beg][i]; Vis[i]=false; } Dis[beg]=0; for(intj=0; j<n; J + +) { intk=-1; intmin=-1; for(intI=1; i<=n; i++) if(!vis[i]&&dis[i]>Min) {Min=Dis[i]; K=i; } if(k==-1) Break; VIS[K]=true; for(intI=1; i<=n; i++) if(!vis[i]&&dis[i]<min (dis[k],map[i][k])) {Dis[i]=min (dis[k],map[i][k]); } }}intMain () {intT; scanf ("%d",&t); intCnt=0; while(t--) {CNT++; intm; memset (Vis,false,sizeof(VIS)); scanf ("%d%d",&n,&m); /*for (int i=1;i<=n;i++) {for (int j=i;j<=n;j++) {if (i==j) map[i][i]=0; else Map[i][j]=map[j][i]=inf; } }*/memset (Map,0,sizeof(map)); intu,v,w; for(intI=1; i<=m;i++) {scanf ("%d%d%d",&u,&v,&W); MAP[U][V]=map[v][u]=W; } Dijkstra (1); printf ("Scenario #%d:\n", CNT); printf ("%d\n", Dis[n]); Puts (""); } return 0;}
POJ 1797 Heavy Transportation (Dijkstra variant)