传送门: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. Python中并发前戏之操作系统

    进程: 1.串行: 一个任务完完整整地运行完毕后,才能运行下一个任务 2.并发 看起来多个任务是同时运行的即可,单核也可以实现并发 3.并行: 真正意义上多个任务的同时运行,只有多核才实现并行 1.什 ...

  2. android去掉layout顶部的阴影(状态栏下边的阴影)

    http://blog.csdn.net/kepoon/article/details/7207100

  3. ansible基础☞第一条命令

    我的两个测试机: 系统: ubuntu 16.04.2 ansible-master: 192.168.0.107 ansible-slave: 192.168.0.108 ansible版本: ro ...

  4. jmeter响应代码为乱码

    1.在请求的前面添加BeanShell PostProcessor 输入prev.setDataEncoding("UTF-8"); 2.当响应数据或响应页面没有设置编码时,jme ...

  5. Open Source GIS and Freeware GIS Applications

    Open Source GIS and Freeware GIS Applications   An open source application by definition is software ...

  6. JVM -XX: 参数列表

    功能开关: 参数 默认值或限制 说明 参数 默认值 功能 -XX:-AllowUserSignalHandlers 限于Linux和Solaris,默认不启用 允许为java进程安装信号处理器,信号处 ...

  7. linux下oracle查询中文乱码

    export NLS_LANG=AMERICAN_AMERICA.UTF8

  8. Logback新版本报no applicable action for [Encoding]问题

    logback.xml配置文件如下: <?xml version="1.0" encoding="UTF-8"?> <configuratio ...

  9. codeforces1238-div2

    C 目前在h的高度,1~h每一个台阶要么处于out的状态,要么处于in的状态,问最少改变几个台阶的状态,使得能够从h的高度到0. 下降的唯一的方式,拉动lever,h-1的状态取反,下落的最大的高度不 ...

  10. 【原生JS】键盘事件

    视频播放器音量调节效果. 效果图:“我很丑!~可是我有音乐和啤酒!~” HTML: <!DOCTYPE html> <html> <head> <meta c ...