zoukankan      html  css  js  c++  java
  • floyd 算法

    #include<stdio.h>
    int n,m,map[124][124];
    int inf = 0x7fffffff;
    void floyd(  )
    {
         for( int i = 1; i <= n; ++i )
              for( int j = 1; j <= n; ++j )
                   for( int k = 1; k <= n; ++k )
                        if( map[i][j] != inf && map[i][k] != inf )
                            if( map[i][j] + map[i][k] < map[j][k] )
                                map[j][k] = map[i][j] + map[i][k];
     }
    int main( )
    {
        while( scanf( "%d%d",&n,&m ),n&&m )
        {
               for( int i = 1; i <= n; ++i )
                    for( int j = 1; j <= n; ++j )
                         map[i][j] = inf;
               for( int i = 1; i <= m; ++i )
               {
                    int x,y,v;
                    scanf( "%d%d%d",&x,&y,&v );
                    if( map[x][y] > v )
                        map[x][y] = map[y][x] = v;
                    }
               floyd(  );
               printf( "%d\n",map[1][n] );
               }
        return 0;
    }
  • 相关阅读:
    Hibernate连接mysql数据库的配置
    opendaynight(karaf) 和 mininet测试openflow
    电信新势力,TIP/CORD能颠覆电信设备商吗?
    minnet sample
    ONIE
    升级Mininet自带的OpenvSwitch & 编译OpenvSwitch
    mininet test
    dpctl 命令实践
    白盒交换机
    Wedge 100-32X 100GbE Data Center Switch
  • 原文地址:https://www.cnblogs.com/QQbai/p/2135273.html
Copyright © 2011-2022 走看看