E - Heavy Transportation
来源poj1797
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
要求你算出从1到n的道路,找出能运最大的重量,最大生成树,用了prim算法,额一开始没看到到n,以为是到任意一个地方,wa了
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1005;
int visit[N],Map[N][N],dist[N];
int prim(int n)
{
int pos,ans=inf;
rep(i,1,n+1)
dist[i]=Map[1][i];
visit[1]=1;
dist[1]=0;
rep(i,1,n+1)
{
int max1=-inf;
rep(j,1,n+1)
if(visit[j]==0&&dist[j]>max1)
{
max1=dist[j];
pos=j;
}
visit[pos]=1;
ans=min(max1,ans);
if(pos==n) break;
rep(j,1,n+1)
if(visit[j]==0&&dist[j]<Map[pos][j])
dist[j]=Map[pos][j];
}
return ans;
}
int main()
{
int re,cas=1,n,m,x,y,k;
cin>>re;
while(re--)
{
sf("%d%d",&n,&m);
mm(visit,0);
mm(Map,0);
mm(dist,0);
while(m--)
{
sf("%d%d%d",&x,&y,&k);
Map[x][y]=Map[y][x]=k;
}
pf("Scenario #%d:\n%d\n\n",cas++,prim(n));
}
// pf("\n");
return 0;
}
E - Heavy Transportation的更多相关文章
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- Heavy Transportation(最短路 + dp)
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- poj 1797 Heavy Transportation(最短路径Dijkdtra)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 26968 Accepted: ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation (最短路)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 22440 Accepted: ...
- POJ 1797 Heavy Transportation (dijkstra 最小边最大)
Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...
- POJ1797 Heavy Transportation 【Dijkstra】
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 21037 Accepted: ...
- #图# #最大生成树# #kruskal# ----- OpenJudge 799:Heavy Transportation
OpenJudge 799:Heavy Transportation 总时间限制: 3000ms 内存限制: 65536kB 描述BackgroundHugo Heavy is happy. Afte ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
随机推荐
- 第三届山西省赛1004 一道大水题(scanf)
一道大水题 时间限制: C/C++ 2000ms; Java 4000ms 内存限制: 65535KB 通过次数: 44 总提交次数: 1020 问题描述 Dr. Pan作为上兰帝国ACM的总负责人, ...
- Jmeter压力测试(简单的http请求)-实例
服务端系分提供的某接口样例为: 评估后可采用使用jmeter进行压力测试的步骤为: 启动jmeter:在bin下点击jmeter.bat,运行jmeter 2. 创建测试计划: 默认启动jmeter时 ...
- Asp.Net Core获取请求上下文HttpContext
注:特别说明当前版本对应.Net Core2.1意义上框架 一.注入HttpContextAccessor ASP.NET Core中提供了一个IHttpContextAccessor接口,HttpC ...
- idea插件actiBPM源码
actiBPM https://github.com/Activiti/Activiti
- [jvm][面试]JVM 调优总结
https://blog.csdn.net/wfh6732/article/details/57422967 堆大小设置JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-b ...
- Linux输入子系统框架分析(1)
在Linux下的输入设备键盘.触摸屏.鼠标等都能够用输入子系统来实现驱动.输入子系统分为三层,核心层和设备驱动层.事件层.核心层和事件层由Linux输入子系统本身实现,设备驱动层由我们实现.我们在设备 ...
- MacOS下保护浏览器主页和默认搜索
Windows流氓软件已被中国人玩烂了, 终于连Mac也被沦陷. 视频演示地址: http://v.youku.com/v_show/id_XMTMwMTk4MzQ0MA==.html
- pm2启动jenkins不存在tty的问题
问题 使用pm2管理jenkins, 直接启动bash script, 运行一些命令时会遇到tty不存在的错误 child_process.js:120 p.open(fd); ^ Error: EN ...
- [转]调试利器-SSH隧道
在开发微信公众号或小程序的时候,由于微信平台规则的限制,部分接口需要通过线上域名才能正常访问.但我们一般都会在本地开发,因为这能快速的看到源码修改后的运行结果.但当涉及到需要调用微信接口时,由于不和你 ...
- 重置BizTalk RosettaNet
RosettaNet如果出现问题,可以进行重新配置安装,不过重置过程稍微有点麻烦.步骤如下: 注意:执行如下步骤前请做全部备份工作,如BTARN文件夹,自主开发的BTARN应用程序源码.MSI及Bin ...