BZOJ2292——【POJ Challenge 】永远挑战
1、题意:dijkstra模板题,存点模板
#include <queue> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; #define M 2000010 #define inf 1047483647 inline int read(){ char ch = getchar(); int x = 0, f = 1; while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while('0' <= ch && ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } namespace dijkstra{ struct Node{ int d, u; inline bool operator < (const Node& rhs) const{ return d > rhs.d; } }; int d[M], done[M]; priority_queue<Node> Q; struct Edge{ int u, v, w, next; } G[M]; int head[M], tot; int n; //number of points inline void init(){ memset(head, -1, sizeof(head)); tot = -1; } inline void add(int u, int v, int w){ G[++ tot] = (Edge){u, v, w, head[u]}; head[u] = tot; } inline void get_dis(int s){ for(int i = 1; i <= n; i ++) d[i] = inf; d[s] = 0; while(!Q.empty()) Q.pop(); Q.push((Node){0, s}); memset(done, 0, sizeof(done)); while(!Q.empty()){ Node u = Q.top(); Q.pop(); int x = u.u; if(done[x]) continue; done[x] = 1; for(int i = head[x]; i != -1; i = G[i].next){ Edge& e = G[i]; if(d[e.v] > d[x] + e.w){ d[e.v] = d[x] + e.w; Q.push((Node){d[e.v], e.v}); } } } } } using namespace dijkstra; int main(){ n = read(); int m = read(); init(); for(int i = 1; i <= m; i ++){ int u = read(), v = read(), w = read(); add(u, v, w); } get_dis(1); printf("%d\n", d[n]); return 0; }
BZOJ2292——【POJ Challenge 】永远挑战的更多相关文章
- bzoj2292【POJ Challenge 】永远挑战*
bzoj2292[POJ Challenge ]永远挑战 题意: 有向图,每条边长度为1或2,求1到n最短路.点数≤100000,边数≤1000000. 题解: 有人说spfa会T,所以我用了dijk ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 553 Solved: 230[Submit][ ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
随机推荐
- [LeetCode] Implement Queue using Stacks 用栈来实现队列
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...
- Ubuntu 16.04 LAMP server 指南 - 配置 Apache2.4,PHP7,和MariaDB(而不是MySQL)
翻译自:https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/ 昨天在虚 ...
- 【MySQL】mysql workbench
1.导入,导出,数据之间的传输[两台服务器]2.连接管理3.服务器管理4.表的管理
- AngularJS模型
1. AngularJS模型主要就是使用的AngularJS的ng-model指令. ng-model指令可以将输入域的值与 AngularJS 创建的变量绑定. <!DOCTYPE html& ...
- React JS的基本用法[ES5,纯前端写法]
1.配置webpack npm install -g webpack #webpack的cli npm install -g webpack-dev-server #webpack自带的服务器 npm ...
- Codeforces #364 DIV2
~A题 A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- lua命令行编译
http://jingyan.baidu.com/article/359911f551917457fe0306e5.html 最后将生成的.exe解释器的根目录配置到系统环境变量 copy lua.c ...
- mysql Packet for query is too large (1185 > 1024)异常
注:最近mysql一直提示如下错误 Packet for query is too large (1185 > 1024). You can change this value on the s ...
- 几个MQTT的知识点
开始正文前需要感谢一下网友“小龙”和emqtt.io群里的网友们的帮助,本人刚刚开始使用MQTT有很多不懂的地方,在emqtt.io群里询问解决方法的时候,“小龙”给我详细的讲解了一些MQTT的知识点 ...
- Mysql两个引擎对比
Mysql两个引擎对比 MyIsam 优点: 1.支持B-Tree检索和文本全文检索 2.性能消耗方面相对较低 3.支持全表(table)锁 缺点: ...