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 ...
随机推荐
- cf Round 633
A.Rebus(思维题) 给出一个这种形式的表达式 ? + ? - ? + ? = n.要求用1-n的数字填充疑问号使等式成立,如果不存在这样的方式,则输出不可能.存在则输出任意的方式. 移项可以变成 ...
- [LeetCode] Nested List Weight Sum 嵌套链表权重和
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- 为什么要在游戏开发中使用ECS模式
http://www.richardlord.net/blog/why-use-an-entity-framework Why use an entity system framework for g ...
- Codeforces Round #384(div 2)
A 题意:有n个机场处于一直线上,可两两到达,每个机场只可能属于两家公司中的一家(用0,1表示),现在要从a机场到b机场,可任意次转机.若机场i与机场j从属同一公司,则费用为0,否则费用为1.问最小费 ...
- Todo list and 学习心得
1. 理论实践要区分起来学习,结合起来运用. 2. 内事不决问百度外事不决问谷歌 3. 一个人走的快,一群人走得远或者更快 2016-09-01 23:27:58 九月目标:对程序从编译到执行的整个 ...
- 【ios开发】UITableViewCell的重用
移动开发需要解决的一个问题就是资源稀缺的问题.多数情况下是内存问题. 虽然现在的手机都号称大内存,高配置.但是移动app所占用的资源也在跟着不断膨胀, 也是造成内存不足的主要原因. 在前面的例子中,还 ...
- centos 6.5 redis 安装
安装教程有用的地址 https://my.oschina.net/u/2478188/blog/726984: 错误1 Redis: You need tcl 8.5 or newer in orde ...
- vector迭代器用法
#include<iostream> #include<vector> using namespace std; int main() { vector<int> ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'dd' in 'where clause'
今天在使用mysql数据库查找数据的时候报错,错误信息如下: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown co ...
- XCode8 App上传AppStore更新
1.在这个网站中https://itunesconnect.apple.com 点击"我的APP" 选取需要更新的app 2.点击加号 版本或平台,填写对应的更新版本 3.配置Xc ...