博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj1797——Heavy Transportation(最大生成树)
阅读量:2344 次
发布时间:2019-05-10

本文共 2282 字,大约阅读时间需要 7 分钟。

Description

Background

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.
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.

Problem

You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (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.
Input

The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) 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 1000000. There will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario starting at 1. 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.

Sample Input

1

3 3
1 2 3
1 3 4
2 3 5
Sample Output

Scenario #1:

4

用构造最小生成树的方法,每次加入生成树的是当前权值最大的边,到达n点停止,这里如果没停止就会受其他边的影响WA掉。

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 1010#define mod 1000000007using namespace std;int n,m,mp[MAXN][MAXN],vis[MAXN],lowc[MAXN];int prim(int n){ memset(vis,0,sizeof(vis)); vis[1]=1; for(int i=1; i<=n; ++i) lowc[i]=mp[1][i]; int ans=INF; for(int i=2; i<=n; ++i) { int maxc=-2; int p=-1; for(int j=1; j<=n; ++j) if(!vis[j]&&maxc

转载地址:http://yscvb.baihongyu.com/

你可能感兴趣的文章
Ubuntu系统如何安装双网卡及更改网卡名称(eth0改为eth1)
查看>>
销毁new的指针
查看>>
向控制台打印指针
查看>>
四种类型转换
查看>>
数组指针和指针数组
查看>>
数据的大端小端表示法
查看>>
什么是类型安全的
查看>>
深拷贝和浅拷贝
查看>>
全局静态变量和局部静态变量的区别
查看>>
内链接和外连接
查看>>
类的静态成员
查看>>
类的公有私有保护继承
查看>>
类的常量成员的初始化
查看>>
类成员初始化顺序
查看>>
拷贝构造和赋值函数
查看>>
将类的方法声明为虚函数的作用
查看>>
函数指针
查看>>
进程调度的概念
查看>>
操作系统典型调度算法
查看>>
1.内存管理的概念
查看>>