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 ...
随机推荐
- UVIYN的基本设置
- MacOS配置.bash_profile,重启终端后配置失效和MacOS .zshrc does not exist问题
MacOS配置.bash_profile,重启终端后配置失效和MacOS .zshrc does not exist问题 场景 在Mac中配置golang环境变量更改GOPATH路径,在~/.ba ...
- 一网打尽枚举操作 .net core
本文介绍如何使用枚举以及,如何将枚举类型更好的应用于项目中,看完本文可以有序的将项目中的枚举更容易的使用到每个角落. 1,分析枚举 /// <summary> /// 性别 /// < ...
- 关于一个服务和api监控的界面,涉及ajax-jsonp,promise应用
<!DOCTYPE html> <html class="mobile hairline" data-dpr=""> <head& ...
- Ultra-QuickSort (求逆序数+离散化处理)、Cows、Stars【树状数组】
一.Ultra-QuickSort(树状数组求逆序数) 题目链接(点击) Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total ...
- Ubuntu:E: Sub-process /usr/bin/dpkg returned an error code (1)
Ubuntu系统安装软件时报以下错误: E: Sub-process /usr/bin/dpkg returned an error code (1) 解决: mv /var/lib/dpkg/inf ...
- 数据处理一条龙!这15个Python库不可不知
如果你是一名数据科学家或数据分析师,或者只是对这一行业感兴趣,那下文中这些广受欢迎且非常实用的Python库你一定得知道. 从数据收集.清理转化,到数据可视化.图像识别和网页相关,这15个Python ...
- 从0到70%:Chrome上位揭秘!
最近的数据显示,Chrome在2020年4月的市场份额达到了70%左右,把微软的Edge和Firefox远远甩在身后,毫无疑问,Chrome赢得了第二次游览器之战,成为新一代王者. Chrome的第一 ...
- c常用函数-strcat 和 strncat
strcat 和 strncat strcat与strncat都是字符串连接函数,功能上稍有区别: strcat可以把一个字符串的全部内容复制到另一个字符串的后面; strncat则是把一个字符串的指 ...
- 小白的mapbox学习之路-显示地图
刚接触mapbox,只是简单记下自己的学习之路,如有错误,欢迎大神指正 1-头部引入链接 2-body中定义一个div块,用来显示地图 3-在script中创建一个map对象,并设置相关参数 mapb ...