POJ1797 Heavy Transportation
来源:互联网 发布:淘宝售前客服怎么做 编辑:程序博客网 时间:2024/06/05 07:23
Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%lld & %llu
Submit
Status
Description
Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.
Problem
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo’s place) to crossing n (the customer’s place). You may assume that there is at least one path. All streets can be travelled in both directions.
Input
The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are 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 will be at most one street between each pair of crossings.
Output
The output for every scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.
Sample Input
1
3 3
1 2 3
1 3 4
2 3 5
Sample Output
Scenario #1:
4
题目大意是就是何处一个图,n个顶点和m条边,每个边都有最大承载量,现在我要从1点运送货物到n点,求能运送货物的最大重量。
#include<set>#include<queue>#include<cmath>#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#define N 1005#define Inf 0x3fffffffusing namespace std;struct Edge{ int to,vo; Edge(int a,int b): to(a),vo(b) {}};vector<Edge> edge[N];int n,m;int dis[N],vis[N];int SPFA(){ queue<int>que; memset(vis,0,sizeof(vis)); memset(dis,0,sizeof(dis)); que.push(1); vis[1]=1; dis[1]=Inf; while(!que.empty()) { int temp=que.front(); que.pop(); for(int i=0; i<edge[temp].size(); i++) { Edge e=edge[temp][i]; if(min(dis[temp],e.vo)>dis[e.to]) { dis[e.to] = min(dis[temp],e.vo); if(!vis[e.to]) { vis[e.to]=1; que.push(e.to); } } } vis[temp]=0; } return dis[n];}int main(){ int t; int cas=1; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=0; i<=n; i++) edge[i].clear(); for(int i=0; i<m; i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); edge[a].push_back(Edge(b,c)); edge[b].push_back(Edge(a,c)); } int ans=SPFA(); printf("Scenario #%d:\n%d\n\n", cas++, ans); } return 0;}
更新中。。。。。。
- Heavy Transportation (POJ1797)
- poj1797 - Heavy Transportation
- POJ1797--Heavy Transportation
- poj1797 Heavy Transportation
- POJ1797 Heavy Transportation 【Dijkstra】
- POJ1797 Heavy Transportation
- POJ1797 Heavy Transportation
- poj1797 Heavy Transportation
- [poj1797] Heavy Transportation
- POJ1797 Heavy Transportation
- POJ1797 Heavy Transportation
- POJ1797 Heavy Transportation
- POJ1797——Heavy Transportation
- 【POJ1797】Heavy Transportation 最短路
- poj1797 Heavy Transportation spfa变形
- 【POJ1797】Heavy Transportation【dijkstra优化】
- 【POJ1797】【Heavy Transportation】【dij变形】
- POJ1797 Heavy Transportation 最短路
- git 上传项目到github
- 从零开始学习jQuery (九) jQuery工具函数
- Hadoop下Mahout配置
- ios的手势操作之UIGestureRecognizer浅析
- 从零开始学习jQuery (十) jQueryUI常用功能实战
- POJ1797 Heavy Transportation
- dfs解救小哈
- POJ 2182 Lost Cows树状数组 *
- Activity的执行流程
- 从零开始学习jQuery (十一) 实战表单验证与自动完成提示插件
- JAVA Eclipse使用Maven构建web项目详解(SSM框架)
- codeforces 708B-Recover the String
- PHP WebShell源码下载(1)
- C语言 FILE结构体