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

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

用最短路把初始赋为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. SharePoint 2013 App 开发—Auto Hosted 方式

    Auto Hosted 方式,自动使用Windows Azure来作为host,这种模式将App 发布到Office 365上的SharePoint Developer Site上.这种方式可以不用花 ...

  2. 【MFC】VS2013 动态创建快捷菜单(右键菜单)

    参考 http://blog.csdn.net/csdnzhwk/article/details/47395639 参考 http://blog.csdn.net/jiadabin/article/d ...

  3. pstack

    pstree  linux 查看进程树 和 包含的线程 pstack 显示每个进程的栈跟踪

  4. Beyond compare vs kdiff3

    這裡使用的 kdiff3 版本是 0.9.98   基於以下 三點,最終選擇了 beyond compare   1. kdiff3 不能刪檔案,     以下為例,不能刪1   2. kdiff3 ...

  5. mysql tinyint bit

    Java bit 对应 mysql tinyint(1)    false = 0 ,true = 1.

  6. python re的findall和finditer

    记录一个现象: 今天在写程序的时候,发现finditer和findall返回的结果不同.一个为list,一个为iterator. 红色箭头的地方,用finditer写的时候,print(item.gr ...

  7. JVM类加载机制————2

    类加载机制的第一个阶段加载做的工作有: 1.通过一个类的全限定名(包名与类名)来获取定义此类的二进制字节流(Class文件).而获取的方式,可以通过jar包.war包.网络中获取.JSP文件生成等方式 ...

  8. Spring IOC知识java反射

    [1] Java反射知识-->Spring IoC :http://www.iteye.com/topic/1123081 [2] Java动态代理-->Spring AOP :http: ...

  9. filter 中用spring StopWatch 监控请求执行时间

    在filter中用spring stopWatch 来统计每个请求的执行时间: 虽然在firefox 中可以清楚的看到每个请求的执行时间,但是为了测试,记录日志, 方便以后查询维护. 还是必要的,下面 ...

  10. 几点iOS开发技巧

    转自I'm Allen的博客   原文:iOS Programming Architecture and Design Guidelines   原文来自破船的分享   原文作者是开发界中知晓度相当高 ...