牛客国庆days赛 地铁
传送门:https://ac.nowcoder.com/acm/problem/52805
我佛了,还能跑边图啊!!!
跑边图不能用vector啦啦啦啦啦
具体也不难,就直接上代码了
#include<cstdio>
#include<queue>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const int INF = 0x3f3f3f3f;
int n, m;
int head[maxn]; struct edge {
int p;
ll len;
edge(int _p, ll _len) :p(_p), len(_len) {}
}; struct Node {
int p;
ll len;
ll c;
int next;
}G[maxn]; int cnt = 1; void add(int be, int en, ll c,ll len) {
G[cnt].p = en; G[cnt].next = head[be]; head[be] = cnt; G[cnt].len = len; G[cnt].c = c;//头插法
cnt++;
} bool operator <(const edge a, const edge b) {
return a.len > b.len;
}
ll dis[maxn];
int vis[maxn]; ll dij() {
for (int i = 0; i < maxn; i++) dis[i] = 1e17;
priority_queue<edge>que; for (int i = head[1]; i; i = G[i].next) {
dis[i] = G[i].len;
que.push(edge(i, dis[i]));
}
ll a = 1e16;
while (que.size()) {
edge ans = que.top();
que.pop();
if (vis[ans.p]) continue;
vis[ans.p] = 1; int x = G[ans.p].p;
if (n == x) a = min(dis[ans.p], a); for (int i = head[x]; i; i = G[i].next) { if (dis[i] > dis[ans.p] + G[i].len + abs(G[ans.p].c - G[i].c)) {
dis[i] = dis[ans.p] + G[i].len + abs(G[ans.p].c - G[i].c); que.push(edge(i, dis[i]));
}
}
}
return a;
}
int main() { int be, en;
ll c, len;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d %d %lld %lld", &be, &en, &c, &len);
add(be, en, c, len);
add(en, be, c, len);
}
ll ans = dij();
cout << ans << endl;
return 0;
}
牛客国庆days赛 地铁的更多相关文章
- 牛客国庆集训派对Day6 A Birthday 费用流
牛客国庆集训派对Day6 A Birthday:https://www.nowcoder.com/acm/contest/206/A 题意: 恬恬的生日临近了.宇扬给她准备了一个蛋糕. 正如往常一样, ...
- 2019牛客国庆集训派对day5
2019牛客国庆集训派对day5 I.Strange Prime 题意 \(P=1e10+19\),求\(\sum x[i] mod P = 0\)的方案数,其中\(0 \leq x[i] < ...
- 牛客编程巅峰赛S2第4场
牛客编程巅峰赛S2第4场 牛牛摆玩偶 题目描述 牛牛有\(n(2 \leq n \leq 10^5)(2≤n≤105)\)个玩偶,牛牛打算把这n个玩偶摆在桌子上,桌子的形状的长条形的,可以看做一维数轴 ...
- 牛客集训 湖南省赛E题 Grid 动态开点线段树
国庆牛客集训的题,正好准备好好训练线段树,想起来就补一下. 题意很简单,两种操作行合并或者列合并,每个操作后计算有多少个子块. 这题应该先推导公式,行操作或者列操作只有一种的时候,很简单,总数就是n* ...
- 牛客国庆集训派对Day1 L-New Game!(最短路)
链接:https://www.nowcoder.com/acm/contest/201/L 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 牛客国庆集训派对Day4 J-寻找复读机
链接:https://www.nowcoder.com/acm/contest/204/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 牛客国庆集训派对Day4 I-连通块计数(思维,组合数学)
链接:https://www.nowcoder.com/acm/contest/204/I 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 牛客国庆集训派对Day1-C:Utawarerumono(数学)
链接:https://www.nowcoder.com/acm/contest/201/C 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 牛客红包OI赛 B 小可爱序列
Description 链接:https://ac.nowcoder.com/acm/contest/224/B 来源:牛客网 "我愿意舍弃一切,以想念你,终此一生." " ...
随机推荐
- 从零学React Native之10Text
在React Native开发中,所有需要显示的字符串文本都需要放置在Text或者Text的子组件中.虽然在之前的文章中多次使用了Text组件,但是Text组件还是值得专门学习的, 并没有想象中的那么 ...
- HDU_1087-Super Jumping! Jumping! Jumping!
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- Hbase数据模型 行
- C++ 输出到文本文件
输出到文本文件 就像从文件输入数据一样,你也可以将数据输出到文件.假设你有一个矩阵,你想把结果保存到一个文本文件中.你会看到,将矩阵输出到文件的代码和将矩阵输出到终端的代码非常相似. 你需要在本地运行 ...
- selenium webdriver学习(八)------------如何操作select下拉框(转)
selenium webdriver学习(八)------------如何操作select下拉框 博客分类: Selenium-webdriver 下面我们来看一下selenium webdriv ...
- LightOJ 1269 Consecutive Sum (Trie树)
Jan's LightOJ :: Problem 1269 - Consecutive Sum 题意是,求给定序列的中,子序列最大最小的抑或和. 做法就是用一棵Trie树,记录数的每一位是0还是1.查 ...
- 原生js设置audio在谷歌浏览器自动播放
https://www.cnblogs.com/sandraryan/ 谷歌浏览器更新后禁止了autoplay功能,但是有时候可能会需要自动播放. 研究了一段代码. <!DOCTYPE html ...
- 2014年NOIP普及组复赛题解
题目涉及算法: 珠心算测验:枚举: 比例简化:枚举: 螺旋矩阵:模拟: 子矩阵:状态压缩/枚举/动态规划 珠心算测验 题目链接:https://www.luogu.org/problem/P2141 ...
- css技巧 1200px居中容器中某个div增加横屏背景
<div class='container' style='width:1200px;margin:0 auto;'> <div style='width:200px;margin: ...
- JS精度问题,解决方案 math.js
JS精度问题 Vue中使用 解决方案 math.js npm install mathjs import { create, all } from 'mathjs' const config = ...