传送门: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赛 地铁的更多相关文章

  1. 牛客国庆集训派对Day6 A Birthday 费用流

    牛客国庆集训派对Day6 A Birthday:https://www.nowcoder.com/acm/contest/206/A 题意: 恬恬的生日临近了.宇扬给她准备了一个蛋糕. 正如往常一样, ...

  2. 2019牛客国庆集训派对day5

    2019牛客国庆集训派对day5 I.Strange Prime 题意 \(P=1e10+19\),求\(\sum x[i] mod P = 0\)的方案数,其中\(0 \leq x[i] < ...

  3. 牛客编程巅峰赛S2第4场

    牛客编程巅峰赛S2第4场 牛牛摆玩偶 题目描述 牛牛有\(n(2 \leq n \leq 10^5)(2≤n≤105)\)个玩偶,牛牛打算把这n个玩偶摆在桌子上,桌子的形状的长条形的,可以看做一维数轴 ...

  4. 牛客集训 湖南省赛E题 Grid 动态开点线段树

    国庆牛客集训的题,正好准备好好训练线段树,想起来就补一下. 题意很简单,两种操作行合并或者列合并,每个操作后计算有多少个子块. 这题应该先推导公式,行操作或者列操作只有一种的时候,很简单,总数就是n* ...

  5. 牛客国庆集训派对Day1 L-New Game!(最短路)

    链接:https://www.nowcoder.com/acm/contest/201/L 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  6. 牛客国庆集训派对Day4 J-寻找复读机

    链接:https://www.nowcoder.com/acm/contest/204/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  7. 牛客国庆集训派对Day4 I-连通块计数(思维,组合数学)

    链接:https://www.nowcoder.com/acm/contest/204/I 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  8. 牛客国庆集训派对Day1-C:Utawarerumono(数学)

    链接:https://www.nowcoder.com/acm/contest/201/C 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  9. 牛客红包OI赛 B 小可爱序列

    Description 链接:https://ac.nowcoder.com/acm/contest/224/B 来源:牛客网 "我愿意舍弃一切,以想念你,终此一生." " ...

随机推荐

  1. seleium 滑动到底部

    def scroll(driver): driver.execute_script(""" (function () { var y = document.body.sc ...

  2. Streamy障碍二:超大排序合并

  3. epoll简介(一)

    一:概述   1:简介 EPOLL类似于POLL,是Linux特有的一种IO多路复用的机制.它在2.5.44内核中引入. 对于大量的描述符处理,EPOLL更有优势,它提供了三个系统调用来创建管理epo ...

  4. uva 12003 Array Transformer (线段树套平衡树)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  5. Element-ui学习笔记1

    1.col,row布局注意事项 el-row el-col gutter就是css,span的时候宽度是按boder-box来计算. 将 type 属性赋值为 'flex',可以启用 flex 布局, ...

  6. Android ViewGroup点击效果(背景色)

    在开发Android应用的界面时,我们必然会用到本文ViewGroup,尤其是FrameLayout,LinearLayout,RelativeLayout等ViewGroup的子类: 在一些情况下, ...

  7. 微软的可疑更新DhMachineSvc.exe

    最近微软大范围的推出了一个只针对中国的更新,包含了DhMachineSvc.exe,也就是所谓的'微软设备健康助手服务'. 这个更新很神秘,首先这个更新只针对中国区,其次这个更新支持WinXP,第三这 ...

  8. java 创建线程方式

    1.继承Thread类 子类覆写父类中的run方法,将线程运行的代码存放在run中. 建立子类对象的同时线程也被创建. 通过调用start方法开启线程. 2.实现Runnable接口 子类覆盖接口中的 ...

  9. Vue v-if和v-show的使用.区别

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. P1056 骑士游历

    题目描述 给出一个8*8的空棋盘,其中行由a-h编号,列由1-8编号. 再给出起点和终点,问,骑士至少需要几步可以从起点移到终点.骑士是走日的.类似于中国象棋的马. 输入格式 输入两个字符串,每个字符 ...