牛客国庆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 来源:牛客网 "我愿意舍弃一切,以想念你,终此一生." " ...
随机推荐
- 【牛腩视频】之SQL触发器 标签: 数据库 2015-05-23 09:44 1339人阅读 评论(40) 收藏
之前在学习机房管理系统.net版的时候,已经写过了关于数据库的操作,但是现在开始学习牛腩,才发现之前自己理解的太浅显,很多东西看似好像会了,不去实际操作一下,不把代码从头到尾敲出来,到头来还是不会,所 ...
- SDUT-2772_数据结构实验之串一:KMP简单应用
数据结构实验之串一:KMP简单应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定两个字符串string1和str ...
- @codeforces - 1214G@ Feeling Good
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n*m 的 01 矩阵 A,一开始所有格子都为 0. ...
- 洛谷P1060 开心的金明
//01背包 价值等于重要度乘体积 #include<bits/stdc++.h> using namespace std; ; ; int n,m,v[maxn],w[maxn],f[m ...
- Python基础:22__slots__类属性
1:工厂函数 由于类型和类的统一,因而可以子类化Python数据类型.但是所有的Python 内建的转换函数现在都是工厂函数.当这些函数被调用时,你实际上是对相应的类型进行实例化.比如下面的函数都已经 ...
- python selenium 处理悬浮窗口(baidu tj_more)
python selenium 处理悬浮窗口 from selenium.webdriver.common.action_chains import ActionChainsActionChains( ...
- Android Studio(一):介绍、安装、配置
Android Studio相关博客: Android Studio(一):介绍.安装.配置 Android Studio(二):快捷键设置.插件安装 Android Studio(三):设置Andr ...
- 我爱自然语言处理bert ner chinese
BERT相关论文.文章和代码资源汇总 4条回复 BERT最近太火,蹭个热点,整理一下相关的资源,包括Paper, 代码和文章解读. 1.Google官方: 1) BERT: Pre-training ...
- OpenCV 安装与调试
Visual Studio 是微软提供的面向任何开发者的同类最佳工具. OpenCV(开源计算机视觉库)是一个开源的计算机视觉和机器学习软件库. 目前最新版本:Visual Studio 2019.O ...
- [Err] 1062 - Duplicate entry '0' for key 'PRIMARY'
问题描述: sql语句执行的时候,插入语句无法正确执行 问题原因: 主键 重复 出现 0 解决方案: 将主键设置为自增 然而,设置自增后还是可能会出现下面的问题 #1062 – Duplicate e ...