zoukankan      html  css  js  c++  java
  • UVA

    题目&分析:

    思路:

    Floyd变形(见上述紫书分析),根据题目要求对应的改变判断条件来解题。

    代码:

    #include <bits/stdc++.h>
    #define inf 0x3f3f3f3f
    #define MAX 1000000000
    #define FRE() freopen("in.txt","r",stdin)
    #define FRO() freopen("out.txt","w",stdout)
    using namespace std;
    typedef long long ll;
    typedef pair<int,ll> pii;
    const int maxn = 120;
    int c,s,q;
    int mp[maxn][maxn];
    
    void init(){
        for(int i=1; i<=c; i++){
            mp[i][i] = 0;
            for(int j=i+1; j<=c; j++){
                mp[j][i] = mp[i][j] = inf;
            }
        }
    }
    
    
    int main(){
        //FRE();
        int kase = 0;
        while(scanf("%d%d%d",&c,&s,&q) && c){
            init();
            for(int i=0; i<s; i++){
                int ss,t,d;
                scanf("%d%d%d",&ss,&t,&d);
                mp[ss][t] = d;
                mp[t][ss] = d;
            }
    
            for(int k=1; k<=c; k++){
                for(int i=1; i<=c; i++){
                    for(int j=1; j<=c; j++){
                        if(mp[i][k]<inf && mp[k][j]<inf){
                            mp[i][j] = min(mp[i][j],max(mp[i][k],mp[k][j]));//mark!!
                        }
                    }
                }
            }
            if(kase) printf("
    ");
            printf("Case #%d
    ",++kase);
            while(q--){
                int st,en;
                scanf("%d%d",&st,&en);
                if(mp[st][en]==inf){
                    printf("no path
    ");
                }else{
                    printf("%d
    ",mp[st][en]);
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    习题解答chapter09
    习题解答chapter08
    习题解答chapter07
    银行账户实验-1.2
    银行账户实验-1.1
    银行账户实验-1.0
    习题解答chapter06
    习题解答chapter05
    习题解答chapter04
    习题解答chapter03
  • 原文地址:https://www.cnblogs.com/sykline/p/10384241.html
Copyright © 2011-2022 走看看