题目链接:http://poj.org/problem?id=1797

  1. Description
  2.  
  3. Background
  4. Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
  5. Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.
  6.  
  7. Problem
  8. You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from to n. Your task is to find the maximum weight that can be transported from crossing (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.
  9. Input
  10.  
  11. The first line contains the number of scenarios (city plans). For each city the number n of street crossings ( <= n <= ) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than . There will be at most one street between each pair of crossings.
  12. Output
  13.  
  14. The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at . Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.
  15. Sample Input
  16.  
  17. Sample Output
  18.  
  19. Scenario #:

题目大意:有N个城市,有M条路,每条路上有一个最大承重量,问从1到N的道路上能通过的最大承重量是多少?

思路:就是求最大生成树上的最小值,dis【i】表示1到i的最大承重数

  1. #include<stdio.h>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<queue>
  6. #include <stack>
  7. using namespace std;
  8. #define ll long long
  9. #define INF 0x3f3f3f3f
  10. #define met(a,b) memset(a,b,sizeof(a))
  11. #define N 1010
  12. int Map[N][N];
  13. int vis[N],dis[N],n,minn;
  14. int dij(int s)
  15. {
  16. vis[s]=;
  17. for(int i=;i<=n;i++)
  18. dis[i]=Map[s][i];
  19. for(int i=;i<n;i++)
  20. {
  21. int ans=-INF,k=;
  22. for(int j=;j<=n;j++)
  23. {
  24. if(!vis[j] && ans<dis[j])
  25. ans=dis[k=j]; /// 找到之中的最大值
  26. }
  27. vis[k]=;
  28. for(int j=;j<=n;j++)
  29. {
  30. if(!vis[j])
  31. {
  32. int m=min(Map[k][j],dis[k]) ///经过k点到j点,取从1到k点的最大承重量与从k到j点之间的最大承重量之间较小的值
  33. }
  34. dis[j]=max(dis[j],k);///从1到j是否要经过k点,如果经过k点的最大承重量大就经过k点
  35. }
  36. }
  37. return dis[n];///1到每个点的最大承重量
  38. }
  39. int main()
  40. {
  41. int t,m,x,b,l,con=;
  42. scanf("%d",&t);
  43. while(t--)
  44. {
  45. scanf("%d %d",&n,&m);
  46. met(Map,);
  47. for(int i=;i<m;i++)
  48. {
  49. scanf("%d %d %d",&x,&b,&l);
  50. Map[x][b]=Map[b][x]=l; ///道路是双向的
  51. }
  52. met(vis,);
  53. printf("Scenario #%d:\n%d\n\n",con++,dij());
  54. }
  55. return ;
  56. }

(POJ 1797) Heavy Transportation 最大生成树的更多相关文章

  1. POJ 1797 Heavy Transportation (最大生成树)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

  2. poj 1797 Heavy Transportation(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

  3. POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  4. POJ.1797 Heavy Transportation (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  5. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  6. POJ 1797 Heavy Transportation SPFA变形

    原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  7. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

  8. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  9. POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

  10. POJ 1797 Heavy Transportation (Dijkstra)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

随机推荐

  1. ios开发——面试篇C语言精华

    面试篇C语言精华    1.面向过程:分析解决问题所需要的步骤,然后用函数把这些步骤一步一步实 现. 面向对象:直接描述客观世界的对象及其相互关系.现实世界中任何实体都 可以看作是对象,对象之间通过消 ...

  2. ios--uitextfield动态限制输入的字数(解决方式)

    1.定义一个事件: -(IBAction)limitLength:(UITextField *)sender { bool isChinese;//推断当前输入法是否是中文 if ([[[UIText ...

  3. android147 360 程序锁

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  4. jsonp跨域原理解析

    前言: 跨域请求是前台开发中经常遇到的场景,但是由于浏览器同源策略,导致A域下普通的http请求没法加载B域下的数据,跨域问题由此产生.但是通过script标签的方式却可以加载非同域下的js,因此可以 ...

  5. Linux下vim配置详解

    转自http://www.cnblogs.com/witcxc/archive/2011/12/28/2304704.html

  6. 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token

    GCC编译C源程序时出现:错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token,通常是因为在函数声明(包括包含的头文 ...

  7. iOS AR技术初体验,使用EasyAR示例程序的小白指南

    QQ前两天的传递火炬,是我第一次直接接触到AR.(虽然之前听同事说过,因为他喜欢玩游戏,PS.3DS等等都玩过,这个技术最开始就是从这里出现的).所以感觉很有趣,就想自己也试着搞一下玩玩...下面是我 ...

  8. Algernon's Noxious Emissions POJ1121 zoj1052

    One of the greatest alchemists of the lower Middle Renaissance, Algernon da Vinci (one of Leonardo's ...

  9. [改善Java代码]警惕泛型是不能协变和逆变的

    什么叫做协变(covariance)和逆变(contravariance)? 在变成语言的类型框架中,协变和逆变是指宽类型和窄类型在某种情况下(如参数,泛型,返回值)替换或交换的特性,简单的说,协变是 ...

  10. Linux系统调用(转载)

    目录: 1. Linux系统调用原理 2. 系统调用的实现 3. Linux系统调用分类及列表 4.系统调用.用户编程接口(API).系统命令和内核函数的关系 5. Linux系统调用实例 6. Li ...