Poj 2263 Heavy Cargo Floyd 求最大容量路

f[i][j] = max(f[i][j],min(f[i][k],f[j][k]))

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <string>
#include <iostream>
#include <map>
#include <cstdlib>
#include <list>
#include <set>
#include <queue>
#include <stack>

using namespace std;

typedef long long LL;
const int maxn = 205;
const int INF = INT_MAX / 4;
map<string,int> mp;
int d[maxn][maxn],n,m;
string a,b;

int id(string &s) {
    int now = mp.size();
    if(mp.count(s) == 0) mp[s] = now + 1;
    return mp[s];
}

int main() {
    int kase = 1;
    while(cin >> n >> m,n) {
        mp.clear();
        int dist;
        for(int i = 1;i <= n;i++) {
            for(int j = 1;j <= n;j++) {
                d[i][j] = -1;
            }
        }
        for(int i = 1;i <= m;i++) {
            cin >> a >> b >> dist;
            d[id(a)][id(b)] = d[id(b)][id(a)] = dist;
        }
        for(int k = 1;k <= n;k++) {
            for(int i = 1;i <= n;i++) {
                for(int j = 1;j <= n;j++) {
                    d[i][j] = max(d[i][j],
                            min(d[i][k],d[j][k]));
                }
            }
        }
        cin >> a >> b;
        cout << "Scenario #" << kase++ << endl;
        cout << d[id(a)][id(b)] << " " << "tons" << endl;
        cout << endl;
    }
    return 0;
}

Poj 2263 Heavy Cargo Floyd 求最大容量路,布布扣,bubuko.com

时间: 2024-12-27 11:46:28

Poj 2263 Heavy Cargo Floyd 求最大容量路的相关文章

poj2263 Heavy Cargo --- floyd求最大容量路

求给定起点到终点的路径中,最小边权的最大值 #include <iostream> #include <cstring> #include <string> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> #define inf 0x3f

poj 2263 Heavy Cargo(floyd+dijkstra)

floyd #include<stdio.h> #include<string.h> #include<algorithm> #include<string> #include<map> #include<iostream> using namespace std; int n,m,edge[250][250],vis[250],dist[250]; map<string,int>a; void floyd() { int

POJ 2263 Heavy Cargo(二分+并查集)

题目地址:POJ 2263 这题是在网上的一篇关于优先队列的博文中看到的..但是实在没看出跟优先队列有什么关系..我用的二分+并查集做出来了... 二分路的载重量.然后用并查集检查是否连通. 代码如下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #

POJ 2263 Heavy Cargo(Floyd + map)

Heavy Cargo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3768   Accepted: 2013 Description Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their latest model, the Godzilla V12, is so big that the amount

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<ma

poj2263 zoj1952 Heavy Cargo(floyd||spfa)

这道题数据范围小,方法比较多.我用floyd和spfa分别写了一下,spfa明显有时间优势. 一个小技巧在于:把城市名称对应到数字序号,处理是用数字. 方法一:spfa #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include&

Heavy Cargo POJ 2263 (Floyd传递闭包)

Description Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their latest model, the Godzilla V12, is so big that the amount of cargo you can transport with it is never limited by the truck itself. It is only limited by

POJ 1797 Heavy Transportation (最短路变形)

Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 20364   Accepted: 5401 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man

HDU - 1599 find the mincost route(Floyd求最小环)

find the mincost route Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须满足K>2,就是说至除了出发点以外至少要经过2个其他不同的景区,而且不能重复经过同一个