POJ 1797 Heavy Transportation

Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
题意:先输入测试组数,再输n,m,即点数和边数。m行,每行三个数据,两个顶点及顶点的边的容量。求1到n路径最少容量的最大值。
跟上一篇一样,dijkstra的变形。

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<cmath>
#include<functional>
using namespace std;
#define N 1000+5
#define MAXN 1000000
#define mem(arr,a) memset(arr,a,sizeof(arr))
#define INF 0x3f3f3f3f
#define LL long long int 
#define pow(a) (a)*(a)
int d[N];
struct node{
    int x, y;
}p[N];
int vis[N];
int cost[N][N];
int n, m;
int t;
int cnt = 1;
void dijkstra(){
    mem(d, 0);
    mem(vis, 0);
    while (1){
        int v = -1;
        for (int i = 1; i <= n; i++){
            if (!vis[i] && (v == -1 || d[i] > d[v]))v = i;
        }
        if (v == -1)break;
        vis[v] = 1;
        for (int i = 1; i <= n; i++){
            if (!vis[i]){
                if(!d[i])d[i] = min((d[v]?d[v]:INF), cost[v][i]);
                else d[i] = max(d[i], min((d[v] ? d[v] : INF), cost[v][i]));
            }
        }
    }
    printf("Scenario #%d:\n%d\n\n", cnt++, d[n]);
}
int main(){
    cin >> t;
    while (t--){
        cin >> n >> m;
        mem(cost, 0);
        for (int i = 1; i <= m; i++){
            int a, b, c;
            cin >> a >> b >> c;
            cost[a][b] = cost[b][a] = max(c,cost[a][b]);
        }
        dijkstra();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值