【codevs1077】多源最短路

problem

solution

codes

//Floyd-wallshall模板
#include<iostream>
using namespace std;
int n, e[110][110];
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            cin>>e[i][j];
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++) 
                if(e[i][k]+e[k][j]<e[i][j])
                    e[i][j] = e[i][k]+e[k][j];
    int T;  cin>>T;
    while(T--){
        int a, b;
        cin>>a>>b;
        cout<<e[a][b]<<"\n";
    }
    return 0;
}
posted @ 2018-06-01 21:48  gwj1139177410  阅读(91)  评论(0编辑  收藏  举报
选择