zoukankan      html  css  js  c++  java
  • uva10048(floyd)

    题目连接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=989

    floyd..求路上的边权的最小值(该路中的最大值)。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 const int maxn=110;
     6 const int inf=0x3f3f3f3f;
     7 int p[maxn][maxn];
     8 int n,m,q;
     9 void floyd()
    10 {
    11     for(int k=1;k<=n;k++)
    12         for(int i=1;i<=n;i++)
    13         for(int j=1;j<=n;j++)
    14     {
    15         int temp=max(p[i][k],p[k][j]);
    16         p[i][j]=min(temp,p[i][j]);
    17     }
    18 }
    19 
    20 int main()
    21 {
    22 
    23     int u,v,w;
    24     int cas=0;
    25     while(scanf("%d%d%d",&n,&m,&q)&&(n||m||q))
    26     {
    27          for(int i=1;i<=n;i++)
    28             for(int j=1;j<=n;j++)
    29                 p[i][j]=i==j?0:inf;
    30         for(int i=0;i<m;i++)
    31         {
    32             scanf("%d%d%d",&u,&v,&w);
    33             p[u][v]=p[v][u]=w;
    34         }
    35 
    36 
    37         floyd();
    38         if(cas>0) puts("");
    39         printf("Case #%d
    ",++cas);
    40         while(q--)
    41         {
    42             scanf("%d%d",&u,&v);
    43             if(p[u][v]==inf) puts("no path");
    44             else printf("%d
    ",p[u][v]);
    45         }
    46     }
    47 }
  • 相关阅读:
    django 2.0 path
    Django
    ORM
    Django简介
    web框架
    HTTP协议
    web应用
    索引
    pyMysql模块
    视图、触发器、存储过程、函数
  • 原文地址:https://www.cnblogs.com/yijiull/p/6703912.html
Copyright © 2011-2022 走看看