POJ 1797 最短路

链接:

http://poj.org/problem?id=1797

题意:

给出N个城市M条边,每条边都有个容量,求一条运输路线,使城市1到城市N的运输量最大

代码:

31 int cost[MAXN][MAXN];
32 int d[MAXN];
33 int used[MAXN];
34 int n, m;
35
36 void dijkstra() {
37     memset(d, 0, sizeof(d));
38     memset(used, 0, sizeof(used));
39     d[0] = INF;
40
41     while (1) {
42         int v = -1;
43         rep(u, 0, n) if (!used[u] && (v == -1 || d[u] >= d[v])) v = u;
44         if (v == -1) break; used[v] = 1;
45         rep(u, 0, n) d[u] = max(d[u], min(d[v], cost[v][u]));
46     }
47 }
48
49 int main() {
50     int T;
51     cin >> T;
52     rep(cas, 0, T) {
53         memset(cost, 0, sizeof(cost));
54         cin >> n >> m;
55         while (m--) {
56             int a, b, c;
57             scanf("%d%d%d", &a, &b, &c);
58             a--, b--;
59             cost[a][b] = cost[b][a] = c;
60         }
61         dijkstra();
62         cout << "Scenario #" << cas + 1 << ‘:‘ << endl;
63         cout << d[n - 1] << endl << endl;
64     }
65     return 0;
66 }
时间: 2024-08-24 09:12:46

POJ 1797 最短路的相关文章

Heavy Transportation POJ 1797 最短路变形

Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你求从编号为1的城市到编号为n的城市的路线中,最大能经过多重的车. 解题思路 这个题可以使用最短路的思路,不过转移方程变了\(dis[j]=max(dis[j], min(dis[u], e[u][j]))\).这里dis[j]表示从标号为1的点到达编号为j的点的路径中,最小的承重能力,就像短板效应样

POJ 1797 Heavy Transportation (最短路变形)

Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 20364   Accepted: 5401 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man

POJ 1797 Heavy Transportation (Dijkstra变形)

F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand busines

poj 1502 最短路+坑爹题意

链接:http://poj.org/problem?id=1502 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5249   Accepted: 3237 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed share

POJ 2448(K短路,A*+SPFA) Remmarguts&#39; Date

题意 给一个n个点m条边的图,然后给一个起点和一个终点,求起点到终点的第K短路. 思路 求第K短路.一个经典的问题. SPFA+A* 核心思想在A*搜索的估计函数的建立上. F(x) = g(x) + h(x) 估价函数 = s到x的距离 + x到t的距离 估价函数的含义就是经过x这个点的路径的距离. 我们在搜索的时候每次选择估价函数较小的值,进行拓展.这样我们搜索到t点的状态出来顺序就是,最短路-次短路-.第三短路- 就减少了我们搜索的状态数. 代码实现上,实现一个估价函数的结构体,然后是实现

poj 1797 Heavy Transportation(最大生成树)

poj 1797 Heavy Transportation 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

poj 1135 最短路 dijkstra

传送门 http://poj.org/problem?id=1135 建模分两部分:1.如果最后是关键牌倒下,那么找最短路中最长的就行--最远的倒下,其他的牌一定倒下,所以找最远的最短路 2.如果最后是普通牌倒下,那么找三角形,三角形周长的一半就是倒下的位置 到底是情况1还是情况2,自己在脑子模拟一下就能想到,还是那句话,最难倒下的倒下了,其他的一定都倒下了,若第二种情况的时间比第一种长,那么就是第二种,反之,第一种 上代码 /**********************************

It&amp;#39;s not a Bug, It&amp;#39;s a Feature! (poj 1482 最短路SPFA+隐式图+位运算)

Language: Default It's not a Bug, It's a Feature! Time Limit: 5000MS   Memory Limit: 30000K Total Submissions: 1353   Accepted: 516 Description It is a curious fact that consumers buying a new software product generally do not expect the software to

POJ 1797 Heavy Transportation (Dijkstra)

题目链接:POJ 1797 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