• 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;
    }
  • 相关阅读:
    python并发编程之多进程(实践篇)
    python之网络编程
    python并发编程之协程(实践篇)
    python并发编程之IO模型(实践篇)
    复制命令(ROBOCOPY)
    创建文件命令
    创建文件夹命令
    复制命令(XCOPY)
    进程命令(tasklist)
    目录命令(tree)
  • 原文地址:https://www.cnblogs.com/QQbai/p/2135273.html
Copyright © 2020-2023  润新知