大意: 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. RabbitMQ MQTT协议和AMQP协议

    RabbitMQ MQTT协议和AMQP协议 1        序言... 1 1.1     RabbitMq结构... 1 1.2     RabbitMq消息接收... 4 1.3     Ex ...

  2. SCOI2009迷路

    当初学矩阵幂的时候弃掉了,那时候只会用矩阵优化递推,碰到这种图论的瞬间躺地. 昨天听学长的课,有一道例题,在边权为一的图上求从某点到某点的路径方案数,只要对邻接矩阵跑qpow就完事了. 于是自己画了个 ...

  3. shell编程-定时任务(备份数据库)

    计划任务定时备份,删除等操作: #crontab -e #注意 会区分用户 默认在root用户登录用的是root权限用户的计划任务, 如果想在postgres备份 应使用postgres用户权限, 设 ...

  4. ping包的checksum校验和

    PING包发送里面有一个比较关键的就是checksum即校验和 checksum本来就是ICMP包内的数据 怎么又从ICMP包开始计算?后来看了一下文档,就是就算ICMP的时候checksum本身 的 ...

  5. TensorFlow 学习(1)——第一个程序:线性回归

    目前这个程序还有很多地方没有搞懂,先跑一跑例程看看效果如何.从结果来看,最终的训练成果能够接近于预设的数据

  6. pandas基础,Serires,Dataframe

    DataFrame DataFrame是Pandas中的一个表格型的数据结构,包含有一组有序的列,每列可以是不同的值类型(数值.字符串.布尔型等),DataFrame即有行索引也有列索引,可以被看做是 ...

  7. SVN+MAVEN项目打包

    题记:项目打包bash脚本 环境准备 maven版本:3.5.2 mvn -v #查看maven的版本信息 svn版本:1.4.0 svn --version #查看svn版本信息 1.update_ ...

  8. Sql UpdateOrInsert

    SqlServer(先更新,受影响条数为0,则Insert,通过事务): begin tran update table set column=columnvalue where wherestr b ...

  9. 2.oracle数据库:[1]oracle简易客户端安装方法

      准备oracle简易客户端程序,如果没有请到oracle网站下载www.oracle.com,可以下载基本包及其他扩展程序包,例如:如果要使用sqlplus则需要下载sqlplus包,笔者下载了i ...

  10. linux常用命令(7)cp命令

    cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一般情况下,shell会设置一个别名,在命令行下复制文件时,如果目标文件已经存在,就会询问是否覆盖,不管你是否使用-i参数.但是如果是 ...