Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2461283
  • 博文数量: 392
  • 博客积分: 7040
  • 博客等级: 少将
  • 技术积分: 4138
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-17 13:03
个人简介

范德萨发而为

文章分类

全部博文(392)

文章存档

2017年(5)

2016年(19)

2015年(34)

2014年(14)

2013年(47)

2012年(40)

2011年(51)

2010年(137)

2009年(45)

分类:

2010-04-15 13:23:28

Heavy Transportation
Time Limit: 3000MS        Memory Limit: 30000K
Total Submissions: 8505        Accepted: 2310

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


题意描述:
1.给定一个双向可达的有向图,求出1->n之间的所有可达路径,每条路径中的最小边的最大值。

解题思路:
1.最大流?但是这是个双向可达的有向图!!
2.dijksra变形,需要很好的理解dijkstra的过程.每次抽取最大值(保证从其他点出发,不可能有具有更大最小边的路径到达当前点),对当前点的可达点进行release(这个release操作目的是求出最小值)




#include <stdio.h>
#include <string.h>

#define MAX_INT 0x7fffffff
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int n, m, path[1010][1010]/* 双向有向图 */
int map[1010]/* 记录点的当前最优值 */
int processed[1010]; /* 标记该点是否已被抽取 */

/* 初始化map,为了抽取最大值 */
void init_single_source(int size)
{
    int i;
    memset(map, 0, sizeof(map));
    map[1] = MAX_INT;
}

int extract_max(int size)
{
    int i, max, max_idx;

    max = 0;
    for (i=1 ; i<=size ; i++)
    {
        if (0 == processed[i] && map[i] > max)
        {
            max = map[i];
            max_idx = i;
        }
    }
    processed[max_idx] = 1;
    return max_idx;
}

int solve(int size)
{
    int i, j, max_idx, min;

    init_single_source(size);
    for (i=1 ; i<=size ; i++)
    {
        max_idx = extract_max(size);
        for (j=1 ; j<=size ; j++)
        {
            if (0 == processed[j] && 0 != path[max_idx][j])
            {
                /* 选择这条路径上的边的最小值 */
                min = MIN(map[max_idx], path[max_idx][j]);
                /* 选取可到达当前点的路径中的最小边值的最大值 */
                if (min > map[j])
                    map[j] = min;
            }
        }
    }

    return map[size];
}

int main(int argc, char *argv[])
{
    int cas, i, j, a, b, w, ret;

    scanf("%d", &cas);
    for (i=1 ; i<=cas ; i++)
    {
        memset(path, 0, sizeof(path));
        memset(processed, 0, sizeof(processed));
        scanf("%d %d", &n, &m);
        for (j=1 ; j<=m ; j++)
        {
            scanf("%d %d %d", &a, &b, &w);
            path[a][b] = path[b][a] = w;
        }

        ret = solve(n);
        printf("Scenario #%d:\n%d\n\n", i, ret);
    }
}


阅读(2536) | 评论(0) | 转发(0) |
0

上一篇:floyd poj1125

下一篇:boj1490 找零钱 dp

给主人留下些什么吧!~~