• poj 1797 一条路径中的最小边 再找出最大的


    Sample Input

    1 // T
    3 3// n m
    1 2 3//u v w
    1 3 4
    2 3 5
    Sample Output

    Scenario #1:
    4

     1 # include <iostream>
     2 # include <cstdio>
     3 # include <cstring>
     4 # include <algorithm>
     5 # include <cmath>
     6 # define LL long long
     7 using namespace std ;
     8 
     9 const int MAXN=1010;
    10 const int INF=0x3f3f3f3f;
    11 int cost[MAXN][MAXN];
    12 int lowcost[MAXN];
    13 bool vis[MAXN];
    14 int n ;
    15 
    16 void Dijkstra(int beg)
    17 {
    18     for(int i=1;i<=n;i++)
    19     {
    20         lowcost[i]=0;
    21         vis[i]=false;
    22     }
    23     lowcost[beg]=INF;
    24     for(int j=0;j<n;j++)
    25     {
    26         int k=-1;
    27         int Max=0;
    28         for(int i=1;i<=n;i++)
    29             if(!vis[i]&&lowcost[i]>Max)
    30             {
    31                 Max=lowcost[i];
    32                 k=i;
    33             }
    34         if(k==-1)break;
    35         vis[k]=true;
    36         for(int i=1;i<=n;i++)
    37             if(!vis[i]&&min(lowcost[k],cost[k][i])>lowcost[i] )
    38                 lowcost[i]=min(lowcost[k],cost[k][i]);
    39     }
    40 }
    41 
    42 int main()
    43 {
    44   //  freopen("in.txt","r",stdin) ;
    45     int T;
    46     int m;
    47     scanf("%d",&T);
    48     int iCase=0;
    49     while(T--)
    50     {
    51         iCase++;
    52         scanf("%d%d",&n,&m);
    53         memset(cost,0,sizeof(cost));
    54         int u,v,w;
    55         while(m--)
    56         {
    57             scanf("%d%d%d",&u,&v,&w);
    58             cost[u][v]=cost[v][u]=max(cost[u][v],w);
    59         }
    60         Dijkstra(1);
    61         printf("Scenario #%d:
    ",iCase);
    62         printf("%d
    
    ",lowcost[n]);
    63     }
    64     return 0;
    65 }
    View Code
  • 相关阅读:
    Delimiter must not be alphanumeric or backslash php
    mysql replace用法
    MySQL transaction
    最大子数组问题
    LUP分解法求解线性方程组
    PHP和MySQL Web开发从新手到高手,第9天-总结
    DRBD+Heartbeat+mysql 高可用性负载均衡
    优秀博客网址
    rsync+inotify 实时同步数据
    Bugfree 搭建
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/4592453.html
Copyright © 2020-2023  润新知