大意: 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. IDEA安装配置Thrift

    下载exe:http://archive.apache.org/dist/thrift/0.9.3/ 新建一个thrift目录放进来,并将名字改成thrift

  2. Oracle12C SGA PGA UGA

    SGA和PGA简介 1 sga组成: 2b4p1s(记忆) database buffer cache:包括 default pool,keep pool,recycle pool: redo log ...

  3. 2.ibatis执行流程解析

    以下仅为个人理解,如有问题,欢迎指正

  4. Android和jS互调技术Demo实现

    package com.loaderman.webviewdemo; import android.os.Bundle; import android.support.v7.app.AppCompat ...

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

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

  6. ABAP 判断字符串是否是数字

    通过正则表达式: IF cl_abap_matcher=>matches( pattern = '^(-?[1-9]\d*(\.\d*[1-9])?)|(-?0\.\d*[1-9])$' tex ...

  7. 队列:Beanstalkd介绍

    一:介绍 Beanstalkd 是一个轻量级的内存型队列.它是典型的类Memcached设计,协议和使用方式都是同样风格.github:https://github.com/beanstalkd官网: ...

  8. @Validated和@Valid校验参数、级联属性、List

    @Validated和@Valid的区别 在Controller中校验方法参数时,使用@Valid和@Validated并无特殊差异(若不需要分组校验的话): @Valid:标准JSR-303规范的标 ...

  9. configparser模块 subprocess 模块,xlrd 模块(表格处理)

    今日内容: 1.configparser模块 2.subprocess模块 3.xlrd(读),xlwt(写) 表格处理 configparser模块 import configparser # co ...

  10. 实验----Java的二维数组的应用及杨辉三角的编写

    (1) 编写一个程序,生成一个10*10的二维随机整数数组,并将该数组的每行最大值保存于一个一维数组中,将每列平均值保存于另外一个一维数组中并分别输出. (2) 编程输出杨辉三角的前10行. 找出一个 ...