zoukankan      html  css  js  c++  java
  • poj 1797Heavy Transportation(dijkstra变形)

    题目链接:http://poj.org/problem?id=1797

    题意:有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上的最大承载量

    就是将dijkstra更新变一下更新到每一个点最大载重即可。

    #include <iostream>
    #include <cstring>
    #include <string>
    #include <cstdio>
    using namespace std;
    const int M = 1010;
    int n , m , mmp[M][M] , dis[M];
    bool vis[M];
    void dij(int s) {
        memset(vis , false , sizeof(vis));
        vis[s] = true;
        int pos = s , MAX = -1;
        for(int i = 1 ; i <= n ; i++) {
            dis[i] = mmp[s][i];
        }
        for(int i = 1 ; i < n ; i++) {
            MAX = -1;
            for(int j = 1 ; j <= n ; j++) {
                if(MAX < dis[j] && !vis[j]) {
                    MAX = dis[j];
                    pos = j;
                }
            }
            vis[pos] = true;
            for(int j = 1 ; j <= n ; j++) {
                if(!vis[j] && mmp[pos][j] != -1) {
                    if(dis[j] == -1) {
                        dis[j] = min(dis[pos] , mmp[pos][j]);
                    }
                    else {
                        dis[j] = max(dis[j] , min(dis[pos] , mmp[pos][j]));
                    }
                }
            }
        }
    }
    int main() {
        int t , ans = 0 , sta , end , w;
        scanf("%d" , &t);
        while(t--) {
            ans++;
            scanf("%d%d" , &n , &m);
            for(int i = 1 ; i <= n ; i++) {
                for(int j = 1 ; j <= n ; j++) {
                    mmp[i][j] = -1;
                }
            }
            for(int i = 1 ; i <= m ; i++) {
                scanf("%d%d%d" , &sta , &end , &w);
                mmp[sta][end] = max(mmp[sta][end] , w);
                mmp[end][sta] = mmp[sta][end];
            }
            dij(1);
            printf("Scenario #%d:
    " , ans);
            printf("%d
    
    " , dis[n]);
        }
        return 0;
    }
    
  • 相关阅读:
    selenium自动化测试实战——12306铁路官网范例
    mock接口开发——flask模块
    python调用接口——requests模块
    python操作redis
    python修改excel内容
    python读excel
    python发送邮件
    python写日志
    python的模块
    python写excel
  • 原文地址:https://www.cnblogs.com/TnT2333333/p/6514922.html
Copyright © 2011-2022 走看看