[kuangbin带你飞]专题四 最短路练习 C
2016-12-03 01:05
417 查看
http://poj.org/problem?id=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 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
最大堆,贪心的策略是每次的dis为前面路径的中最小值,但因为每次取出的都是最大值,故最后得到的一定正确。。
为毛线都是dijstra。。这个输出啊 excitd
\n\
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
题意:
给定一个双向可达的有向图,求出1->n之间的所有可达路径,每条路径中的最小边的最大值。tip:
上一个题是最长边最小,这个是最短边最大。。最大堆,贪心的策略是每次的dis为前面路径的中最小值,但因为每次取出的都是最大值,故最后得到的一定正确。。
为毛线都是dijstra。。这个输出啊 excitd
\n\
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <cmath> #include <vector> #include <deque> #include <utility> #include <functional> const int maxn = 100010; const double eps = 1e-6; const int INF = (1<<30); using namespace std; int n,m,tot; int dis[maxn],first[maxn]; typedef pair<int,int>pii; priority_queue <pii> pq; struct node{ int v,w,next; }edges[10*maxn]; void add(int u,int v,int w){ edges[tot].v = v;edges[tot].w = w;edges[tot].next = first[u];first[u] = tot++; edges[tot].v = u;edges[tot].w = w;edges[tot].next = first[v];first[v] = tot++; } void dij(){ while(!pq.empty()){ int no = pq.top().second; if(no == n) return; pq.pop(); for(int i = first[no]; i != -1;i = edges[i].next){ if(min(edges[i].w ,dis[no]) > dis[edges[i].v]){ dis[edges[i].v] = min(edges[i].w ,dis[no]); pq.push(make_pair(dis[edges[i].v],edges[i].v)); } } } } void init(){ tot = 0; memset(dis,0,sizeof(dis)); memset(first,-1,sizeof(first)); scanf("%d%d",&n,&m); for(int i = 0 ; i < m ; i++){ int u,v,w; scanf("%d%d%d",&u,&v,&w); add(u,v,w); } while(!pq.empty()){ pq.pop(); } dis[1] = INF; pq.push(make_pair(0,1)); } int main(){ int T; scanf("%d",&T); for(int ca = 1 ;ca <= T ;ca++){ init(); dij(); printf("Scenario #%d:\n%d\n\n",ca,dis ); } }
相关文章推荐
- [kuangbin带你飞]专题四 最短路练习 O LightOJ 1074
- [kuangbin带你飞]专题四 最短路练习 A POJ 2387
- [kuangbin带你飞]专题四 最短路练习 G POJ 1502
- [kuangbin带你飞]专题四 最短路练习 I POJ 2240
- [kuangbin带你飞]专题四 最短路练习
- [kuangbin带你飞]专题四 最短路练习
- [kuangbin带你飞]专题四 最短路练习 B POJ 2253
- [kuangbin带你飞]专题四 最短路练习 L POJ 2502
- [kuangbin带你飞]专题四 最短路练习 P
- [kuangbin带你飞]专题四 最短路练习 C POJ 1797
- [kuangbin带你飞]专题四 最短路练习 H POJ 3660
- [kuangbin带你飞]专题四 最短路练习-E
- [kuangbin带你飞]专题四 最短路练习 J POJ 1511
- [kuangbin带你飞]专题四 最短路练习 P HDU 4725
- [kuangbin带你飞]专题四 最短路练习 R HDU 437
- [kuangbin带你飞]专题四 最短路练习
- [kuangbin带你飞]专题四 最短路练习D
- 【算法系列学习】Dijkstra求最短路 [kuangbin带你飞]专题四 最短路练习 D - Silver Cow Party
- [kuangbin带你飞]专题四 最短路练习 B
- 【算法系列学习】Dijkstra单源最短路 [kuangbin带你飞]专题四 最短路练习 A - Til the Cows Come Home