zoukankan      html  css  js  c++  java
  • 最短路径算法

    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int main()
    {
        int stations[31][31];
        int m,n,f,t,c;
        const int INF = 0x7fffffff;
        while(scanf("%d%d",&m,&n) != EOF){
            for(int i = 0; i <= n; i++){
                for(int j = 0; j <= n; j++) stations[i][j] = INF;
            }
            for(int i = 0; i < m; i++){
                scanf("%d%d%d",&f,&t,&c);
                stations[f][t] = c;
            }
            for(int k = 1; k <= n; k++){
                for(int i = 0; i <= n; i++){
                    for(int j = 0; j <= n; j++){        
                        if(k != i && k != j && i != j && stations[i][k] != INF && stations[k][j] != INF){
                                stations[i][j] = min(stations[i][j],stations[i][k]+stations[k][j]);
                        }
                    }
                }
            }
            printf("%d
    ",stations[0][n]);
        }
        return 0;
    }
  • 相关阅读:
    SortedList的使用示例
    oracle 查询
    sql group by统计
    删除隐藏盘符的隐藏共享,打开隐藏盘符
    【C#】Entity Framework 增删改查和事务操作
    CSS rem长度单位
    HTML 页面meta标签
    VUE 生成二维码(qrcodejs)
    VUE 密码验证与提示
    JavaScript 加解密库(crypto-js)
  • 原文地址:https://www.cnblogs.com/achao123456/p/9187517.html
Copyright © 2011-2022 走看看