最短路变形或最大生成树变形。

问 目标两地之间能通过的小重量。

用最短路把初始赋为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)的更多相关文章

  1. POJ 2263 Heavy Cargo(Floyd + map)

    Heavy Cargo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3768   Accepted: 2013 Descr ...

  2. POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列

    POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...

  3. poj 1797 Heavy Transportation(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

  4. POJ 1595 Prime Cuts (ZOJ 1312) 素数打表

    ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...

  5. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  6. poj 1797 Heavy Transportation(最短路径Dijkdtra)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 26968   Accepted: ...

  7. poj 1797 Heavy Transportation(Dijkstar变形)

    http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...

  8. POJ 1791 Heavy Transportation(最大生成树)

    题面 Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand ...

  9. POJ 1797 Heavy Transportation(Dijkstra运用)

    Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can no ...

随机推荐

  1. Keepalived+NFS+SHELL脚本实现NFS-HA高可用

    本来想做DRBD+HEARTBEAT,但是领导说再加硬盘浪费资源,没有必要,而且在已有硬盘上做风险较大,所以就只能用rsync来实现数据同步了,实验中发现很多的坑,都用脚本和计划任务给填上了,打算把这 ...

  2. 第5章-unix网络编程 TCP/服务端程序示例

    这一章主要是完成一个完整的tcp客户/服务器程序.通过一很简单的例子.弄清客户和服务器如何启动,如何终止,发生了某些错误会发生什么.这些事很重要的  客户端代码 #include "unp. ...

  3. Charger Battery Warning Message 的 改善

    今天與人聊到有關 charger battery safety 的 warning message, 認為說 warning message 真的有起到 保護 user 的作用? 譬如: batter ...

  4. Day 22 生成器yield表达式及内置函数(一丢丢)

    本日知识点: ################################### #一.上节课复习:在for循环式,调用对象内部的__iter__方法, # 把他们变成了可迭代对象然后for循环调 ...

  5. python pyd 加密相关

    Dockerfile RUN 同时执行多条命令 Dokcerfile中的命令每执行一条即产生一个新的镜像,当前命令总是在最新的镜像上执行.如下Dockerfile: RUN cd /usr/share ...

  6. mysql数据库编码格式

    1.查看数据库编码格式 mysql> show variables like 'character_set_database'; 2.查看数据表的编码格式 mysql> show crea ...

  7. TF-IDF 实践

    打算分以下几个部分进行 1. 用python写一个爬虫爬取网易新闻 2. 用分词工具对爬下来的文字进行处理, 形成语料库 3. 根据TF-IDF, 自动找出新闻的关键词 4. 根据TF-IDF, 实现 ...

  8. Codeforces 946 C.String Transformation

    C. String Transformation   time limit per test 1 second memory limit per test 256 megabytes input st ...

  9. Uncaught TypeError: window.showModalDialog is not a function

    if(window.showModalDialog == undefined){ window.showModalDialog = function(url,mixedVar,features){ w ...

  10. ios 6.0模拟器页面调出pop窗口消失后无法使用键盘

    ios 6模拟器上,点击事件调用出pop窗口,这个窗口新创建了window,在pop窗口消失的函数中使用了makeKeyWindow,这个是将要显示的window放到最前端.发现 屏蔽这个方法后可以了 ...