大意: 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. C++入门经典-例8.5-多重继承

    1:C++允许子类从多个父类继承公有的和受保护的成员,这称为多重继承. 2:多重继承的定义.多重继承有多个基类名称标识符,其声明形式如下: class 派生类名标识符:[继承方式] 基类名标识符1,. ...

  2. TCP最大报文段MSS源码分析

    概述 本文主要对MSS相关的几个字段结合源码流程进行分析: 字段含义 user_mss(tcp_options_received)–用户配置的mss,优先级最高: mss_clamp(tcp_opti ...

  3. LeetCode 147. 对链表进行插入排序(Insertion Sort List)

    题目描述 对链表进行插入排序. 插入排序的动画演示如上.从第一个元素开始,该链表可以被认为已经部分排序(用黑色表示). 每次迭代时,从输入数据中移除一个元素(用红色表示),并原地将其插入到已排好序的链 ...

  4. LeetCode 134. 加油站(Gas Station)

    题目描述 在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升. 你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i] 升.你从其 ...

  5. vuex 讲解

    vuex 状态的管理状态,它采用集中式存储管理应用的所有组件的状态,尤其是在中大型项目,则是很好的开发利器 vuex 的流程图 vuex 的优势: 1. vuex 的存储状态,响应式的 2. 他是所有 ...

  6. c 使用lua 示例

    #include <stdio.h> #include <string.h> #include <lua.h> #include <lauxlib.h> ...

  7. mysql|full join 多表联查,系统报错,无法解答!

    查询语句: select 分数 from cfull join don c.姓名=d.姓名 报错: [Err] 1054 - Unknown column 'c.姓名' in 'on clause' ...

  8. 使用Navicat Premium 客户端绕过白名单限制mysql数据库

    针对有些数据库有白名单限制,但如果IP经常浮动的话,会要经常加白名单,但如果知道可以连接数据库的linux用户密码就能 通过SSH通道代理来连接数据库.保存密码后,这样就能直接连接数据库,减省很多麻烦 ...

  9. [idea]创建一个控制台程序

    新建项目时,选择JBoss即可.

  10. 电脑上不了网,但是能登录QQ 问题解决方案

    电脑上不了网,但是能登录QQ 问题解决方案 问题现象 个人电脑连上Wifi,打不开百度等网页,但是能登录QQ. 解决方案 1.打开命令提示对话框(Win+R) 2.输入ipconfig/display ...