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

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

用最短路把初始赋为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. 瞄一眼LongAdder(jdk11)

    java版本11.0.1,感觉写得太水了,等心情好的时候再重新编辑一下. LongAdder中的核心逻辑主要由java.util.concurrent.atomic.Striped64维护,作为Str ...

  2. UVa11361 Investigating Div-Sum Property

    数位DP f[位数][自身模k余数][各位数字之和模k余数][当前位是否有上限]=方案数 k<10000,空间不够,如何优化? 不必优化,2^31以内,数字最多只有10位,各位数字之和最多为99 ...

  3. 观察者模式在MVP中的应用

    先简单写下观察者模式.观察者模式,又叫做发布-订阅模式.观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态发生变化时,会通知所有观察者对象,是他们能够自动 ...

  4. libstdc++.so.6: version `GLIBCXX_3.4.20' not found

    libstdc++.so.6: version `GLIBCXX_3.4.20' not found 参考链接: (1)解决/usr/lib/libstdc++.so.6: version `GLIB ...

  5. LightOJ 1140: How Many Zeroes? (数位DP)

    当前数位DP还不理解的点: 1:出口用i==0的方式 2:如何省略状态d(就是枚举下一个数的那个状态.当然枚举还是要的,怎么把空间省了) 总结: 1:此类DP,考虑转移的时候,应当同时考虑查询时候的情 ...

  6. elasticsearch入库错误:gc overhead导致数据节点脱离集群

    https://my.oschina.net/u/3625378/blog/1793796

  7. [Machine Learning with Python] Data Visualization by Matplotlib Library

    Before you can plot anything, you need to specify which backend Matplotlib should use. The simplest ...

  8. android wifi相关模块 命令列表 汇总

    static final int BASE =Protocol.BASE_WIFI;  131072 static final intCMD_START_SUPPLICANT  = BASE +11; ...

  9. Go语言阅读小笔记,来自知呼达达关于unsafe.Pointer的分享.

    第一式 - 获得Slice和String的内存数据 func stringPointer(s string) unsafe.Pointer { p := (*reflect.StringHeader) ...

  10. Android Camera探究之路——起步

    Android Camera探究之路--起步 Camera在手机中有着举足轻重的地位,无论是二维码还是照片.识别.都离不开摄像头,本文将对Android中的Camera进行全面解析. 权限镇楼: &l ...