zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    HashMap源码分析jdk1.8
    Struts1.x总结
    session的使用
    浅谈EL
    浅谈JavaBean
    try、catch、finally带return的执行顺序总结
    jvm内存模型
    left join 、right join 、inner join之间的区别
    js按键事件
    log4j配置详解
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/4592453.html
Copyright © 2011-2022 走看看