zoukankan      html  css  js  c++  java
  • POJ 1125 Stockbroker Grapevine 最短路 难度:0

    http://poj.org/problem?id=1125

    #include <iostream>
    #include <cstring>
    using namespace std;
    int d[101][101];// dag ATTENTION
    int num[101];//the number of contracts
    int edge[101][101];// adjecent edge table
    int n;//always represent the maxnum of single data
    bool input(){
        if((cin>>n)==NULL)return false;
        if(n==0)return false;
        for(int i=0;i<n;i++){
            memset(d+i,0x3f,n*sizeof(int));
            cin>>num[i];
            int temp;
            for(int j=0;j<num[i];j++){
                cin>>temp;
                temp--;
                edge[i][j]=temp;
                cin>>d[i][temp];
            }
        }
        return true;
    }
    void solve(){
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    d[i][j]=min(d[i][k]+d[k][j],d[i][j]);
                }
            }
        }
        int maxn=0;
        int ans=0x3f3f;
        int ansn;
        for(int i=0;i<n;i++){
            maxn=0;
            for(int j=0;j<n;j++){
                if(j!=i)maxn=max(maxn,d[i][j]);
            }
            if(ans>maxn){
                ansn=i;
                ans=maxn;
            }
        }
        cout<<ansn+1<<" "<<ans<<"
    ";
    }
    int main(){
        while(input()){
            solve();
        }
        return 0;
    }
    

      

  • 相关阅读:
    neo4j 运行报错解决方法
    vmstat 指令简介
    yarn的安装和使用
    easyconnect的下载地址
    2021.07.08 泗水
    2021.04.10 春游
    “两”个证明
    2021.04.01
    Swoft调用阿里云OSS报错:RequestId
    mysql临时表代替in的写法
  • 原文地址:https://www.cnblogs.com/xuesu/p/4754397.html
Copyright © 2011-2022 走看看