POJ-1797.HeavyTransportation(最长路中的最小权值)

  本题思路:最短路变形,改变松弛方式即可,dist存的是源结点到当前结点的最长路的最小权值。

  参考代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define INF 0x3f3f3f3f
 5 using namespace std;
 6
 7 const int maxn = 1000 + 10;
 8 int n, m, k, Case = 0, G[maxn][maxn], dist[maxn];
 9 bool vis[maxn];
10
11 int Dijkstra(int source, int aid) {
12     for(int i = 1; i <= n; i ++)
13         dist[i] = (i == source ? INF : 0);
14     for(int i = 1; i <= n; i ++) {
15         int minf = -1;
16         for(int j = 1; j <= n; j ++)
17             if(!vis[j] && minf < dist[j]) {
18                 minf = dist[j];
19                 k = j;
20             }
21         vis[k] = true;
22         if(minf == - 1) break;
23         for(int j = 1; j <= n; j ++)
24             if(!vis[j] && dist[j] < min(dist[k], G[k][j]))
25                 dist[j] = min(dist[k], G[k][j]);
26     }
27     return dist[aid];
28 }
29
30 int main () {
31     int t, x, y, w;
32     scanf("%d", &t);
33     while(t --) {
34         memset(vis, false, sizeof vis);
35         for(int i = 1; i <= n; i ++) {
36             for(int j = 1; j <= n; j ++)
37                 G[i][j] = 0;
38         }
39         scanf("%d %d", &n, &m);
40         for(int i = 1; i <= m; i ++) {
41             scanf("%d %d %d", &x, &y, &w);
42             G[x][y] = G[y][x] = max(G[x][y], w);
43         }
44         printf("Scenario #%d:\n%d\n\n", ++Case, Dijkstra(1, n));
45     }
46     return 0;
47 }

原文地址:https://www.cnblogs.com/bianjunting/p/10687954.html

时间: 2024-10-13 01:50:10

POJ-1797.HeavyTransportation(最长路中的最小权值)的相关文章

poj 2253 Frogger (最长路中的最短路)

链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过任意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,以前求的是路径总长的最小值,而此题是通路中最长边的最小值,每条边的权值可以通过坐标算出,因为是单源起点,直接用SPFA算法或dijkstra算法就可以了 SPFA 16MS #include<cstdio> #include<queue> #include<cmath> #include<

Frogger POJ - 2253(求两个石头之间”所有通路中最长边中“的最小边)

题意 ? 题目主要说的是,有两只青蛙,在两个石头上,他们之间也有一些石头,一只青蛙要想到达另一只青蛙所在地方,必须跳在石头上.题目中给出了两只青蛙的初始位置,以及剩余石头的位置,问一只青蛙到达另一只青蛙所在地的所有路径中的"the frog distance"中的最小值. ? 解释一下"the frog distance": 题目中给出了一段解释"The frog distance (humans also call it minimax distance

POJ 2253 Frogger(Dijkstra变形——最短路径最小权值)

题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' suns

POJ 3686 The Windy&#39;s 最小权值匹配

点击打开链接 The Windy's Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3788   Accepted: 1630 Description The Windy's is a world famous toy factory that owns M top-class workshop to make toys. This year the manager receives N orders for toys.

POJ 2195 Going Home 【二分图最小权值匹配】

传送门:http://poj.org/problem?id=2195 Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26151   Accepted: 13117 Description On a grid map there are n little men and n houses. In each unit time, every little man can move one unit st

【POJ 2400】 Supervisor, Supervisee(KM求最小权匹配)

[POJ 2400] Supervisor, Supervisee(KM求最小权匹配) Supervisor, Supervisee Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2538   Accepted: 719 Description Suppose some supervisors each get to hire a new person for their department. There are N

POJ 2195 Going Home(BFS+KM求最小权值)

Description: On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each little man, you need to pay a $1 travel fee for every step

POj 3253 Fence Repair(修农场栅栏,锯木板)(小根堆 + 哈弗曼建树得最小权值思想 )

Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28359   Accepted: 9213 Description Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000)

[ACM] POJ 3686 The Windy&#39;s (二分图最小权匹配,KM算法,特殊建图)

The Windy's Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4158   Accepted: 1777 Description The Windy's is a world famous toy factory that owns M top-class workshop to make toys. This year the manager receivesN orders for toys. The man