大意: n节点无向图, 点$i$到点$j$的花费为$2dis(i,j)+a[j]$, 对于每个点, 求最少花费.

每条边权翻倍, 源点S向所有点$i$连边, 权为$a[i]$, 答案就为$S$到每个点的最短路距离.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n, m, vis[N];
struct _ {
int to;
ll w;
bool operator < (const _ &rhs) const {
return w>rhs.w;
}
};
vector<_> g[N];
priority_queue<_> q;
ll d[N]; void Dij(int s) {
memset(d,0x3f,sizeof d);
q.push({s,d[s]=0});
while (q.size()) {
int u = q.top().to; q.pop();
if (vis[u]) continue;
vis[u] = 1;
for (_ e:g[u]) {
ll dd = d[u]+e.w;
int v=e.to;
if (dd<d[v]) q.push({v,d[v]=dd});
}
}
} int main() {
scanf("%d%d", &n, &m);
REP(i,1,m) {
int u, v;
ll w;
scanf("%d%d%lld", &u, &v, &w);
g[u].pb({v,2*w});
g[v].pb({u,2*w});
}
REP(i,1,n) {
ll t;
scanf("%lld", &t);
g[n+1].pb({i,t});
}
Dij(n+1);
REP(i,1,n) printf("%lld ", d[i]);hr;
}

Buy a Ticket CodeForces - 938D (dijkstra)的更多相关文章

  1. 【Educational Codeforces Round 38】D. Buy a Ticket 堆优化Dijkstra

    题意 给定一张无向图,对每个点$i\in S$求$\min_{j\in S} {2\times d(i,j)+a_j}$ 考虑多源多汇最短路会超时,换个角度考虑每个$j$,如果$j=i$,那么答案为$ ...

  2. Codeforces 938 D. Buy a Ticket (dijkstra 求多元最短路)

    题目链接:Buy a Ticket 题意: 给出n个点m条边,每个点每条边都有各自的权值,对于每个点i,求一个任意j,使得2×d[i][j] + a[j]最小. 题解: 这题其实就是要我们求任意两点的 ...

  3. Codeforces 938D Buy a Ticket

    Buy a Ticket 题意要求:求出每个城市看演出的最小费用, 注意的一点就是车票要来回的. 题解:dijkstra 生成优先队列的时候直接将在本地城市看演出的费用放入队列里, 然后直接跑就好了, ...

  4. Codeforces 938D Buy a Ticket (转化建图 + 最短路)

    题目链接  Buy a Ticket 题意   给定一个无向图.对于每个$i$ $\in$ $[1, n]$, 求$min\left\{2d(i,j) + a_{j}\right\}$ 建立超级源点$ ...

  5. 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 ...

  6. Buy A Ticket(图论)

    Buy A Ticket 题目大意 每个点有一个点权,每个边有一个边权,求对于每个点u的\(min(2*d(u,v)+val[v])\)(v可以等于u) solution 想到了之前的虚点,方便统计终 ...

  7. Buy the Ticket{HDU1133}

    Buy the TicketTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. 【HDU 1133】 Buy the Ticket (卡特兰数)

    Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...

  9. 【高精度练习+卡特兰数】【Uva1133】Buy the Ticket

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

随机推荐

  1. [BZOJ4827][Hnoi2017]礼物(FFT)

    4827: [Hnoi2017]礼物 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1315  Solved: 915[Submit][Status] ...

  2. 线程系列5--java中的ThreadLocal类实现线程范围内的数据共享(二)

    ThreadLocal类可以理解成一个类似与map集合使用,以当前线程当做key 来使用,将线程氛围内需要共享的数据当做value,形成键值对的形式使用.ThreadLocal和线程同步机制都是为了解 ...

  3. Bug集锦-Spring Cloud Feign调用其它接口报错

    问题描述 Spring Cloud Feign调用其它服务报错,错误提示如下:Failed to instantiate [java.util.List]: Specified class is an ...

  4. Mysql中两个select语句的连接

    Mysql中两个select语句连接需要用到操作符 SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥 ...

  5. 如何利用css进行网页布局

    一.单列布局(类似于搜狐网站) 如: 代码为: 二.两列布局 1.固定宽度 代码为: 2.自适应 代码为: 三.三列布局 代码为: 四.混合布局 就是在前面的基础上,在进行划分块 如: 代码为:

  6. 【React自制全家桶】五、React组件的生命周期函数详解

    一.总览React组件的生命周期函数 什么是生命周期函数:简单的来说就是 在某个时刻会自动执行的函数 二.React的生命周期函数主要由四块组成 分别是:组件初始化.组件挂载.组件更新.组件卸载 三. ...

  7. 微信小程序开发工具下载以及安装教程

    微信公众平台上登录你的微信小程序账号   登录进入小程序开发-工具-下载,再根据你的系统选择相对应的版本地址进行下载.   以管理员身份运行下载,点击下一步,如图所示:   下一步,就会出现许可证协议 ...

  8. 八十六:redis之RDB和AOF两种数据持久化机制

    详见:http://redisdoc.com/persistence/index.html redis.conf RDB机制 改为5秒内1次 文件已生成 关闭RDB,注释掉3个save,重启redis ...

  9. 数据库字段和实体类和map中对应类型

    http://blog.csdn.net/sxe18652071425/article/details/46416217 地址 MySQL数据类型 JAVA数据类型 JDBC TYPE 普通变量类型 ...

  10. Session中的方法概述

    一.操作实体对象 delete()把持久化或游离转为删除状态 save()把临时状态变为持久化状态(交给Sessioin管理) saveOrUpdate()把临时或游离状态转为持久化状态 update ...