HDOJ 4318 —— dijkstra + 优先队列 求最短路
来源:互联网 发布:几何画图软件 编辑:程序博客网 时间:2024/05/21 21:41
Power transmission
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1591 Accepted Submission(s): 600
Problem Description
The project West-East power transmission is famous around the world. It transmits the electricity from western areas to east China. There are many nodes in the power system. Each node is connected with several other nodes in the system by cable. Power can be only transmitted between two connected nodes. For each node, it can’t send power to two or more other nodes at the same time.
As we have all known, power will be loss during the transmission. Bob is the chief engineer of the project. He wants to build a transmission line which send power from one node to another node and minimize the power loss at the same time. Now he asks you to help him solve the problem.
As we have all known, power will be loss during the transmission. Bob is the chief engineer of the project. He wants to build a transmission line which send power from one node to another node and minimize the power loss at the same time. Now he asks you to help him solve the problem.
Input
There are several test cases. For each test case, the first line contains an integer N (0 < N ≤ 50000) which represents the number of nodes in the power system. Then there will be N groups of data following. For the i-th(0 < i ≤ N) group, the first line is an integer ki (ki ≤ 50), which means the node i is connected with ki nodes. The rest of the i-th group data are divided into ki lines. Each line contains an integer ai (0 < ai ≤ N, ai ≠ i) and an integer bi (0 ≤ bi ≤ 100), which represents power can be transmitted from node i to ai and will loss bi% while transmitting. The last line of input data contains three integers separated by single spaces. The first one is s, the second is t (0 < s, t ≤ N), and the third is the total power M (0 < M ≤ 10^6) at node s.
Output
For each test case, output the minimum of loss power while transmitting from node s to node t. The result should be printed with two digits to the right of the decimal point. If power cannot be transmitted from node s to node t, output “IMPOSSIBLE!” in a line.
Sample Input
422 503 7021 304 2021 104 4001 4 100
Sample Output
60.00HintIn the sample, the best transmission line is 1 -> 2 -> 4, loss power is 100 * 50% + 100 * (100%-50%)*20% = 60.00
Author
TJU
Source
2012 Multi-University Training Contest 2
Recommend
zhuyuanchen520
一道简单的最短路,无trick。据说O(n^2)也能过?
#include <cstdio>#include <cmath>#include <algorithm>#include <iostream>#include <cstring>#include <map>#include <string>#include <stack>#include <cctype>#include <vector>#include <queue>#include <set>#include <utility>using namespace std;//#define Online_Judge#define outstars cout << "***********************" << endl;#define clr(a,b) memset(a,b,sizeof(a))#define lson l , mid , rt << 1#define rson mid + 1 , r , rt << 1 | 1//#define mid ((l + r) >> 1)#define mk make_pair#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)const int MAXN = 50000 + 500;const long long LLMAX = 0x7fffffffffffffffLL;const long long LLMIN = 0x8000000000000000LL;const int INF = 0x3f3f3f3f;const int IMIN = 0x80000000;const double E = 2.718281828;#define eps 1e-8#define DEBUG 1#define mod 1000000007typedef long long LL;const double PI = acos(-1.0);typedef double D;typedef pair<int , int> pi;///#pragma comment(linker, "/STACK:102400000,102400000")__int64 a[10050];int n , m;int vis[MAXN];double dis[MAXN] , sum;int st , en ;struct Edge{ double w; int v; Edge(int vv , double ww) { v = vv; w = ww; }};vector <Edge> e[MAXN];struct Node{ int v ; double w; Node(int vv , double ww) { v = vv; w = ww; } bool operator < (const Node &a)const { return w < a.w; }};priority_queue <Node> pq;void dijkstra(){ FORR(i , 1 , n) { vis[i] = 0; dis[i] = -1.0; } while(!pq.empty())pq.pop(); pq.push(Node(st , sum)); while(!pq.empty()) { Node cur = pq.top(); pq.pop(); int u = cur.v; double w = cur.w; if(vis[u])continue; vis[u] = 1; dis[u] = w; FOR(i , 0 , e[u].size()) { int uu = e[u][i].v; double ww = e[u][i].w; if(dis[uu] < w * ww) { dis[uu] = w * ww; pq.push(Node(uu , dis[uu])); } } }}int main(){ while(~scanf("%d" , &n)) { clr(e , 0); FORR(i , 1, n) { int v ; double w; scanf("%d" , &m); while(m--) { scanf("%d%lf" , &v , &w); e[i].push_back(Edge(v, (100.0 - w) / 100.0)); } } scanf("%d%d%lf" , &st , &en , &sum); dijkstra(); if(dis[en] == -1)puts("IMPOSSIBLE!"); else printf("%.2lf\n" , sum - dis[en]); } return 0;}
- HDOJ 4318 —— dijkstra + 优先队列 求最短路
- 优先队列Dijkstra实现最短路算法
- 最短路(Dijkstra+优先队列)
- hdu 2112 最短路 dijkstra优先队列
- hdu2544 最短路(dijkstra/优先队列)
- dijkstra + 优先队列 最短路 [sdut 2143]
- Codeforces 128B. String(优先队列,模仿dijkstra求最短路)
- HDU 2544 最短路 静态邻接表+优先队列 dijkstra
- hdu 2066最短路 dijkstra 及其优先队列优化
- [最短路]使用优先队列优化的Dijkstra算法
- hdu 2544 最短路(Dijkstra 邻接表+优先队列)
- 【poj 1724】 ROADS 最短路(dijkstra+优先队列)
- 图论: 优先队列 + dijkstra最短路…
- 算法训练 最短路 dijkstra优先队列和spfa
- 最短路 Dijkstra+优先队列与SPFA 模版
- 【原创】最短路模板 Floyd,优先队列优化dijkstra,SPFA
- Dijkstra 求最短路
- Dijkstra 求最短路
- 讲解NoSQL的文章整理收集
- 学习笔记 线段树
- usb协议
- 有关数据库范式
- 博客推荐
- HDOJ 4318 —— dijkstra + 优先队列 求最短路
- MySQL行锁小结
- JavaScript复习
- IBM Security AppScan Standard【Web应用安全测试工具】
- java自带的定时任务的实现
- MySQL存储引擎
- 【API文档】更有效率的载入图片【1】
- cimg编程灰度转换示例
- MySQL调优