POJ 2263 Heavy Cargo(ZOJ 1952)
最短路变形或最大生成树变形。
问 目标两地之间能通过的小重量。
用最短路把初始赋为INF。其它为0.然后找 dis[v]=min(dis[u], d);
生成树就是把最大生成树找出来。直到出发和终点能沟通的时候,最小的边就是。
Kruskal:
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-6
#define LL long long
using namespace std;
int n,m;
int fa[201];
map<string,int>city;
struct lx
{
int u,v,len;
}l[19901]; int father(int x)
{
if(x!=fa[x])
return fa[x]=father(fa[x]);
} bool cmp(lx a, lx b)
{
return a.len>b.len;
} int main()
{
int nn=1;
while(scanf("%d%d",&n,&m),n||m)
{
for(int i=0;i<=n;i++)
fa[i]=i;
city.clear();
char a[31],b[31];
int len,u,v,cot=0;
for(int i=0;i<m;i++)
{
scanf("%s%s%d",a,b,&len);
u=city[a];
if(u==0)city[a]=cot++;
u=city[a];
v=city[b];
if(v==0)city[b]=cot++;
v=city[b]; l[i].u=u,l[i].v=v,l[i].len=len; }
scanf("%s%s",a,b);
int x=city[a];
int y=city[b]; sort(l,l+m,cmp);
int ans=INF;
for(int i=0;i<m;i++)
{
u=father(l[i].u);
v=father(l[i].v);
if(u==v)continue;
fa[v]=u;
ans=min(ans,l[i].len); if(father(x)==father(y))break;
}
printf("Scenario #%d\n%d tons\n\n",nn++,ans);
}
}
POJ 2263 Heavy Cargo(ZOJ 1952)的更多相关文章
- POJ 2263 Heavy Cargo(Floyd + map)
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3768 Accepted: 2013 Descr ...
- POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列
POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- POJ 1595 Prime Cuts (ZOJ 1312) 素数打表
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...
- 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(Dijkstar变形)
http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...
- POJ 1791 Heavy Transportation(最大生成树)
题面 Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand ...
- POJ 1797 Heavy Transportation(Dijkstra运用)
Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can no ...
随机推荐
- 关于scarpy的一些说明
一 scrapy添加代理 1 内置代理:os.environ. 固定格式,不推荐 os.environ['http_proxy'] = "http://root:woshiniba@192 ...
- 【CF711C】Coloring Trees(DP)
题意:给你n个数字,一共有m种,如果某数为0则该数为空,空的地方可以填任意种类数,但每填一个数字都要花费一定的费用, 从头到尾,所有相邻且相同的数字看作一个集合,求使n个数字的集合数为k所需的最小费用 ...
- Linux 之 文件内容查看
文件内容查看 参考教程:[千峰教育] 文件内容查看: cat: 作用:一次性顺序显示文件的所有内容 格式:cat file tac: 作用:一次性倒序显示文件的所有内容 格式:tac file hea ...
- 本地安装Sass,Compass
使用本地的gem文件来安装Sass和Compass. 1.安装Ruby http://rubyinstaller.org/downloads/ 下载之后双击安装即可,在安装过程中可以选择“Add Ru ...
- 更新YUM源后的arning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY错误
yum源更新后需要导入key值,否则报错如下,无法安装相关的包. Totalsize:42M DownloadingPackages: warning:rpmts_HdrFromFdno:Header ...
- 问题:Linux 输入任何命令都显示 -bash: fork: Cannot allocate memory
应该是某个程序吃掉了所有的内存,只能重启
- 总结下web开发中基础性的常识
一,HTML/5 1,浏览器渲染过程 主流浏览器渲染过程叫法有区别,但是主要流程还是相同的.Gecko 将视觉格式化元素组成的树称为“框架树”.每个元素都是一个框架.WebKit 使用的术语是“呈现树 ...
- (1)Unity3d界面、入门
项目视图 层级视图 属性视图 场景视图 游戏视图 调整u3d整体界面布局 1.查看和移动视图 快捷键Q 2.沿轴方向位移 快捷键W 3.沿轴向旋转 快捷键E 4.沿轴向缩放 快捷键R 5.自由调节小大 ...
- codevs贪吃的九头龙
传说中的九头龙是一种特别贪吃的动物.虽然名字叫“九头龙”,但这只是说它出生的时候有九个头,而在成长的过程中,它有时会长出很多的新头,头的总数会远大于九,当然也会有旧头因衰老而自己脱落.有一天,有M 个 ...
- java中正则表达式要进行转义的字符。
/** * 转义正则特殊字符 ($()*+.[]?\^{},|) * * @param keyword * @return */public static String escapeExprSpeci ...