牛客国庆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 来源:牛客网 "我愿意舍弃一切,以想念你,终此一生." " ...
随机推荐
- Java成员方法,构造方法
//作者:qingfeng//2017/2/17//功能:理解类的成员方法和构造方法class CreatWays{ public static void main(String args[]){ ...
- Xcode无法退出,报错提示 The document “xxx.h” could not be saved. The file doesn’t exist.
记录一个问题 场景:Xcode编辑一个工程时直接在工程内部修改了某个目录的文件夹名字,而后删除了其下的某 .h.m 文件 之后总是提示上述错误且无法强制退出Xcode,clean等操作基本没用 查找本 ...
- Android中使用Apache common ftp进行下载文件
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/birdsaction/article/details/36379201 在Android使用ftp下 ...
- 洛谷P2820 局域网
#include<bits/stdc++.h> using namespace std; ; ; int n,k,sum,tot; struct node{ int cnt,fa; }f[ ...
- 选用适合的ORACLE优化器
ORACLE的优化器共有3种: a. RULE (基于规则) b. COST (基于成本) c. CHOOSE (选择性) 设置缺省的优化器,可以通过对init.ora文件中OPTIMIZER ...
- part10.3-字符驱动访问揭秘
- H3C 轮询DCC和共享DCC
- html5 canvas 3d屏保 源码
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <met ...
- java super关键字和调用父类构造方法
表示父类对象的默认引用 如果子类要调用父类被覆盖的实例方法,可用super作为调用者调用父类被覆盖的实例方法. 使用super调用父类方法 使用super调用父类的构造方法 调用构造方法 本类中调用另 ...
- Html5 @media + css3 媒体查询
css3 media媒体查询器用法总结 随着响应式设计模型的诞生,Web网站又要发生翻天腹地的改革浪潮,可能有些人会觉得在国内IE6用户居高不下的情况下,这些新的技术还不会广泛的蔓延下去,那你就错 ...