Buy A Ticket(图论)
Buy A Ticket
题目大意
每个点有一个点权,每个边有一个边权,求对于每个点u的\(min(2*d(u,v)+val[v])\)(v可以等于u)
solution
想到了之前的虚点,方便统计终点的权值,将所有点和虚点建边,边权不变,这样只需要求虚点到其他点的最短路即可,就将多源最短路问题转换成了单源最短路
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
struct Edge {
int v, next;
long long w;
} edges[1000000];
int head[300000], tot, vis[250000], n, m, u ,v;
long long dis[250000], a[230000], w;
void add(int x, int y, long long w) { edges[++tot] = (Edge){y, head[x], w}, head[x] = tot; }
struct node {
int id;
long long w;
bool operator<(node b) const { return w > b.w; }
};
void dijkstra(int x) {
priority_queue<node> queue;
dis[x] = 0;
queue.push((node){x, 0});
while (!queue.empty()) {
node newn = queue.top();
queue.pop();
if (vis[newn.id]) continue;
vis[newn.id] = 1;
for (int i = head[newn.id]; i; i = edges[i].next) {
int v = edges[i].v;
if (dis[v] > dis[newn.id] + edges[i].w) {
dis[v] = dis[newn.id] + edges[i].w;
queue.push((node){v, dis[v]});
}
}
}
}
int main() {
memset(dis, 0x3f, sizeof(dis));
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) scanf("%d%d%lld", &u, &v, &w), add(u, v, 2 * w), add(v, u, 2 * w);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), add(0, i, a[i]);
dijkstra(0);
for (int i = 1; i <= n; i++) printf("%lld ", dis[i]);
return 0;
}
Buy A Ticket(图论)的更多相关文章
- Buy the Ticket{HDU1133}
Buy the TicketTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 【HDU 1133】 Buy the Ticket (卡特兰数)
Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...
- 【高精度练习+卡特兰数】【Uva1133】Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Buy the Ticket(卡特兰数+递推高精度)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- hdu 1133 Buy the Ticket(Catalan)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Codeforces 938 D. Buy a Ticket (dijkstra 求多元最短路)
题目链接:Buy a Ticket 题意: 给出n个点m条边,每个点每条边都有各自的权值,对于每个点i,求一个任意j,使得2×d[i][j] + a[j]最小. 题解: 这题其实就是要我们求任意两点的 ...
- HDUOJ---1133(卡特兰数扩展)Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Codeforces 938.D Buy a Ticket
D. Buy a Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- hdu 1133 Buy the Ticket (大数+递推)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- PAT 有理数四则运算
本题要求编写程序,计算 2 个有理数的和.差.积.商. 输入格式: 输入在一行中按照 a1/b1 a2/b2 的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前 ...
- node实现图片分割
前言 最近,女王大大日常找我弄图片,本来之前我一直是ps帮他弄得,后来- -,ps不能分割过长的图片,我就想想能不能通过代码来帮他实现好了. 经过我在npm搜索一番,发现没有一个纯代码层面的high ...
- ES索引操作
1.创建测试索引 PUT /test_index{ "mappings": { "test_type":{ "properties": { ...
- Matplotlib 的正确使用方法,画一张好看的图
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:Python中文社区 本文用的数据如图所示,Dataframe中显示 ...
- “进大厂大半年,每个月都想走!”大公司 VS 小公司到底该如何选择?
前言 江湖风云不断,有人吐槽阿里996,也有人吐槽华为狼性文化,这不,就看到有腾讯员工吐槽“进腾讯大半年,每个月都想走!” “和我一样,进去一周就想走”.“我都陷入自我怀疑了,以为自己适应不了大公司” ...
- Copy-on-write + Proxy = ?
一.简介 Immer (German for: always) is a tiny package that allows you to work with immutable state in a ...
- 在c++MFC下用PCL显示操作点云文件 MFC对话框显示操作PCL点云
原文作者:aircraft 原文地址:https://www.cnblogs.com/DOMLX/p/13115873.html 第一步 下载PCL库 我的版本是1.8.1的 你都要MFC下跑PCL ...
- 容器编排工具之Docker-compose
前文我们聊了下docker私有仓库harbor的搭建,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13061984.html:在上一篇博客的末尾,我们简单聊了 ...
- 读懂操作系统之虚拟内存TLB与缓存(cache)关系篇(四)
前言 前面我们讲到通过TLB缓存页表加快地址翻译,通过上一节缓存原理的讲解为本节做铺垫引入TLB和缓存的关系,同时我们来完整梳理下从CPU产生虚拟地址最终映射为物理地址获取数据的整个过程是怎样的,若有 ...
- 私有云nextcloud、seafile、syncthing的比较
可选 nextcloud.seafile.syncthing 1. seafile https://www.jianshu.com/p/43f570118e63 https://www.jianshu ...