大意: 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. Inter IPP+ VS + opencv 在 Windows下的环境搭建

    首先Inter官网申请和下载:https://software.intel.com/en-us/intel-ipp 需要VS2013或更高版本(先装vs再装IPP,我的版本是VS2015社区版,IPP ...

  2. TCP时间戳选项Timestamp

    时间戳选项发送方在每个报文段中放置一个时间戳值.接收方在确认中返回这个数值,从而允许发送方为每一个收到的ACK计算RTT(我们必须说“每一个收到的ACK”而不是“每一个收到的报文段”,是因为TCP通常 ...

  3. R语言:时间的转化

    一般使用R从数据库导出来的时间数据一般都不是我们能看的懂的(具体是什么格式的我也忘记了),需要做如下转化 as.Date(time,origin = '1970-01-01') 最近从网上爬下来的时间 ...

  4. python pandas(ix & iloc &loc)

    python pandas(ix & iloc &loc) loc——通过行标签索引行数据 iloc——通过行号索引行数据 ix——通过行标签或者行号索引行数据(基于loc和iloc ...

  5. IIS7 部署MVC 运行不了 注意事项

    经常安装完iis7或者7.5后,部署MVC3.运行后提示 403 找不到目录. 解决办法:需要重新注册下iis C:\Windows\Microsoft.NET\Framework64\v4.0.30 ...

  6. mysql常用操作与日志

    在linux上的mysql命令 mysql -e "mysql内部命令" #可在外部显示myslq内的输出,-e可跟多条命令用;隔开 在mysql内的mysql命令 system ...

  7. SQLServer 简单数据拆分

    --1. 旧的解决方法(sql server 2000)   create table tb(id int,value varchar(30)) insert into tb values(1,'aa ...

  8. pyqt5在QMainWindow中布局的问题

    在pyqt5中使用了父类为QMainWindow的话,在里面使用布局类,QGridLayout, QHBoxLayout ,QVBoxLayout 时,发现不好用. 解决: 如果是在以QWidget为 ...

  9. PHP 文件夹上传

    一.我的准备情况说明. 编辑器:sublime text3(用什么编辑器看自己爱好)服务器构建:使用phpstudy2014构建服务器,服务器文件存储在我自身电脑D盘的www文件中.(安装phpstu ...

  10. CRLF、CR、LF详解

    名词解释 CR:Carriage Return,对应ASCII中转义字符\r,表示回车 LF:Linefeed,对应ASCII中转义字符\n,表示换行 CRLF:Carriage Return &am ...