码迷,mamicode.com
首页 > 其他好文 > 详细

Floyd

时间:2018-03-06 19:12:33      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:class   turn   clu   post   div   cin   code   弗洛伊德算法   space   

#include<iostream>  
using namespace std;  
int main() {  
    int e[10][10], i, j, k, m, n;  
    int  t1, t2, t3;
    int inf = 999999999;   
    cin >> n >> m;  
    for (i = 1; i <= n; i++)  
        for (j = 1; j <= n; j++) {  
            if (i == j)  
                e[i][j] = 0;  
            else  
                e[i][j] = inf;  
        }  
    for (i = 1; i <= m; i++) {  
        cin >> t1 >> t2 >> t3;  
        e[t1][t2] = t3;  
    }  
    for (k = 1; k <= n; k++)//弗洛伊德算法  
        for (i = 1; i <= n; i++)  
            for (j = 1; j <= n; j++)  
                if (e[i][k]<inf&&e[k][j]<inf&&e[i][j] > e[i][k] + e[k][j])  
                    e[i][j] = e[i][k] + e[k][j];  
                    
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++)  
            cout << e[i][j]<<" ";  
        cout<<endl;  
    }  
    return 0;  
}  

Floyd

标签:class   turn   clu   post   div   cin   code   弗洛伊德算法   space   

原文地址:https://www.cnblogs.com/WAoyu/p/8516022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!