#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <queue>
#define maxn 200001
using namespace std;
typedef long long int lli;
lli n,m,id=0,head[maxn],next[maxn],d[maxn],v[maxn];
struct edge
{
	lli x,y,z;
	edge(lli x=0,lli y=0,lli z=0):x(x),y(y),z(z){}
};
edge e[maxn];
queue <lli> Q;
inline lli read()
{
	lli f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
void init()
{
	memset(v,1,sizeof(v));
	memset(d,0x3f,sizeof(d));
}
void add(lli x,lli y,lli z)
{
	id++;
	e[id]=edge(x,y,z);
	next[id]=head[x];
	head[x]=id;
}
void spfa()
{
	d[0]=0;
	Q.push(0);
	v[0]=0;
	while(!Q.empty())
	{
		lli x=Q.front();
		v[x]=1;
		Q.pop();
		for(lli i=head[x];i;i=next[i])
		{
			lli y=e[i].y;
			if(d[y]>d[x]+e[i].z)
			{
				d[y]=d[x]+e[i].z;
				if(v[y])
				{
					Q.push(y);
					v[y]=0;
				}
			}
		}
	}
}
int main()
{
	init();
	n=read();
	m=read();
	for(lli i=1;i<=m;i++)
	{
		lli x,y,z;
		x=read();
		y=read();
		z=read();
		add(x,y,2*z);
		add(y,x,2*z);
	}
	for(lli i=1;i<=n;i++)
	{
		lli x=0,y=i,z;
		z=read();
		add(x,y,z);
	}
	spfa();
	for(int i=1;i<=n;i++)
	{
		printf("%d ",d[i]);
	}
	printf("\n");
	return 0;
}


#include<bits/stdc++.h>
#define maxn 200005
#define ll long long
using namespace std;
int n,m;
ll a[maxn],dis[maxn];
struct edge
{
	int v;long long w;
	edge(int v=0,ll w=0):v(v),w(w){}
};
vector<edge>adj[maxn];
struct node
{
	long long dis;int u;
	node(ll dis=0,int u=0):dis(dis),u(u){}
	bool operator<(const node &p)const
	{
		return dis>p.dis;
	}
};
priority_queue<node>q;
bool vis[maxn];
void dijkstra()
{
	for(int i=1;i<=n;i++)
	{
		dis[i]=a[i];
		q.push(node(dis[i],i));
	}
	int u,v,sz;
	long long w;
	while(!q.empty())
	{
		u=q.top().u;
		q.pop();
		if(vis[u])continue;
		vis[u]=1;
		sz=adj[u].size();
		for(int i=0;i<sz;i++)
		{
			v=adj[u][i].v;
			w=adj[u][i].w;
			if(dis[u]+w<dis[v])
			{
				dis[v]=dis[u]+w;
				q.push(node(dis[v],w));
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	int u,v;ll w;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%lld",&u,&v,&w);
		w*=2;
		adj[u].push_back(edge(v,w));
		adj[v].push_back(edge(u,w));
	}
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	dijkstra();
	for(int i=1;i<=n;i++)
		printf("%lld ",dis[i]);
	printf("\n");
	return 0;
}


#include <queue>
#include <cstring>
#include <cstdio>
#define maxn 1000005
#define maxm 1000005
#define MAX 1e18
#define ll long long
#define Pli pair<long long,int>

using namespace std;

priority_queue<Pli,vector<Pli>,greater<Pli> >q;
int n,m,tot,x,y;
bool vis[maxn];
ll z,now,dis[maxn],w[maxm];
int v[maxn],Next[maxm],Head[maxn];

inline void addedge(int x,int y,ll z)
{
	v[++tot]=y,w[tot]=z;
	Next[tot]=Head[x],Head[x]=tot;
}

void dijkstra()
{
	q.push(make_pair(0,n+1));
	dis[n+1]=0;
	vis[n+1]=true;
	while(!q.empty())
	{
		Pli x=q.top();q.pop();
		if(dis[x.second]<x.first) continue;
		for(int i=Head[x.second];i;i=Next[i])
		{
			if(dis[x.second]+w[i]<dis[v[i]])
			{
				dis[v[i]]=dis[x.second]+w[i];
				q.push(make_pair(dis[v[i]],v[i]));
			}
		}
	}
}

int main ()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%lld",&x,&y,&z);
		addedge(x,y,z*2);addedge(y,x,z*2);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&now);
		addedge(n+1,i,now);
		dis[i]=MAX;
	}
	dijkstra();
	for(int i=1;i<=n;i++)
	  printf("%lld ",dis[i]);
	return 0;
}


#include <cstdio>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#define ll long long
#define Game return
#define Over 0
using namespace std;
const int maxn = 200000+10, maxm = 400000+10;

int head[maxn], len = 0;

struct Edge{
    int to,nex;
    ll w;
}e[maxm << 1];

void Add(int u,int v,ll w){
    e[++len].to = v;
    e[len].nex = head[u];
    e[len].w = w;
    head[u] = len;
}

ll dis[maxn], n, m;
bool vis[maxn];

struct Node{
    ll num, val;
    Node(){};
    Node(ll a,ll b){
        num = a;
        val = b;
    }
    bool operator <(const Node& x)const{
        return val > x.val;
    }
};

void Dij(){
    priority_queue <Node> q;
    for(int i = 1; i <= n; i++)
        dis[i] = 9999999999999999;
    memset(vis, 0, sizeof vis);
    dis[0] = 0;
    q.push(Node(0,0));

    while(!q.empty()){
        ll num = q.top().num;
        ll val = q.top().val;
        q.pop();
        if(vis[num]) continue;
        vis[num] = 1;
        for(int i = head[num]; i; i = e[i].nex){
            ll v = e[i].to, w = e[i].w;
            if(dis[v] > dis[num] + w){
                dis[v] = dis[num] + w;
                q.push(Node(v,dis[v]));
            }
        }
    }
}

int main(){
    while(~scanf("%lld %lld", &n, &m)){
        for(int i = 1; i <= m; i++){
            int u,v;
            ll w;
            scanf("%d %d %lld", &u, &v, &w);
            Add(u, v, w << 1), Add(v, u, w << 1);
        }
        for(int i = 1; i <= n; i++){
            ll w;
            scanf("%lld", &w);
            Add(0, i ,w);
        }
        Dij();
        for(int i = 1; i <= n; i++)
            printf("%lld ", dis[i]);

        memset(head, 0, sizeof head);
        len = 0;
    }
    Game Over;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#define MAXN 700010
#define ll long long
#define inf 0x3f3f3f
#define mk(x,y) make_pair(x,y)
using namespace std;
struct node{
	int nex,to;
	ll dis;
}a[MAXN];
int head[MAXN],cnt;
void add(int u,int v,ll w)
{
	a[++cnt].nex=head[u];
	a[cnt].to=v;
	a[cnt].dis=w;
	head[u]=cnt;
}
int n,m,vis[MAXN];
ll dis[MAXN];
priority_queue<pair<ll,int> > q;
void dij()
{
	memset(dis,inf,sizeof(dis));
	dis[0]=0;
	q.push(mk(0,0));
	while(!q.empty())
	{
		int u=q.top().second;
		q.pop();
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=head[u];i;i=a[i].nex)
		{
			int v=a[i].to;
			if(dis[v]>dis[u]+a[i].dis)
			{
				dis[v]=dis[u]+a[i].dis;
				q.push(mk(-dis[v],v));
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;ll z;
		scanf("%d%d%lld",&x,&y,&z);
		add(x,y,z*2);
		add(y,x,z*2);
	}
	for(int i=1;i<=n;i++)
	{
		ll z;
		scanf("%lld",&z);
		add(0,i,z);
	}
	dij();
	for(int i=1;i<=n;i++)
		printf("%lld ",dis[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
struct cow{int x,y,z;}e[N];
#define ll long long
int head[N],tot,a[N],n,m;ll dis[N];
void inse(int xxxx,int yyyy,int zzzz){
	e[++tot].x=head[xxxx];
	head[xxxx]=tot;
	e[tot].y=yyyy;
	e[tot].z=zzzz;
}
#define P pair<ll,int>
#define E(x,y) make_pair(x,y)
int v[N];priority_queue<P>q;
void DJ(){
	memset(dis,60,sizeof(dis));
	q.push(E(0,0));dis[0]=0;
	while(!q.empty()){
		int x=q.top().second;q.pop();
		if(v[x])continue;v[x]=1;
		for(int i=head[x];i;i=e[i].x){
			int y=e[i].y,z=e[i].z;
			if(dis[x]+z<dis[y]){
				dis[y]=dis[x]+z;
				q.push(E(-dis[y],y));
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		inse(x,y,z<<1);inse(y,x,z<<1);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	    inse(i,0,a[i]);
		inse(0,i,a[i]);
	}DJ();
	for(int i=1;i<=n;i++)printf("%lld ",dis[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
typedef long long ll;
struct edge
{
    int ed;
    ll val;
    int nxt;
};
int n, cnt;
int *h;
edge *e;
inline void add(int bg, int ed, ll val)
{
    cnt++;
    e[cnt].ed = ed;
    e[cnt].val = val;
    e[cnt].nxt = h[bg];
    h[bg] = cnt;
}
inline void dijkstra()
{
    ll *dis;
    dis = new ll[n + 1];
    for (register int i = 1; i <= n; i++)
    {
        dis[i] = LLONG_MAX;
    }
    bool *vst;
    vst = new bool[n + 1]();
    priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > q;
    dis[0] = 0;
    q.push(make_pair(0, 0));
    int x;
    while (!q.empty())
    {
        x = q.top().second;
        q.pop();
        if (vst[x])
        {
            continue;
        }
        vst[x] = true;
        for (register int i = h[x]; i; i = e[i].nxt)
        {
            if (dis[e[i].ed] > dis[x] + e[i].val)
            {
                dis[e[i].ed] = dis[x] + e[i].val;
                if (!vst[e[i].ed])
                {
                    q.push(make_pair(dis[e[i].ed], e[i].ed));
                }
            }
        }
    }
    for (register int i = 1; i <= n; i++)
    {
        cout << dis[i] << ' ';
    }
}
int main()
{
    //freopen("CF938D.in", "r", stdin);
    int m;
    cin >> n >> m;
    h = new int[n + 1]();
    e = new edge[(m << 1 | 1) + n];
    int u, v;
    ll w;
    for (register int i = 0; i < m; i++)
    {
        cin >> u >> v >> w;
        w <<= 1;
        add(u, v, w);
        add(v, u, w);
    }
    for (register int i = 1; i <= n; i++)
    {
        cin >> w;
        add(0, i, w);
    }
    dijkstra();
    return 0;
}


#include <bits/stdc++.h>

#define setI(x) freopen(x".in", "r", stdin);

#define setO(x) freopen(x".out", "w", stdout);

#define setIO(x) setI(x) setO(x)

using namespace std;

typedef long long ll;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int rd() {
	int x = 0, f = 1;
	char c = nc();
	while (c < 48) {
		if (c == '-') {
			f = -1;
		}
		c = nc();
	}
	while (c > 47) {
		x = (((x << 2) + x) << 1) + (c ^ 48);
		c = nc();
	}
	return x * f;
}

ll lrd() {
	ll x = 0, f = 1;
	char c = nc();
	while (c < 48) {
		if (c == '-') {
			f = -1;
		}
		c = nc();
	}
	while (c > 47) {
		x = (((x << 2) + x) << 1) + (c ^ 48);
		c = nc();
	}
	return x * f;
}

const int N = 2e5 + 10;

const int inf = 0x3f3f3f3f;

int tot, head[N], to[N << 2], nxt[N << 2]

ll val[N << 2];

int n, m;

ll num[N];

ll dis[N];

bool vis[N];

void add(int x, int y, llabs z) {
	to[ ++ tot] = y;
	val[tot] = z;
	nxt[tot] = head[x];
	head[x] = tot;
}

priority_queue < pair<ll, int> > q;

void dijkstra(int s)
{
	memset(dis, 0x3f, sizeof dis);
	// memset(vis, 0, sizeof vis);
	dis[s] = 0;
	q.push(make_pair(0, s));
	while (!q.empty())
	{
		if (vis[q.top().second])
		{
			q.pop();
			continue ;
		}
		int x = q.top().second;
		q.pop();
		vis[x] = 1;
		for (int i = head[x]; i; i = nxt[i])
		{
			if (dis[to[i]] > dis[x] + val[i])
			{
				dis[to[i]] = dis[x] + val[i];
				q.push(make_pair(-dis[to[i]], to[i]));
			}
		}
	}
}

int main() {

// setIO("movie");
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i ++ ) {
		int a = rd(), b = rd(), c = rd();
		add(a, b, c * 2);
		add(b, a, c * 2);
	}
	for (int i = 1; i <= n; i ++ ) {
		num[i] = lrd();
		add(0, i, num[i]);
	}
	dijkstra(0);
	for (int i = 1; i <= n; i ++ ) {
		printf("%lld ", dis[i]);
	}
	return 0;

}


#include <bits/stdc++.h>
#define int long long

using namespace std;

struct Edge
{
	int next, to;
	int val;
}edge[114514 << 1];

struct Node
{
	int idx, val;
	inline bool operator < (const Node& a) const
	{
		return val > a.val;
	}
};

inline void AddEdge(int, int, int);

int edgeSum, head[114514 << 2], vis[114514 << 2], qaq[114514 << 2];

signed main(signed argc, char* argv[])
{
	int n, m;
	scanf("%lld%lld",&n, &m);
	for(register int i = 1; i <= m; i++)
	{
		int uu, vv, d;
		scanf("%lld%lld%lld", &uu, &vv, &d);
		AddEdge(uu, vv, d * 2);
		AddEdge(vv, uu, d * 2);
	}
	for(register int i = 1; i <= n; i++)
	{
		int d;
		scanf("%lld", &d);
		AddEdge(0, i, d);
	}
	priority_queue<Node> qwq;
	Node tmp;
	tmp.idx = 0, tmp.val = 0;
	qwq.push(tmp);
	memset(qaq, 0x3f, sizeof(qaq));
	qaq[0] = 0;
	while(!qwq.empty())
	{
		int index = qwq.top().idx;
		qwq.pop();
		if(!vis[index])
		{
			vis[index] = 1;
			for(register int i = head[index]; i; i = edge[i].next)
			{
				if(qaq[edge[i].to] > edge[i].val + qaq[index] && !vis[edge[i].to])
				{
					qaq[edge[i].to] = edge[i].val + qaq[index];
					tmp.idx = edge[i].to;
					tmp.val = qaq[edge[i].to];
					qwq.push(tmp);
				}
			}
		}
	}
	for(register int i = 1; i <= n; i++)
	{
		printf("%lld ", qaq[i]);
	}
	return 0;
}

inline void AddEdge(int u,int v, int data)
{
	edge[++edgeSum].next = head[u];
	edge[edgeSum].to = v;
	edge[edgeSum].val = data;
	head[u] = edgeSum;
}


#include <stdio.h>
#include <cstring>
#include <iostream>
#include <stdlib.h>
#include <queue>
using namespace std;
const int maxn=200000+100;
struct edge
{
	int u,v,next;
	long long w;
}e[maxn*2];
int front[maxn];
int cnt;
long long f[maxn];
inline void addedge(int u,int v,long long w)
{
	cnt++;
	e[cnt].u=u;
	e[cnt].v=v;
	e[cnt].w=w;
	e[cnt].next=front[u];
	front[u]=cnt;
}
int n,m;
long long d[maxn];
int visit[maxn];
void spfa()
{
	queue <int> q;
	for(int i=1;i<=n;i++)
	    d[i]=1e18;
	d[0]=0;
	visit[0]=1;
	q.push(0);
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		visit[x]=0;
		for(int i=front[x];i>=0;i=e[i].next)
		{
			int v=e[i].v;
			long long w=e[i].w;
			if(d[v]>d[x]+w)
			{
				d[v]=d[x]+w;
				if(!visit[v])
				{
					visit[v]=1;
					q.push(v);
				}
			}
		}
	}
}

int main()
{
	memset(front,-1,sizeof(front));
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		long long w;
		scanf("%d %d",&u,&v);
		cin>>w;
		addedge(u,v,w*2);
		addedge(v,u,w*2);
	}
	for(int i=1;i<=n;i++)
	    cin>>f[i];
	for(int i=1;i<=n;i++)
		addedge(0,i,f[i]);
	spfa();
	for(int i=1;i<=n;i++)
	    cout<<d[i]<<" ";
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
struct Edge {
    int v, next;
    long long w;
} edges[1000000];
int head[300000], tot, vis[250000], n, m, u ,v;
long long dis[250000], a[230000], w;
void add(int x, int y, long long w) { edges[++tot] = (Edge){y, head[x], w}, head[x] = tot; }
struct node {
    int id;
    long long w;
    bool operator<(node b) const  { return w > b.w; }
};
void dijkstra(int x) {
    priority_queue<node> queue;
    dis[x] = 0;
    queue.push((node){x, 0});
    while (!queue.empty()) {
        node newn = queue.top();
        queue.pop();
        if (vis[newn.id]) continue;
        vis[newn.id] = 1;
        for (int i = head[newn.id]; i; i = edges[i].next) {
            int v = edges[i].v;
            if (dis[v] > dis[newn.id] + edges[i].w) {
                dis[v] = dis[newn.id] + edges[i].w;
                queue.push((node){v, dis[v]});
            }
        }
    }
}
int main() {
    memset(dis, 0x3f, sizeof(dis));
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) scanf("%d%d%lld", &u, &v, &w), add(u, v, 2 * w), add(v, u, 2 * w);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), add(0, i, a[i]);
    dijkstra(0);
    for (int i = 1; i <= n; i++) printf("%lld ", dis[i]);
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
ll dis[maxn];
int vis[maxn];
ll p[maxn],len[maxn<<1];
int n,m;
priority_queue< pair<int,ll> > q;
int l,pre[maxn<<1],last[maxn],other[maxn<<1];
void add(int x,int y,int z){
	l ++;
	pre[l] = last[x];
	last[x] = l;
	other[l] = y;
	len[l] = z;
}
void dijkstra(int x){
	memset(dis,0x3f,sizeof dis);
	dis[x] = 0;
	q.push(make_pair(0,x));
	while(!q.empty()){
		int u = q.top().second;q.pop();
		if(vis[u])continue;
		vis[u] = 1;
		for(int p = last[u];p;p = pre[p]){
			int v = other[p];
			if(dis[v] > dis[u] + len[p]){
				dis[v] = dis[u] + len[p];
				q.push(make_pair(-dis[v],v));
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= m;i ++){
		int a,b;ll c;
		scanf("%d%d%lld",&a,&b,&c);
		add(a,b,2*c);add(b,a,2*c);
	}
	for(int i = 1;i <= n;i ++)
	scanf("%lld",&p[i]);
	for(int i = 1;i <= n;i ++){
		add(n+1,i,p[i]);
	}
	dijkstra(n+1);
	for(int i = 1;i <= n ;i ++){
		cout<<dis[i]<<" ";
	}
	cout<<endl;
	return 0;
}
/*
long long
线段树四倍
写代码时请注意:
	1.是否要开Long Long?数组边界处理好了么?
	2.实数精度有没有处理?
	3.特殊情况处理好了么?
	4.做一些总比不做好.
思考提醒:
	1.最大值和最小值问题可不可以用二分答案?
	2.有没有贪心策略?否则能不能dp?
*/


#include<bits/stdc++.h>
using namespace std;
const int N =2*1e5+1;
const int INF = 0x3f3f3f3f;
struct ed{
	int next,to;
	long long dis;
}
edge[3*N];
long long dist[3*N];
bool visit[N*3];
int n, m;
int cnt;
int head[N*3];
void addedge(int u,int v,long long w)
{
	edge[++cnt].next=head[u];
	edge[cnt].to=v;
	edge[cnt].dis=w;
	head[u]=cnt;
}
void spfa()
{
	queue<int> Q;
	int now;
	memset(visit, false, sizeof(visit));
	memset(dist,INF,sizeof(dist));
	dist[0] = 0;
	Q.push(0);
	visit[0]= true;
	while (!Q.empty())
	{
		now = Q.front();
		Q.pop();
		visit[now] = false;
		for (int i = head[now]; i; i=edge[i].next)
		{
           int y=edge[i].to;
			if (dist[y] > dist[now] + edge[i].dis)
			{
				dist[y] = dist[now] + edge[i].dis;
				if (!visit[y])
				{
					Q.push(y);
	                visit[y] = true;
				}
			}
		}
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b;
		long long c;
		scanf("%d%d%lld",&a,&b,&c);
		addedge(a,b,c*2);
		addedge(b,a,c*2);
	}
	for(int i=1;i<=n;i++)
	{
		long long a;
		scanf("%lld",&a);
		addedge(0,i,a);
	}
	spfa();
	for(int i=1;i<=n;i++)
	 printf("%lld ",dist[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x) {
    x=0;T f=1,ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x*=f;
}
typedef long long ll;
typedef pair<ll,ll> PII;
const int N=210000;
const ll inf=1e18;
ll n,m,k,x,y,v,tot,ans,vis[N],dis[N],lin[N];
struct gg {
	ll y,next,v;
}a[N<<1];
inline void add(ll x,ll y,ll v) {
	a[++tot].y=y;
	a[tot].next=lin[x];
	lin[x]=tot;
	a[tot].v=v;
}
priority_queue <PII,vector<PII>,greater<PII> >q;
inline void dij() {
//	memset(dis,0x7f,sizeof(dis));
	for(int i=1;i<=n;i++) dis[i]=inf;
	dis[0]=0;
	q.push(make_pair(0,0));
	while(q.size()) {
		ll x=q.top().second;
		q.pop();
		if(vis[x]) continue;
		vis[x]=1;
		for(int i=lin[x];i;i=a[i].next) {
			int y=a[i].y;
			if(dis[y]>dis[x]+a[i].v) {
				dis[y]=dis[x]+a[i].v;
				q.push(make_pair(dis[y],y));
			}
		}
	}
}
int main() {
	read(n); read(m);
	for(int i=1;i<=m;i++) {
		read(x); read(y); read(v);
		add(x,y,2*v); add(y,x,2*v);
	}
	for(int i=1;i<=n;i++) {
		read(x);
		add(0,i,x); add(i,0,x);
	}
	dij();
	for(int i=1;i<=n;i++)
		printf("%d ",dis[i]);
	return 0;
}


//Buy a Ticket
//https://www.luogu.com.cn/problem/CF938D

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &ff){
	T rr=1;ff=0;register char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')rr=-1;ch=getchar();}
	while(isdigit(ch)){ff=(ff<<1)+(ff<<3)+(ch^48);ch=getchar();}
	ff*=rr;
}
typedef long long ll;
const int N=200010;
int n,m,head[N],ver[N<<1],nxt[N<<1],tot,vis[N];
ll dis[N],w[N<<1];
inline void add(int u,int v,ll e){ver[++tot]=v,w[tot]=e,nxt[tot]=head[u];head[u]=tot;}
/*inline void dijkstra(){
	priority_queue<pair<ll,int> > q;
	memset(dis,0x3f,sizeof(dis));
	q.push(make_pair(0,0));dis[0]=0;
	while(!q.empty()){
		int x=q.top().second;q.pop();
		if(vis[x])continue;
		vis[x]=1;
		for(int i=head[x];i;i=nxt[i]){
			int y=ver[i];ll z=w[i];
			if(dis[y]>dis[x]+z){
				dis[y]=dis[x]+z;
				q.push(make_pair(-dis[y],y));
			}
		}
	}
}*/
void dijkstra()
{
	priority_queue<pair<ll,int> > q;
    memset(dis,0x3f,sizeof(dis));
    dis[0]=0;
    q.push(make_pair(0,0));
    while(!q.empty())
    {
        int x=q.top().second;
        if(vis[x])
        {
            q.pop();
            continue;
        }
        x=q.top().second;q.pop();vis[x]=1;
        for(int i=head[x];i;i=nxt[i])
        {
            int y=ver[i];
            if(dis[y]>dis[x]+w[i])
                dis[y]=dis[x]+w[i],q.push(make_pair(-dis[y],y));
        }
    }
}
int main(){
	read(n),read(m);
	for(int i=1;i<=m;++i){
		ll x,y,c;
		read(x),read(y),read(c);c*=2;
		add(y,x,c);add(x,y,c);
	}
	for(int i=1;i<=n;++i){
		ll x;read(x);
		add(0,i,x);
	}
	dijkstra();
	for(int i=1;i<=n;++i)printf("%lld ",dis[i]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
using namespace std;

struct node
{
	int to,next,s;
};

int n,m,s,num_edge=0,h[200010],l=0;
long long dis[200010];
bool b[200010];
node edge[200010];

int read()
{
	char c=getchar();
	int num=0,f=1;
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		num=num*10-'0'+c;
		c=getchar();
	}
	return f*num;
}

void add(int x,int y,int z)
{
	num_edge++;
	edge[num_edge].to=y;
	edge[num_edge].next=h[x];
	edge[num_edge].s=z;
	h[x]=num_edge;
	return;
}

int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	n=read(); m=read();
	int x,y,z;
	for(int i=1; i<=m; i++)
	{
		x=read(); y=read(); z=read();
		add(x,y,z*2);
		add(y,x,z*2);
	}
	for(int i=1; i<=n; i++) dis[i]=read();
	s=0;
	dis[s]=0;
	l=1;
	while(l<=n+1)
	{
		int k=2147483647,g;
		for(int i=1; i<=n; i++)
		{
			if(!b[i]&&dis[i]<k)
			{
				k=dis[i];
				g=i;
			}
		}
		b[g]=true;
		for(int i=h[g]; i!=0; i=edge[i].next)
		{
			if(b[edge[i].to]) continue;
			dis[edge[i].to]=min(dis[edge[i].to],dis[g]+edge[i].s);
		}
		l++;
	}
	for(int i=1; i<=n; i++) cout<<dis[i]<<' ';
	return 0;
}


#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
typedef long long ll;
const int maxm=4e5+7;
int n,m;
int pre[maxm],last[maxm],other[maxm],l;
ll len[maxm],w[maxm],dis[maxm];
bool vis[maxm];
priority_queue<pair<ll,int> > q;
void add(int x,int y,int z)
{
 l++;
 pre[l]=last[x];
 last[x]=l;
 other[l]=y;
 len[l]=z;
}
void dijkstra()
{
  for(int i=1;i<=n;i++)
  dis[i]=1e17;
  dis[n+1]=0;
  q.push(make_pair(0,n+1));
  while(q.size())
  {
    int u=q.top().second;
	q.pop();
	if(vis[u]) continue;
	vis[u]=1;
	for(int p=last[u];p;p=pre[p])
	{
	 int v=other[p];
	 if(dis[v]>dis[u]+len[p])
	 {
	 	dis[v]=dis[u]+len[p];
	 	q.push(make_pair(-dis[v],v));
	 }
    }
  }

}
int main()
{
 scanf("%d%d",&n,&m);
 for(int i=1;i<=m;i++)
 {
  int x,y;
  ll z;
  scanf("%d%d%lld",&x,&y,&z);
  add(x,y,2*z);//返程也要算
  add(y,x,2*z);
 }
 for(int i=1;i<=n;i++)
 {
  scanf("%lld",&w[i]);
  add(n+1,i,w[i]);
 }
 dijkstra();
 for(int i=1;i<=n;i++)
 {
  printf("%lld ",dis[i]);
 }
 cout<<endl;
 return 0;
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#define N 200010
using namespace std;
int n,m,q[N*5],hd,tl;
int fir[N],nex[N*2],poi[N*2],sum;
long long w[N*2],d[N];
bool v[N];
void ins(int x,int y,long long z)
{
	nex[++sum]=fir[x];
	poi[sum]=y;
	w[sum]=z;
	fir[x]=sum;
}
void spfa()
{
	q[++tl]=0;
	memset(d,0x3f,sizeof(d));
	d[0]=0;
	while(hd<tl)
	{
		hd++;
		int now=q[hd];v[now]=0;
		for(int i=fir[now];i;i=nex[i])
		{
			int p=poi[i];
			if(d[p]>d[now]+w[i])
			{
				d[p]=d[now]+w[i];
				if(!v[p])
				{
					v[p]=1;
					q[++tl]=p;
				}
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	int x,y;long long z;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);scanf("%lld",&z);
		ins(x,y,z*2);ins(y,x,z*2);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&z);
		ins(0,i,z);
	}
	spfa();
	for(int i=1;i<=n;i++)
	printf("%lld ",d[i]);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
int n,m;
int u,v;
ll mini[200010],line[1000010];
bool vis[200010];
ll w;
int cnt=1,head[200010];
ll sum[200010];
ll p[200010];
struct note
{
    int to;
    int nxt;
    ll f;
}yang[400010];
void add(int x,int y,ll w)
{
    yang[cnt].to=y;
    yang[cnt].nxt=head[x];
    yang[cnt].f=w;
    head[x]=cnt++;
}
void spfa(int x)
{
    int i,j,head1=1,tail=1;
    for(i=1;i<=n;i++)
    {
        mini[i]=10000000000000;
    }
    memset(vis,false,sizeof(vis));
    memset(line,0,sizeof(line));
    mini[x]=0;
    line[tail]=x;
    vis[x]=1;
    tail++;
    while(head1<tail)
    {
        int tt=line[head1];
        vis[tt]=0;
        for(i=head[tt];i!=0;i=yang[i].nxt)
        {
            int yy=yang[i].to;
            if(tt!=0)
            {
            	if(mini[tt]+yang[i].f*2<mini[yy])
            {
                mini[yy]=mini[tt]+yang[i].f*2;
                if(vis[yy]==0)
                {
                    line[tail]=yy;
                    vis[yy]=1;
                    tail++;
                }
            }
            }
            else
            {
            	if(mini[tt]+yang[i].f<mini[yy])
            {
                mini[yy]=mini[tt]+yang[i].f;
                if(vis[yy]==0)
                {
                    line[tail]=yy;
                    vis[yy]=1;
                    tail++;
                }
            }
            }
        }
        head1++;
    }
}
int main()
{
    int i,j;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++)
    {
        scanf("%d%d%lld",&u,&v,&w);
        add(u,v,w);
        add(v,u,w);
    }

    for(i=1;i<=n;i++)
    {
        scanf("%lld",&p[i]);
        add(0,i,p[i]);
        add(i,0,p[i]);
    }
    spfa(0);
    for(i=1;i<=n;i++)
    {
        printf("%lld ",mini[i]);
    }
    return 0;
}


#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define inf 0x7fffffff
const int maxn = 200005,maxm = 600005;
int head[maxn],nxt[maxm],tto[maxm],dis[maxm],num,n,m,s,u,v,d;
long long mindis[maxn];
bool vis[maxn];
struct cmp
{
    bool operator()(int a,int b)
    {
        return mindis[a] > mindis[b];
    }
};
priority_queue<int,vector<int>,cmp> q;
void add(int u,int v,int d)
{
	nxt[++num] = head[u];
	tto[num] = v;
	dis[num] = d;
	head[u] = num;
}

void spfa(int x)
{
	q.push(x);
	vis[x] = true;
	for(int i = 0;i <= n;i++) mindis[i] = inf;
	mindis[x] = 0;
	do
	{
		int xx = q.top();
		q.pop();
		vis[xx] = false;
		for(int i = head[xx];i != 0;i = nxt[i])
		{
			if(mindis[tto[i]] > mindis[xx] + dis[i])
			{
				mindis[tto[i]] = mindis[xx] + dis[i];
				if(vis[tto[i]] == false)
				{
					q.push(tto[i]);
					vis[tto[i]] = true;
				}
			}
		}
	}
	while(!q.empty());
}

int main()
{
	cin>>n>>m;
	for(int i = 1;i <= m;i++)
	{
		cin>>u>>v>>d;
		add(u,v,2*d);
		add(v,u,d*2);
	}
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		add(0,i,x);
		add(i,0,x);
	}
	spfa(0);
	for(int i=1;i<=n;i++)
			cout<<mindis[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define PLI pair<ll,int>
#define x first
#define y second
using namespace std;
int const N=2e5+10;
int n,m,ge=-1;
int head[N],nt[3*N],to[3*N];
ll w[3*N],dis[N];

void jia(int u,int v,ll x){
	nt[++ge]=head[u];
	to[ge]=v;
	w[ge]=x;
	head[u]=ge;
}

void dij(){
	memset(dis,0x3f,sizeof(dis));
	dis[0]=0;
	bool vis[N]={0};
	priority_queue<PLI>q;
	q.push({0,0});
	while(!q.empty()){
		PLI nw=q.top();
		q.pop();
		int u=nw.y;
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=head[u];~i;i=nt[i]){
			int v=to[i];
			if(vis[v]) continue;
			if(dis[v]>dis[u]+w[i]){
				dis[v]=dis[u]+w[i];
				q.push({-dis[v],v});
			}
		}
	}
}

int main(){
	scanf("%d%d",&n,&m);
	memset(head,-1,sizeof(head));
	for(int i=1;i<=m;i++){
		int u,v;
		ll x;
		scanf("%d%d%lld",&u,&v,&x);
		jia(u,v,x*2);
		jia(v,u,x*2);
	}
	for(int i=1;i<=n;i++){
		ll x;
		scanf("%lld",&x);
		jia(0,i,x);
	}
	dij();
	for(int i=1;i<=n;i++) printf("%lld ",dis[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 400009;
int n, m, Link[N], tot, vis[N];
ll dis[N];
struct edge{int next, to; ll w;} e[N << 1];
priority_queue< pair<ll, int> > q;

#define mp make_pair
#define il inline
#define ri register int
#define rep(i, a, n) for (ri i = a; i <= n; ++ i)
#define per(i, a, n) for (ri i = n; i >= a; -- i)

il char gc() {
	static char c, ibuf[1048576], *iS, *iT;
	return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, 1048576, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++);
}

template<class I>
il void read(I &x) {
	register char c = gc(); x = 0; ri f = 0;
	while(!isdigit(c)) f = (c == '-') ? 1 : f, c = gc();
	while(isdigit(c)) x = (x << 3) + (x << 1) + (c & 15), c = gc();
	x = f ? -x : x;
}

il void add(ri x, ri y, ll z) {e[++ tot].next = Link[x]; Link[x] = tot; e[tot].to = y; e[tot].w = z;}

void dij() {
	memset(dis, 30, sizeof(dis));
	q.push(mp(0, n + 1));
	dis[n + 1] = 0;
	while(q.size()) {
		ri x = q.top().second; q.pop();
		if (vis[x]) continue;
		vis[x] = 1;
		for (ri i = Link[x]; i; i = e[i].next) {
			ri y = e[i].to; ll z = e[i].w;
			if (dis[x] + z < dis[y]) {
				dis[y] = dis[x] + z;
				q.push(mp(-dis[y], y));
			}
		}
	}
}

 main() {
    read(n), read(m);
    rep (i, 1, m) {
    	ri x, y; ll z;
    	read(x), read(y), read(z);
    	add(x, y, z << 1), add(y, x, z << 1);
    }
    rep (i, 1, n) {
    	ll val;
    	read(val);
    	add(i, n + 1, val), add(n + 1, i, val);
    }
    dij();
    rep (i, 1, n) printf("%lld ", dis[i]); putchar(10);
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 200020 ;
const int INF = 1e9 ;
int n, m;
struct Tedge
{
	int to, len;
};
vector<Tedge> edge[MAXN];
void add_edge(int u, int v, int w)
{
	Tedge temp;
	temp.to = v;
	temp.len = w;
	edge[u].push_back(temp);
}
int dist[MAXN];
bool inq[MAXN];
queue<int> q;
void spfa(int x)
{
	for (int i = 1; i <= n; ++i) dist[i] = INF;
	q.push(x);
	dist[x] = 0;
	inq[x] = true;
	while (! q.empty())
	{
		int cur = q.front();
		q.pop();
		inq[x] = false;
		for (int i = 0; i < edge[cur].size(); ++i)
		{
			int to = edge[cur][i].to;
			if (dist[to] > dist[cur] + edge[cur][i].len)
			{
				dist[to] = dist[cur] + edge[cur][i].len;
				if (! inq[to])
					inq[to] = true, q.push(to);
			}
		}
	}
}
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1, u, v, w; i <= m; ++i)
	{
		scanf("%d%d%d", &u, &v, &w);
		add_edge(u, v, 2 * w);
		add_edge(v, u, 2 * w);
	}
	for (int i = 1, x; i <= n; ++i)
	{
		cin >> x;
		add_edge(n + 1, i, x);
	}
	spfa(n + 1);
	for (int i = 1; i <= n; ++i)
		cout << dist[i] << " " ;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#define P pair<long long,long long>
#define N 200010
using namespace std;
inline long long read()
{
    long long x=0; char ch=getchar();
    while(ch>'9'||ch<'0') ch=getchar();
    while(ch>='0'&&ch<='9') { x=x*10+(ch-'0'); ch=getchar(); }
    return x;
}
long long n,m,i,j,a[N],v[N],ans;
long long h[N],x,y,t;
long long z;
struct EDGE
{
    long long to,next,l;
}edge[N<<2];
void addedge(long long x,long y,long long z)
{
    edge[++t].to=y;
    edge[t].next=h[x];
    h[x]=t;
    edge[t].l=z;
}
long long d[N];
priority_queue<P,vector<P>,greater<P> > q;
pair<long long,long long> u;

int main()
{
    n=read(); m=read();
    for(i=1;i<=m;i++)
    {
        x=read(); y=read(); z=read();
        z*=2;
        addedge(x,y,z); addedge(y,x,z);
    }
    for(i=1;i<=n;i++) a[i]=read();
    for(i=1;i<=n;i++) addedge(0,i,a[i]);
    for(j=1;j<=n;j++)
    {
        d[j]=(long long)1e18;
        v[j]=0;
    }
    d[0]=0;
    q.push(make_pair(0,0));
    while(!q.empty())
    {
        x=q.top().second; q.pop();
        if(v[x]) continue;
        v[x]=1;
        for(j=h[x];j;j=edge[j].next)
        {
            y=edge[j].to;
            if(d[y]>d[x]+edge[j].l)
            {
                d[y]=d[x]+edge[j].l;
                q.push(make_pair(d[y],y));
            }
        }
    }
    for(i=1;i<=n;i++) printf("%d ",d[i]);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
using namespace std;
struct node
{
	long long dis,to,next;
}edge[2000010];
long long head[2000010],n,m,dis[2000010],num,s;
bool vis[2000010];
void add(int from,int to,long long dis)
{
	edge[++num].next=head[from];
	edge[num].dis=dis;
	edge[num].to=to;
	head[from]=num;
}
long long u,v;
void spfa()
{
	deque<int> q;
	q.push_back(0);
	while(!q.empty())
	{
		int x=q.front();
		q.pop_front();
		vis[x]=0;
		for(int i=head[x];i;i=edge[i].next)
		{
			u=edge[i].to;v=edge[i].dis;
			if(dis[x]+v<dis[u])
			{
				dis[u]=dis[x]+v;
				if(!vis[u])
				{
					if(q.size()&&dis[u]>dis[q.front()]) q.push_front(u);
					else q.push_back(u);
					vis[u]=1;
				}
			}
		}
	}
}
int main()
{
	long long x,y,z;
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=m;i++)
    {
    	scanf("%lld%lld%lld",&x,&y,&z);
    	add(x,y,2*z);
    	add(y,x,2*z);
	}
	for(int i=1;i<=n;i++)
	{
		dis[i]=9e17;
	}
	dis[0]=0;
	vis[0]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		add(0,i,x);
	}
	spfa();
	for(int i=1;i<=n;i++)
	printf("%lld ",dis[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 500005;
const int INF = 0x3f;
struct ed{
	int next,to,dis;
}
edge[2*N];
long long dist[N];
bool visit[N];
int n, m;
int cnt;
int head[N];
void addedge(int u,int v,int w)
{
	edge[++cnt].next=head[u];
	edge[cnt].to=v;
	edge[cnt].dis=w;
	head[u]=cnt;
}
void spfa(int start)
{
	queue<int> Q;
	int i, now;
	memset(visit, false, sizeof(visit));
	for (i = 0; i <= n; i++)
		dist[i] = INF;
	dist[start] = 0;
	Q.push(start);
	visit[start]= true;
	while (!Q.empty())
	{
		now = Q.front();
		Q.pop();
		visit[now] = false;

		for (i = head[now]; i; i=edge[i].next)
		{
			if (dist[edge[i].to] > dist[now] + edge[i].dis)
			{
				dist[edge[i].to] = dist[now] + edge[i].dis;
				if (visit[edge[i].to] == 0)
				{
					Q.push(edge[i].to);
	                visit[edge[i].to] = true;
				}
			}
		}
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b;
		long long c;
		scanf("%d%d%lld",&a,&b,&c);
		addedge(a,b,c*2);
		addedge(b,a,c*2);
	}
	for(int i=1;i<=n;i++)
	{
		long long a;
		scanf("%lld",&a);
		addedge(0,i,a);
	}
	spfa(0);
	for(int i=1;i<=n;i++)
	 printf("%lld ",dist[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=400010;
const int MAXM=400010;
const long long INF=1e18;
struct mapn {
	int c,nxt;
	long long v;
}e[MAXM<<2];
int head[MAXN],cnt=0;
bool visit[MAXN];
long long num[MAXN],dis[MAXN];
priority_queue< pair<int,int> >q;
int n,m;

inline void read(int x,int y,long long z) {
	e[++cnt].c=y;
	e[cnt].v=z;
	e[cnt].nxt=head[x];
	head[x]=cnt;
}

void Dijkstra(int sur) {
	for(register int i=1;i<=n+1;i++) dis[i]=INF;
	dis[sur]=0;
	q.push(make_pair(0,sur));
	while(q.size()) {
		sur=q.top().second; q.pop();
		if(visit[sur]) continue;
		visit[sur]=true;
		for(register int i=head[sur];i;i=e[i].nxt) {
			int child=e[i].c; long long val=e[i].v;
			if(dis[child]>dis[sur]+val) {
				dis[child]=dis[sur]+val;
				q.push(make_pair(-dis[child],child));
			}
		}
	}
}

int main() {
	int x,y,z;
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=m;i++) {
		scanf("%d%d%d",&x,&y,&z);
		read(x,y,z<<1);read(y,x,z<<1);
	}
	for(register int i=1;i<=n;i++) {
		scanf("%lld",&num[i]);
		read(n+1,i,num[i]);read(i,n+1,num[i]);

	}
	Dijkstra(n+1);
	for(register int i=1;i<=n;i++)
		printf("%lld ",dis[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=400010;
const int MAXM=400010;
const long long INF=1e18;
struct mapn {
	int c,nxt;
	long long v;
}e[MAXM<<2];
int head[MAXN],cnt=0;
bool visit[MAXN];
long long num[MAXN],dis[MAXN];
priority_queue< pair<int,int> >q;
int n,m;

inline void read(int x,int y,long long z) {
	e[++cnt].c=y;
	e[cnt].v=z;
	e[cnt].nxt=head[x];
	head[x]=cnt;
}

void Dijkstra(int sur) {
	for(register int i=1;i<=n+1;i++) dis[i]=INF;
	dis[sur]=0;
	q.push(make_pair(0,sur));
	while(q.size()) {
		sur=q.top().second; q.pop();
		if(visit[sur]) continue;
		visit[sur]=true;
		for(register int i=head[sur];i;i=e[i].nxt) {
			int child=e[i].c; long long val=e[i].v;
			if(dis[child]>dis[sur]+val) {
				dis[child]=dis[sur]+val;
				q.push(make_pair(-dis[child],child));
			}
		}
	}
}

int main() {
	int x,y,z;
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=m;i++) {
		scanf("%d%d%d",&x,&y,&z);
		read(x,y,z<<1);read(y,x,z<<1);
	}
	for(register int i=1;i<=n;i++) {
		scanf("%lld",&num[i]);
		read(n+1,i,num[i]);

	}
	Dijkstra(n+1);
	for(register int i=1;i<=n;i++)
		printf("%lld ",dis[i]);
	return 0;
}


// luogu-judger-enable-o2
// luogu-judger-enable-o2
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#define ll long long
const int MaxN = 1005000, MaxM = 1000100;
struct edge
{
    ll to, dis, next;
};
edge e[MaxM];
ll head[MaxN], dis[MaxN], cnt;
bool vis[MaxN];
ll n, m, s;
inline void add_edge( int u, int v, ll d )
{
    cnt++;
    if(u==s)
    e[cnt].dis=d;
    else
    e[cnt].dis =2*d;
    e[cnt].to = v;
    e[cnt].next = head[u];
    head[u] = cnt;
}
struct node
{
    ll dis;
    ll pos;
    bool operator <( const node &x )const
    {
        return x.dis < dis;
    }
};
std::priority_queue<node> q;
inline void dijkstra()
{
    dis[s] = 0;
    q.push( ( node ){0, s} );
    while( !q.empty() )
    {
        node tmp = q.top();
        q.pop();
        int x = tmp.pos, d = tmp.dis;
        if( vis[x] )
            continue;
        vis[x] = 1;
        for( int i = head[x]; i; i = e[i].next )
        {
            int y = e[i].to;
            if( dis[y] > dis[x] + e[i].dis )
            {
                dis[y] = dis[x] + e[i].dis;
                if( !vis[y] )
                {
                    q.push( ( node ){dis[y], y} );
                }
            }
        }
    }
}
int main()
{
    scanf( "%d%d", &n, &m);
    s=n+1;
    for( register int i = 0; i < m; ++i )
    {
        register int u, v, d;
        scanf( "%d%d%d", &u, &v, &d );
        add_edge( u, v, d );
        add_edge( v, u, d );
    }
    int mil;
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&mil);
    	dis[i]=1e16;
    	add_edge(s,i,mil);
	}
    dijkstra();
    for( int i = 1; i <= n; i++ )
        printf( "%d ", dis[i] );
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=2*1e5+1;
const ll M=2*1e5+1;
ll n,m;
struct edge{
	ll num;
	ll w;
};
vector<edge> q[N];
ll d[N],vis[N];
ll read()
{
	ll x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
void dijkstra()
{
	priority_queue<pair<int, int> >Q;
	d[0]=0;
	Q.push(make_pair(0,0));
	while(!Q.empty())
	{
		ll x=Q.top().second;Q.pop();
		if(!vis[x])
		{
			vis[x]=1;
			for(ll i=0;i<q[x].size();i++)
			{
				ll now=q[x][i].num;
				if(d[now]>d[x]+q[x][i].w)
				{
					d[now]=d[x]+q[x][i].w;
					Q.push(make_pair(-d[now],now));
				}
			}
		}
	}
}
int main()
{
	memset(d,0x3f,sizeof(d));
	n=read();
	m=read();
	for(ll i=1;i<=m;i++)
	{
		ll x=read(),y=read();
		ll w=read();
		q[x].push_back((edge){y,w*2});
		q[y].push_back((edge){x,w*2});
	}
	for(ll i=1;i<=n;i++)
	{
		ll a=read();
		q[0].push_back((edge){i,a});
	}
	dijkstra();
	for(ll i=1;i<=n;i++)
		printf("%lld ",d[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,m,s,ans;
long long d[200010];
long long vis[200010];
struct b{
	long long u,v,w;
};
const long long mx=1e18;
vector<b> c[200010];
queue<long long> q;
int main()
{
	//freopen("a.txt","r",stdin);
	cin>>n>>m;
	for(long long i=1;i<=m;i++){
		long long u,v,w;
		cin>>u>>v>>w;
		w*=2;
		c[u].push_back((b){u,v,w});
		c[v].push_back((b){v,u,w});
	}
	for(long long i=1;i<=n;i++) cin>>d[i];
	for(int i=1;i<=n;i++){
		c[0].push_back((b){0,i,d[i]});
		d[i]=mx;
	}
	s=0;
	vis[s]=1;
	q.push(s);
	while(!q.empty()){
		long long now=q.front();
		q.pop();
		vis[now]=0;
		for(long long i=0;i<c[now].size();i++){
			if(d[c[now][i].v]>d[now]+c[now][i].w){
				d[c[now][i].v]=d[now]+c[now][i].w;
				if(vis[c[now][i].v]==0){
					vis[c[now][i].v]=1;
					q.push(c[now][i].v);
				}
			}
		}
	}
	for(long long i=1;i<=n;i++){
		cout<<d[i]<<' ';
	}
    //system("pause");
    return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
const int maxn = 2e5 + 10;
const long long inf = 1e12;
vector<pair<int, long long> >son[maxn];
queue<pair<int, long long> >q;
long long dis[maxn];
long long a[maxn];
bool vis[maxn];
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i <= n; i++)
	{
		dis[i] = inf;
	}
	for (int i = 0; i < m; i++)
	{
		int u, v;
		long long w;
		cin >> u >> v >> w;
		son[u].push_back({ v,2 * w });
		son[v].push_back({ u,2 * w });
	}
	for (int i = 1; i <= n; i++)
	{
		long long ticket;
		cin >> ticket;
		son[0].push_back({ i,ticket });
		q.push({ i,ticket });
		dis[i] = ticket;
		vis[i] = 1;
	}
	dis[0] = 0;
	while (!q.empty())
	{
		int u = q.front().first;
		long long cost = q.front().second;
		q.pop();
		vis[u] = 0;
		for (int i = 0; i < son[u].size(); i++)
		{
			int v = son[u][i].first;
			long long w = son[u][i].second;
			if (dis[v] > dis[u] + w)
			{
				dis[v] = dis[u] + w;
				if (vis[v] == 0)
				{
					q.push({ v,w });
					vis[v] = 1;
				}
			}
		}
	}
	for (int i = 1; i <= n; i++)
		cout << dis[i] << ' ';
	cout << endl;
	return 0;
}


#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=2*1e5+1;
const int INF=1e9;
int n,m,ans;
int head[maxn],nxt[maxn<<1],tot,to[maxn<<1],val[maxn<<1],c[maxn];
int v[maxn],dist[maxn];
void add(int x,int y,int z)
{
    to[++tot]=y;
    nxt[tot]=head[x];
    val[tot]=z;
    head[x]=tot;
}
void spfa(int s)
{
    memset(v,0,sizeof(v));
    memset(dist,0x3f,sizeof(dist));
    queue<int> q;
    q.push(s);v[s]=1;dist[s]=0;
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        v[x]=0;
        for(int i=head[x];i;i=nxt[i])
        {
            int y=to[i];
            if(dist[y]>dist[x]+val[i])
            {
                dist[y]=dist[x]+val[i];
                if(!v[y])
                    v[y]=1,q.push(y);
            }
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        add(u,v,w);
        add(v,u,w);
    }
    for(int i=1;i<=n;i++)
        scanf("%d",&c[i]);
    for(int i=1;i<=n;i++)
    {
        ans=INF;
        spfa(i);
        for(int j=1;j<=n;j++)
            ans=min(ans,dist[j]*2+c[j]);
        printf("%d ",ans);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#define MAXN 700010
#define ll long long
#define inf 0x3f
#define mk(x,y) make_pair(x,y)
using namespace std;
struct node{
	int nex,to;
	ll dis;
}a[MAXN];
int head[MAXN],cnt;
void add(int u,int v,ll w)
{
	a[++cnt].nex=head[u];
	a[cnt].to=v;
	a[cnt].dis=w;
	head[u]=cnt;
}
int n,m,vis[MAXN];
ll dis[MAXN];
priority_queue<pair<ll,int> > q;
void dij()
{
	for(int i=1;i<=n;i++) dis[i]=inf;
	for(int i=1;i<=n;i++) vis[i]=0;
	q.push(mk(0,0));
	while(!q.empty())
	{
		int u=q.top().second;
		q.pop();
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=head[u];i;i=a[i].nex)
		{
			int v=a[i].to;
			if(dis[v]>dis[u]+a[i].dis)
			{
				dis[v]=dis[u]+a[i].dis;
				if(!vis[v])
					q.push(mk(-dis[v],v));
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;ll z;
		scanf("%d%d%lld",&x,&y,&z);
		add(x,y,z<<1);
		add(y,x,z<<1);
	}
	for(int i=1;i<=n;i++)
	{
		ll z;
		scanf("%lld",&z);
		add(0,i,z);
	}
	dij();
	for(int i=1;i<=n;i++)
		printf("%lld ",dis[i]);
	return 0;
}


//
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<ctime>
using namespace std;
#define MAXN 200005
#define MAXM 1005
#define LL long long
#define INF 0x3f3f3f3f
int n,m,k;
vector<pair<int,LL> >G[MAXN];
LL d[MAXN];
struct cmp
{
    bool operator()(int a,int b)
    {
        return d[a]>d[b];
    }
};
priority_queue<int,vector<int>,cmp> Q;
//priority_queue<int>Q;
bool f[MAXN],vis[MAXN];
void Init()
{
	while(!Q.empty())
		Q.pop();
	memset(vis,0,sizeof(vis));
	//for(int i=1;i<=n;i++)
	//	d[i]=9223372036854775800;
	//memset(d,INF,sizeof(d));
}
void spfa()
{
	Init();
	Q.push(0);d[0]=0;vis[0]=1;
	while(!Q.empty())
	{
		int u=Q.top();
		Q.pop();
		vis[u]=0;
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i].first;
			LL w=G[u][i].second;
			if(d[u]+w<=d[v])
			{
				d[v]=d[u]+w;
				f[v]=0;
				if(!vis[v])
				{
					vis[v]=1;
					Q.push(v);
				}
			}
		}
	}
}
int main()
{
	//srand(time(NULL));
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		LL w;
		scanf("%d %d %lld",&u,&v,&w);
		w=w*2;
		G[u].push_back(make_pair(v,w));
		G[v].push_back(make_pair(u,w));
	}
	for(int i=1;i<=n;i++)
	{
		LL w;
		scanf("%lld",&w);
		G[0].push_back(make_pair(i,w));
		//G[i].push_back(make_pair(0,w));
		d[i]=9223372036854775800;
		//random_shuffle(G[i].begin(),G[i].end());//随机化spfa
	}
	//random_shuffle(G[0].begin(),G[0].end());
	spfa();
	for(int i=1;i<n;i++)
		printf("%lld ",d[i]);
	printf("%lld\n",d[n]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long
struct cow{int x,y;ll z;}e[N<<2];
int head[N],tot,n,m;ll dis[N],a[N];
void inse(int xxxx,int yyyy,ll zzzz){
	e[++tot].x=head[xxxx];
	head[xxxx]=tot;
	e[tot].y=yyyy;
	e[tot].z=zzzz;
}
#define P pair<ll,int>
#define E(x,y) make_pair(x,y)
int v[N];priority_queue<P>q;
void DJ(){
	memset(dis,90,sizeof(dis));
	q.push(E(0,0));dis[0]=0;
	while(!q.empty()){
		int x=q.top().second;q.pop();
		if(v[x])continue;v[x]=1;
		for(int i=head[x];i;i=e[i].x){
			int y=e[i].y,z=e[i].z;
			if(dis[x]+z<dis[y]){
				dis[y]=dis[x]+z;
				q.push(E(-dis[y],y));
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y,z;scanf("%d%d%lld",&x,&y,&z);
		inse(x,y,z<<1);inse(y,x,z<<1);
	}
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	    inse(i,0,a[i]);
		inse(0,i,a[i]);
	}DJ();
	for(int i=1;i<=n;i++)printf("%lld ",dis[i]);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=2e5+10;
int vis[maxn];
long long dis[maxn];
struct E{
	int to;
	int next;
	long long val;
}ed[maxn*3];
int tot;
int head[maxn];
void J(int a,int b,long long c){
	tot++;
	ed[tot].to=b;
	ed[tot].val=c;
	ed[tot].next=head[a];
	head[a]=tot;
}
struct Node{
	long long dis;
	int x;
	friend bool operator < (Node a,Node b){
		return a.dis>b.dis;
	}
	Node(int a,long long b){
		x=a;
		dis=b;
	}
};
priority_queue<Node> qu;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int js1,js2,js3;
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&js1,&js2,&js3);
		J(js1,js2,2*js3);
		J(js2,js1,2*js3);
	}
	for(int i=1;i<=n;i++){
		scanf("%lld",&js1);
		J(0,i,js1);
	}
	memset(dis,0x3f,sizeof(dis));
	dis[0]=0;
	qu.push(Node(0,0));
	while(!qu.empty()){
		Node js=qu.top();
		qu.pop();
		if(vis[js.x])
			continue;
		vis[js.x]=1;
		for(int i=head[js.x];i;i=ed[i].next){
			int to=ed[i].to;
			long long di=js.dis+ed[i].val;
			if(dis[to]>di){
				dis[to]=di;
				qu.push(Node(to,di));
			}
		}
	}
	for(int i=1;i<=n;i++)
		printf("%lld ",dis[i]);
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
using namespace std;
const int N = 200001;
struct node {
    int to, len;
    node(int tt, int ll)
        : to(tt)
        , len(ll)
    {
    }
    node() {}
};
vector<node> v[N];
int n, m;
int dist[N];
bool inq[N];
inline void spfa()
{
    queue<int> q;
    for (int i = 1; i <= n; ++i)
        q.push(i), inq[i] = true;
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        inq[cur] = false;
        for (node t : v[cur])
            if (dist[t.to] > dist[cur] + t.len) {
                dist[t.to] = dist[cur] + t.len;
                if (!inq[t.to])
                    q.push(t.to), inq[t.to] = true;
            }
    }
}
int main()
{
    scanf("%d%d", &n, &m);
    while (m--) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        v[a].push_back(node(b, c * 2)), v[b].push_back(node(a, c * 2));
    }
    for (int i = 1; i <= n; ++i)
        scanf("%d", &dist[i]);
    spfa();
    for (int i = 1; i <= n; ++i)
        printf("%d ", dist[i]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=200010;
const int MAXM=200010;
const long long INF=1e18;
struct mapn {
	int c,nxt;
	long long v;
}e[MAXM<<1];
int head[MAXN],cnt=0;
bool visit[MAXN];
long long num[MAXN],dis[MAXN];
priority_queue< pair<int,int> >q;
int n,m;

inline void read(int x,int y,long long z) {
	e[++cnt].c=y;
	e[cnt].v=z;
	e[cnt].nxt=head[x];
	head[x]=cnt;
}

void Dijkstra(int sur) {
	for(register int i=1;i<=n+1;i++) dis[i]=INF;
	dis[sur]=0;
	q.push(make_pair(0,sur));
	while(q.size()) {
		sur=q.top().second; q.pop();
		if(visit[sur]) continue;
		visit[sur]=true;
		for(register int i=head[sur];i;i=e[i].nxt) {
			int child=e[i].c;
			long long val=e[i].v;
			if(dis[child]>dis[sur]+val) {
				dis[child]=dis[sur]+val;
				q.push(make_pair(dis[child],child));
			}
		}
	}
}

int main() {
	int x,y,z;
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=m;i++) {
		scanf("%d%d%d",&x,&y,&z);
		read(x,y,z<<1);read(y,x,z<<1);
	}
	for(register int i=1;i<=n;i++) {
		scanf("%lld",&num[i]);
		read(n+1,i,num[i]);read(i,n+1,num[i]);

	}
	Dijkstra(n+1);
	for(register int i=1;i<=n;i++)
		printf("%lld ",dis[i]);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 200005;
int n, m;
bool f[N];
ll a[N], dis[N];
vector<pair<int, ll> > e[N];
priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > q;
void dijkstra(){
	memset(f, 0, sizeof(f));
	memcpy(dis, a, sizeof(dis));
	for (int i = 1; i <= n; i++) q.push({a[i], i});
	while (!q.empty()){
		int u = q.top().second;
		q.pop();
		if (f[u]) continue;
		f[u] = 1;
		for (int i = 0; i < e[u].size(); i++){
			int v = e[u][i].first;
			ll w = e[u][i].second;
			if (dis[v] > dis[u]+w){
				dis[v] = dis[u]+w;
				q.push({dis[v], v});
			}
		}
	}
}
int main(){
	std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	freopen("test_file/in.txt", "r", stdin);
//	freopen("test_file/out.out", "w", stdout);
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int u, v;
		ll w;
		cin >> u >> v >> w;
		w *= 2;
		e[u].push_back({v, w});
		e[v].push_back({u, w});
	}
	for (int i = 1; i <= n; i++) cin >> a[i];
	dijkstra();
	for (int i = 1; i <= n; i++) cout << dis[i] << ' ';
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
using namespace std;

struct node
{
	int to,next;
	long long s;
};

const int N=500010;
int n,m,s,num_edge=0,h[N],l=0,a[N],wei[N],len=0;
long long dis[N];
node edge[2*N];

int read()
{
	char c=getchar();
	int num=0,f=1;
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		num=num*10-'0'+c;
		c=getchar();
	}
	return f*num;
}

void add(int x,int y,long long z)
{
	num_edge++;
	edge[num_edge].to=y;
	edge[num_edge].next=h[x];
	edge[num_edge].s=z;
	h[x]=num_edge;
	return;
}

void in(int x)
{
	len++;
	a[len]=x;
	wei[x]=len;
	int y=len;
	while(y>1&&dis[a[y]]<dis[a[y/2]])
	{
		swap(wei[a[y]],wei[a[y/2]]);
		swap(a[y],a[y/2]);
		y=y/2;
	}
	return;
}

int out()
{
	int ans;
	ans=a[1];
	a[1]=a[len];
	wei[a[1]]=1;
	wei[a[len]]=0;
	a[len]=0;
	len--;
	int y=1,k;
	while(y<=len/2)
	{
		if(y*2+1>len) k=y*2;
		else
		{
			if(dis[a[y*2]]<dis[a[y*2+1]]) k=y*2;
			else k=y*2+1;
		}
		if(dis[a[y]]>dis[a[k]])
		{
			swap(wei[a[y]],wei[a[k]]);
			swap(a[y],a[k]);
			y=k;
		}
		else break;
	}
	return ans;
}

void protect(int x)
{
	int y=x;
	while(y>1&&dis[a[y]]<dis[a[y/2]])
	{
		swap(wei[a[y]],wei[a[y/2]]);
		swap(a[y],a[y/2]);
		y=y/2;
	}
	return;
}

int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	n=read(); m=read();
	int x,y;
	long long z;
	for(int i=1; i<=m; i++)
	{
		x=read(); y=read(); cin>>z;
		add(x,y,z*2);
		add(y,x,z*2);
	}
	for(int i=1; i<=n; i++)
	{
		cin>>z;
		add(0,i,z);
		add(i,0,z);
	}
	for(int i=1; i<=n; i++) dis[i]=1000000000010;
	s=0;
	dis[s]=0;
	in(s);
	l=1;
	while(l<=n+1)
	{
		int g;
		g=out();
		for(int i=h[g]; i!=0; i=edge[i].next)
		{
			if(dis[edge[i].to]==1000000000010)
			{
				dis[edge[i].to]=dis[g]+edge[i].s;
				in(edge[i].to);
			}
			else
			{
				if(dis[edge[i].to]<=dis[g]+edge[i].s) continue;
				else
				{
					dis[edge[i].to]=dis[g]+edge[i].s;
					protect(wei[edge[i].to]);
				}
			}
		}
		l++;
	}
	for(int i=1; i<=n; i++) cout<<dis[i]<<' ';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct re
{
	int nxt,to;
	long long dis;
}edge[500010];
int num,head[500010],s,n,m,vis[500010];
int x,y,z,cnt;
long long a[300010],dis[500010];
void add(int from,int to,int z)
{
	edge[++num].to=to;
	edge[num].dis=z;
	edge[num].nxt=head[from];
	head[from]=num;
}
void spfa()
{
	queue<int>q;
	for(int i=1;i<=n+1;i++)
	dis[i]=10000000;
	memset(vis,0,sizeof(vis));
	 q.push(s);
	 dis[s]=0;
     vis[s]=1;
	 while(!q.empty())
	 {
	  int u=q.front();
		  q.pop();
		  vis[u]=0;
		for(int i=head[u];i;i=edge[i].nxt)
		{
			int v=edge[i].to;
            if(dis[v]>dis[u]+edge[i].dis)
 			{
			dis[v]=dis[u]+edge[i].dis;
				if(!vis[v])
				{
				vis[v]=1;
				q.push(v);
				}
			}
		}
     }
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
	scanf("%d%d%lld",&x,&y,&z);
	add(x,y,z*2);
	add(y,x,z*2);
	}
	for(int i=1;i<=n;i++)
	{
	scanf("%lld",&a[i]);
	add(n+1,i,a[i]);
	add(i,n+1,a[i]);
	}
	s=n+1;
	spfa();

	for(int i=1;i<=n;i++)
	cout<<dis[i]<<" ";

	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define M make_pair
using namespace std;
const int maxn=2e5+10;
struct edge{
	int next,to,dis;
}a[maxn*4];
int head[maxn],cnt,dis[maxn];
bool used[maxn];
void add(int x,int y,int w)
{
	a[++cnt].dis=w;
	a[cnt].next=head[x];
	a[cnt].to=y;
	head[x]=cnt;
}
int n,m;
priority_queue<pair<int,int> >q;
void dijkstra()
{
	dis[0]=0;
	q.push(M(0,0));
	while(!q.empty())
	{
		int x=q.top().second;
		q.pop();
		if(used[x])continue;
		used[x]=1;
		for(int i=head[x];i;i=a[i].next)
		{
			int y=a[i].to;
			if(dis[x]+a[i].dis<dis[y]){
				dis[y]=a[i].dis+dis[x];
				q.push(M(-dis[y],y));
			}
		}
	}
}
signed main()
{
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y,w;
		scanf("%lld %lld %lld",&x,&y,&w);
		add(x,y,2*w);
		add(y,x,2*w);
	}
	for(int i=1;i<=n;i++)
	{
		int w;
		scanf("%lld",&w);
		add(0,i,w);
		add(i,0,w);
	}
	memset(dis,0x3f,sizeof(dis));
	dijkstra();
	for(int i=1;i<=n;i++)
	printf("%lld ",dis[i]);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=2*1e5+1;
const ll M=2*1e5+1;
priority_queue<pair<int, int> >Q;
ll n,m;
struct edge{
	ll num;
	ll w;
};
vector<edge> q[N];
ll d[N];
int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
void dijkstra()
{
	d[0]=0;
	Q.push(make_pair(0,0));
	while(!Q.empty())
	{
		ll x=Q.top().second;Q.pop();
		for(ll i=0;i<q[x].size();i++)
		{
			ll now=q[x][i].num;
			if(d[now]>d[x]+q[x][i].w)
			{
				d[now]=d[x]+q[x][i].w;
				Q.push(make_pair(-d[now],now));
			}
		}
	}
}
int main()
{
	memset(d,0x3f,sizeof(d));
	n=read();
	m=read();
	for(ll i=1;i<=m;i++)
	{
		ll x=read(),y=read();
		ll w=read();
		q[x].push_back((edge){y,w*2});
		q[y].push_back((edge){x,w*2});
	}
	for(ll i=1;i<=n;i++)
	{
		ll a=read();
		q[0].push_back((edge){i,a});
	}
	dijkstra();
	for(ll i=1;i<=n;i++)
		printf("%lld ",d[i]);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=2e5+10;
int vis[maxn];
long long dis[maxn];
struct E{
	int to;
	int next;
	long long val;
}ed[maxn*3];
int tot;
int head[maxn];
void J(int a,int b,long long c){
	tot++;
	ed[tot].to=b;
	ed[tot].val=c;
	ed[tot].next=head[a];
	head[a]=tot;
}
struct Node{
	long long dis;
	int x;
	friend bool operator < (Node a,Node b){
		return a.dis>b.dis;
	}
	Node(int a,long long b){
		x=a;
		dis=b;
	}
};
priority_queue<Node> qu;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int js1,js2,js3;
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&js1,&js2,&js3);
		J(js1,js2,2ll*js3);
		J(js2,js1,2ll*js3);
	}
	for(int i=1;i<=n;i++){
		scanf("%lld",&js1);
		J(0,i,js1);
	}
	memset(dis,0x3f,sizeof(dis));
	dis[0]=0ll;
	qu.push(Node(0,0ll));
	while(!qu.empty()){
		Node js=qu.top();
		qu.pop();
		if(vis[js.x])
			continue;
		vis[js.x]=1;
		for(int i=head[js.x];i;i=ed[i].next){
			int to=ed[i].to;
			long long di=js.dis+ed[i].val;
			if(dis[to]>di){
				dis[to]=di;
				qu.push(Node(to,di));
			}
		}
	}
	for(int i=1;i<=n;i++)
		printf("%lld ",dis[i]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 100005
#define P pair<int,int>
using namespace std;
struct edge
{
	int to;
	int cost;
};
vector<edge>g[200005];
priority_queue<P, vector<P>, greater<P> >que;
ll  d[200005];
void dij(int s)
{
	MEM(d, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first)
			continue;
		for (int i = 0; i < g[v].size(); i++)
		{
			edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
int main()
{
	//IOS;
	//freopen("1.txt.txt", "r", stdin);
	int n, m;
	cin >> m >> n;
	for (int i = 0; i < n; i++)
	{
		int a, b, c;
		cin >> a >> b >>c;
		g[a].push_back({ b,2 * c });
		g[b].push_back({ a,2 * c });
	}
	for (int i = 0; i < m; i++)
	{
		int a;
		cin >> a;
		g[0].push_back({ i + 1,a });
		g[i+1].push_back({ 0,a });
	}
	dij(0);
	for (int i = 1; i <= m; i++)
	{
		cout << d[i] << " ";
	}
}


#include <queue>
#include <climits>
#include <cstring>
#include <cstdio>
#define maxn 200005
#define maxm 200005
#define MAX 10000000000010
#define ll long long

using namespace std;

int n,m,tot,f,r,x,y,z;
bool vis[maxn];
ll now,dis[maxn],w[maxm];
int v[maxn],Next[maxm],Head[maxn],q[maxn*2];

inline void addedge(int x,int y,ll z)
{
	v[++tot]=y,w[tot]=z;
	Next[tot]=Head[x],Head[x]=tot;
}

void spfa()
{
	f=0,r=1;
	q[0]=n+1;
	dis[n+1]=0;
	vis[n+1]=true;
	while(f<r)
	{
		int x=q[f];
		for(int i=Head[x];i;i=Next[i])
		{
			if(dis[x]+w[i]<dis[v[i]])
			{
				dis[v[i]]=dis[x]+w[i];
				if(!vis[v[i]]) q[r++]=v[i];
			}
		}
		vis[q[f++]]=false;
	}
}

int main ()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		addedge(x,y,z*2);addedge(y,x,z*2);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&now);
		addedge(n+1,i,now);
		dis[i]=MAX;
	}
	spfa();
	for(int i=1;i<=n;i++)
	  printf("%lld ",dis[i]);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2*1e5+1;
const int M=2*1e5+1;
priority_queue<ll,vector<ll>,greater<ll> >Q;
int n,m;
struct edge{
	int num;
	ll w;
};
vector<edge> q[N];
ll d[N];
void dijkstra()
{
	d[0]=0;
	Q.push(0);
	while(!Q.empty())
	{
		int x=Q.top();Q.pop();
		for(int i=0;i<q[x].size();i++)
		{
			int now=q[x][i].num;
			if(d[now]>d[x]+q[x][i].w)
			{
				d[now]=d[x]+q[x][i].w;
				Q.push(now);
			}
		}
	}
}
int main()
{
	memset(d,0x3f,sizeof(d));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		ll w;
		scanf("%d%d%lld",&x,&y,&w);
		q[x].push_back((edge){y,w*2});
		q[y].push_back((edge){x,w*2});
	}
	for(int i=1;i<=n;i++)
	{
		ll a;
		scanf("%lld",&a);
		q[0].push_back((edge){i,a});
	}
	dijkstra();
	for(int i=1;i<=n;i++)
		printf("%lld ",d[i]);
	return 0;
}


#include <queue>
#include <cstring>
#include <cstdio>
#define maxn 2000005
#define maxm 2000005
#define MAX 10000000000010
#define ll long long

using namespace std;

deque<int>q;
int n,m,tot,f,r,cnt;
bool vis[maxn];
ll x,y,z,now,sum,dis[maxn],w[maxm];
int v[maxn],Next[maxm],Head[maxn];

inline void addedge(int x,int y,ll z)
{
	v[++tot]=y,w[tot]=z;
	Next[tot]=Head[x],Head[x]=tot;
}

void spfa()
{
	q.push_back(n+1);
	dis[n+1]=0;
	vis[n+1]=true;
	cnt=1;
	while(!q.empty())
	{
		int x=q.front();
		while(dis[x]*cnt>sum)
		{
			q.pop_front();
			q.push_back(x);
			x=q.front();
		}
		for(int i=Head[x];i;i=Next[i])
		{
			if(dis[x]+w[i]<dis[v[i]])
			{
				dis[v[i]]=dis[x]+w[i];
				if(!vis[v[i]])
				{
					if(dis[v[i]]<dis[q.front()]) q.push_front(v[i]);
					else q.push_back(v[i]);
					sum+=dis[v[i]];
					cnt++;
				}
			}
		}
		vis[x]=false;
		q.pop_front();
		cnt--;
		sum-=dis[x];
	}
}

int main ()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%lld%lld%lld",&x,&y,&z);
		addedge(x,y,z*2);addedge(y,x,z*2);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&now);
		addedge(n+1,i,now);
		addedge(i,n+1,now);
		dis[i]=MAX;
	}
	spfa();
	for(int i=1;i<=n;i++)
	  printf("%lld ",dis[i]);
	return 0;
}


#include<bits/stdc++.h>
#define N 201000
using namespace std;
template<typename T>inline void read(T &x)
{  x=0;
   int f=1;
   char c=getchar();
   while (!isdigit(c))
   {  if (c=='-') f=-1;
	 c=getchar();}
 while (isdigit(c))
 {    x=(x<<3)+(x<<1)+(c^48);
	c=getchar();}
	 x*=f;
}
template<typename T>inline void write(T x)
{  if (x<0) x=-x,putchar('-');
  if (x/10) write(x/10);
  putchar(x%10+48);
}
template<typename T>inline void writeln(T x)
{ write(x);
  puts("");}
int n,m,cnt=1,head[N];
int que[N*10],l,r;
long long dis[N];
struct node{
	int to,mark;
	 long long val;
}pre[N<<1];
void add(int a,int b,long long c)
{  pre[++cnt].mark=head[a];
   pre[cnt].to=b;
   pre[cnt].val=c;
   head[a]=cnt;
}
bool vis[N];
void spfa(int S)
{
  que[l=r=0]=S;
  memset(dis,0x7f7f7f,sizeof(dis));
  dis[S]=0;
  while (l<=r)
  {  int u=que[l++];
     vis[u]=0;
     for (int i=head[u];i;i=pre[i].mark)
     {  int to=pre[i].to;
        if (dis[u]+pre[i].val<dis[to])
         { dis[to]=dis[u]+pre[i].val;
          if(!vis[to])
            {que[++r]=to;
              vis[to]=1;
            }
         }
     }
  }
}
int main()
{    read(n);read(m);
     for (int i=1;i<=m;i++)
     {  int u,v;
        long long w;
        read(u);read(v);read(w);
        add(u,v,w*2);add(v,u,w*2);
     }
     for (int i=1;i<=n;i++)
     {  long long w;
        read(w);
        add(0,i,w);
     }
     spfa(0);
     for (int i=1;i<=n;i++)
       write(dis[i]),putchar(' ');
     puts("");
	return 0;
}
/*
5 2 10
0 11
1 5
0 12
0 6
1 11
*/


#include<bits/stdc++.h>
using namespace std;
struct edge
{
	int to,nxt;
	long long dis;
}edge[700001];
int n,m,s;
int cnt=0;
int head[700001];
bool used[700001];
long long dis[700001];
void add_edge(int u,int v,long long w)
{
	cnt++;
	edge[cnt].dis=w;
	edge[cnt].to=v;
	edge[cnt].nxt=head[u];
	head[u]=cnt;
}
struct node
{
	int pos;
	long long dis;
	bool operator<(const node &x)const
    {
        return x.dis<dis;
    }
};
void dijkstra(int s)
{
	memset(dis,0x3f,sizeof(dis));
	memset(used,0,sizeof(used));
	priority_queue<node>q;
	dis[s]=0;
	q.push((node){s,0});
	while(!q.empty())
	{
		int u=q.top().pos;
		q.pop();
		if(used[u]) continue;
		used[u]=1;
		for(int p=head[u];p!=0;p=edge[p].nxt)
		{
			int v=edge[p].to;
			if(dis[v]>dis[u]+edge[p].dis)
            {
				dis[v]=dis[u]+edge[p].dis;
				if(!used[v]) q.push((node){v,dis[v]});
            }
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		long long w;
		scanf("%d%d%lld",&u,&v,&w);
		add_edge(u,v,w*2);
        add_edge(v,u,w*2);
	}
	for(int i=1;i<=n;i++)
	{
		long long w;
        scanf("%lld",&w);
        add_edge(0,i,w);
	}
	dijkstra(0);
	for(int i=1;i<=n;i++) printf("%lld ",dis[i]);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const ll Inf=1e13;
ll dis[maxn];
int n,m,cnt,head[maxn];
bool vis[maxn];
struct Edge{int to,next;ll val;}e[maxn<<2];
void Add(int x,int y,ll z){
	e[++cnt].to=y;
	e[cnt].val=z;
	e[cnt].next=head[x];
	head[x]=cnt;
}
void Dij(int S){
	priority_queue<pair<ll,int> > q;
	for(int i=1;i<=n;++i)dis[i]=Inf;
	dis[S]=0;q.push(make_pair(0,S));
	while(!q.empty()){
		int x=q.top().second;q.pop();
		if(vis[x])continue;
		vis[x]=1;
		for(int i=head[x];i;i=e[i].next){
			int v=e[i].to;ll w=e[i].val;
			if(!vis[v]&&dis[v]>dis[x]+w){
				dis[v]=dis[x]+w;
				q.push(make_pair(-dis[v],v));
			}
		}
	}
}
int main(){
//	freopen("1.in","r",stdin);
	scanf("%d%d",&n,&m);
	int x,y;ll z;
	for(int i=1;i<=m;++i){
		scanf("%d%d%lld",&x,&y,&z);
		Add(x,y,(z<<1));Add(y,x,(z<<1));
	}
	for(int i=1;i<=n;++i){
		scanf("%lld",&z);
		Add(i,n+1,z);Add(n+1,i,z);
	}
	Dij(n+1);
	for(int i=1;i<=n;++i)
		printf("%lld ",dis[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 200020
struct node{
	int d;
	ll w;
	friend bool operator <(node x,node y){return x.w>y.w;}
};
priority_queue <node> que;
ll w[MAX*3],dis[MAX];
bool book[MAX];
int n,m,u[MAX*3],v[MAX*3],first[MAX],net[MAX*3];
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d %lld",&u[i],&v[i],&w[i]);
		u[i+m]=v[i];
		v[i+m]=u[i];
		w[i]*=2;
		w[i+m]=w[i];
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&w[(m<<1)+i]);
		u[(m<<1)+i]=n+1;
		v[(m<<1)+i]=i;
	}
	for(int i=1;i<=(m<<1)+n;i++)
	{//if(u[i]==5)cout<<"md";
		net[i]=first[u[i]];
		first[u[i]]=i;
	}//cout<<first[5]<<" ";
	for(int i=1;i<=n;i++)
		dis[i]=1e17;
	dis[n+1]=0;
	que.push((node){n+1,0});
	while(!que.empty())
	{
		node cu=que.top();
		que.pop();
		if(!book[cu.d])
		{//cout<<cu.d<<endl;
			book[cu.d]=1;
			for(int i=first[cu.d];i;i=net[i])
			{//cout<<v[i]<<endl;
				if(dis[v[i]]>dis[cu.d]+w[i])
				{//if(v[i]==2)cout<<i<<" "<<w[i]<<" "<<cu.d<<" "<<dis[cu.d]<<" "<<dis[v[i]]<<endl;
					dis[v[i]]=dis[cu.d]+w[i];
					que.push((node){v[i],dis[v[i]]});
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
		printf("%lld ",dis[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxn=2e5+7;
int n,m;

struct edge{
	int to,nxt,w;
}E[maxn<<2];
int head[maxn<<1],cnt=1;

void addedge(int u,int v,int w)
{
	E[cnt].to=v;
	E[cnt].nxt=head[u];
	E[cnt].w=w;
	head[u]=cnt++;
}

struct node{
	int in,w;
	friend bool operator <(node a,node b){
		return a.w<b.w;
	}
	friend bool operator >(node a,node b){
		return b<a;
	}
	node(int _in,int _w){in=_in,w=_w;}
};

long long dist[maxn];
int vis[maxn];
void dij()
{
	memset(dist,127,sizeof(dist));
	priority_queue<node,vector<node>,greater<node> > q;
	q.push(node(n+1,0));
	dist[n+1]=0;
	while(!q.empty()){
		node now=q.top();q.pop();
		int in=now.in,w=now.w;
		if(vis[in])continue;
		vis[in]=1;
		for(int i=head[in];i;i=E[i].nxt){
			int to=E[i].to;
			if(dist[to]>dist[in]+E[i].w){
				dist[to]=dist[in]+E[i].w;
				q.push(node(to,dist[to]));
			}
		}
	}
}

int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;++i){
		int u,v,w;
		scanf("%d %d %d",&u,&v,&w);
		addedge(u,v,2*w);
		addedge(v,u,2*w);
	}
	for(int i=1;i<=n;++i){
		int w;
		scanf("%d",&w);
		addedge(n+1,i,w);
	}
	dij();
	for(int i=1;i<=n;++i)printf("%lld ",dist[i]);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
using namespace std;

struct node
{
	int to,next,s;
};

int n,m,s,num_edge=0,h[200010],l=0,a[200010],wei[200010],len=0;
long long dis[200000];
node edge[400010];

int read()
{
	char c=getchar();
	int num=0,f=1;
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		num=num*10-'0'+c;
		c=getchar();
	}
	return f*num;
}

void add(int x,int y,int z)
{
	num_edge++;
	edge[num_edge].to=y;
	edge[num_edge].next=h[x];
	edge[num_edge].s=z;
	h[x]=num_edge;
	return;
}

void in(int x)
{
	len++;
	a[len]=x;
	wei[x]=len;
	int y=len;
	while(y>1&&dis[a[y]]<dis[a[y/2]])
	{
		swap(wei[a[y]],wei[a[y/2]]);
		swap(a[y],a[y/2]);
		y=y/2;
	}
	return;
}

int out()
{
	int ans;
	ans=a[1];
	a[1]=a[len];
	wei[a[1]]=1;
	wei[a[len]]=0;
	a[len]=0;
	len--;
	int y=1,k;
	while(y<=len/2)
	{
		if(y*2+1>len) k=y*2;
		else
		{
			if(dis[a[y*2]]<dis[a[y*2+1]]) k=y*2;
			else k=y*2+1;
		}
		if(dis[a[y]]>dis[a[k]])
		{
			swap(wei[a[y]],wei[a[k]]);
			swap(a[y],a[k]);
			y=k;
		}
		else break;
	}
	return ans;
}

void protect(int x)
{
	int y=x;
	while(y>1&&dis[a[y]]<dis[a[y/2]])
	{
		swap(wei[a[y]],wei[a[y/2]]);
		swap(a[y],a[y/2]);
		y=y/2;
	}
	return;
}

int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	n=read(); m=read();
	int x,y,z;
	for(int i=1; i<=m; i++)
	{
		x=read(); y=read(); z=read();
		add(x,y,z*2);
		add(y,x,z*2);
	}
	for(int i=1; i<=n; i++)
	{
		x=read();
		add(0,i,x);
		add(i,0,x);
	}
	for(int i=1; i<=n; i++) dis[i]=1000000000010;
	s=0;
	dis[s]=0;
	in(s);
	l=1;
	while(l<=n+1)
	{
		int g;
		g=out();
		for(int i=h[g]; i!=0; i=edge[i].next)
		{
			if(dis[edge[i].to]==1000000000010)
			{
				dis[edge[i].to]=dis[g]+edge[i].s;
				in(edge[i].to);
			}
			else
			{
				if(dis[edge[i].to]<=dis[g]+edge[i].s) continue;
				else
				{
					dis[edge[i].to]=dis[g]+edge[i].s;
					protect(wei[edge[i].to]);
				}
			}
		}
		l++;
	}
	for(int i=1; i<=n; i++) cout<<dis[i]<<' ';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxn=2e5+7;
int n,m;

struct edge{
	int to,nxt,w;
}E[maxn<<1];
int head[maxn],cnt=1;

void addedge(int u,int v,int w)
{
	E[cnt].to=v;
	E[cnt].nxt=head[u];
	E[cnt].w=w;
	head[u]=cnt++;
}

struct node{
	int in,w;
	friend bool operator <(node a,node b){
		return a.w<b.w;
	}
	friend bool operator >(node a,node b){
		return b<a;
	}
	node(int _in,int _w){in=_in,w=_w;}
};

int dist[maxn],vis[maxn];
void dij()
{
	memset(dist,127,sizeof(dist));
	priority_queue<node,vector<node>,greater<node> > q;
	q.push(node(n+1,0));
	dist[n+1]=0;
	while(!q.empty()){
		node now=q.top();q.pop();
		int in=now.in,w=now.w;
		if(vis[in])continue;
		vis[in]=1;
		for(int i=head[in];i;i=E[i].nxt){
			int to=E[i].to;
			if(dist[to]>dist[in]+E[i].w){
				dist[to]=dist[in]+E[i].w;
				q.push(node(to,dist[to]));
			}
		}
	}
}

int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;++i){
		int u,v,w;
		scanf("%d %d %d",&u,&v,&w);
		addedge(u,v,2*w);
	}
	for(int i=1;i<=n;++i){
		int w;
		scanf("%d",&w);
		addedge(i,n+1,w);
		addedge(n+1,i,w);
	}
	dij();
	for(int i=1;i<=n;++i)printf("%d ",dist[i]);
}


#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

const int maxn=400005;

int nex[maxn],pre[maxn],to[maxn],dis[maxn],vis[maxn],w[maxn];
int cnt,ans=2e9,ti;
queue<int>q;

void add(int x,int y,int z){
    to[++cnt]=y;
    pre[cnt]=nex[x];
    nex[x]=cnt;
    w[cnt]=z;
}
void SPFA(){

    memset(vis,0,sizeof(vis));
    q.push(0);vis[0]=1;
    dis[0]=0;
    while(!q.empty()){
        int cur=q.front();q.pop();
        vis[cur]=0;
        for(int i=nex[cur];i;i=pre[i]){
            if(dis[to[i]]>dis[cur]+w[i]){
                dis[to[i]]=dis[cur]+w[i];
                if(!vis[to[i]]){
                    q.push(to[i]);
                    vis[to[i]]=1;
                }
            }
        }
    }
}
int main(){
    int n,m,u,v,_w;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&u,&v,&_w);
        add(u,v,_w*2);add(v,u,_w*2);
    }
	memset(dis,0x3f3f3f3f,sizeof(dis));
    for(int i=1;i<=n;i++)
        scanf("%d",&ti),add(0,i,ti),add(i,0,ti);
    SPFA();
    for(int i=1;i<=n;i++)printf("%d ",dis[i]);
    return 0;
}


#include <iostream>
#include <queue>
using namespace std;
int n,m,head[200005],cnt=0;
long long dis[200005];
bool vis[200005];

struct Edge
{
    long long to,dis,next;
}e[800005];

struct Node
{
    long long dis;
    long long pos;
    bool operator <(const Node&x)const
    {
        return x.dis < dis;
    }
};

void Add(int u,int v,int d)
{
    cnt++;
    e[cnt].dis=d;
    e[cnt].to=v;
    e[cnt].next=head[u];
    head[u]=cnt;
}

priority_queue<Node> q;

void Dijkstra(int s)
{
    dis[s]=0;
    q.push( (Node){0,s} );
    while( !q.empty() )
    {
        Node tmp=q.top();q.pop();
        long long x=tmp.pos,d=tmp.dis;
        if(vis[x])continue;
        vis[x]=1;
        for(int i=head[x];i;i=e[i].next)
        {
            int y=e[i].to;
            if(dis[y]>dis[x]+e[i].dis)
            {
                dis[y]=dis[x]+e[i].dis;
                if( !vis[y] )
                    q.push( (Node){dis[y],y} );
            }
        }
    }
}
int main()
{
    cin>>n>>m;
    long long u,v,w;
    for(int i=1;i<=n;i++)
        dis[i]=0x3f3f;
    for(int i=1;i<=m;i++)
    {
        cin>>u>>v>>w;
        Add(u,v,w*2);
        Add(v,u,w*2);
    }
    long long cost;
    for(int i=1;i<=n;i++)
    {
        cin>>cost;
        Add(0,i,cost);
        Add(i,0,cost);
    }
    Dijkstra(0);
    for(int i=1;i<=n;i++)
        cout<<dis[i]<<" ";
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
int cnt,u,v,m,n,vis[200010];
long long w,dis[200010],h;
int head[600010];
struct Edge
{
	int to,next;
	long long va;
}edge[600010];
void addedge(int u,int v,long long w)
{
	edge[++cnt].to=v;
	edge[cnt].va=w;
	edge[cnt].next=head[u];
	head[u]=cnt;
}
struct cmp
{
	bool operator()(int a,int b)
	{
		return dis[a]>dis[b];
	}
};
priority_queue<int,vector<int>,cmp>q;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n+1;i++)
    dis[i]=50000000000000000;
    dis[n+1]=0;
    for(int i=1;i<=m;i++)
    {
    	scanf("%d%d%lld",&u,&v,&w);
    	addedge(u,v,w*2);
    	addedge(v,u,w*2);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&h);
		addedge(n+1,i,h);
	}
	q.push(n+1);
	while(!q.empty())
	{
		int t=q.top();
		q.pop();
		if(vis[t])
		continue;
		vis[t]=1;
		for(int i=head[t];i!=0;i=edge[i].next)
		{
			if(dis[edge[i].to]>edge[i].va+dis[t])
			{
				dis[edge[i].to]=edge[i].va+dis[t];
				q.push(edge[i].to);
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		printf("%lld ",dis[i]);
	}
	//system("pause");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int fir[N<<1],to[N<<1],nex[N<<1],w[N<<1];
ll d[N];
int n,m,head,tail,num;
priority_queue<pair<ll,int> >Q;
bool v[N];
void add(int x,int y,ll k){
	num++;
	to[num]=y;
	nex[num]=fir[x];
	w[num]=k;
	fir[x]=num;
}
int main()
{
	int i,j,x,y,k;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d%d%d",&x,&y,&k);
		add(x,y,2*k);
		add(y,x,2*k);
	}
	for(i=1;i<=n;i++){
		scanf("%d",&x);
		add(0,i,x);
		add(i,0,0);
	}
	memset(d,0x7f,sizeof(d));
	d[0]=0;
	Q.push(make_pair(0,0));
	while(!Q.empty()){
		x=Q.top().second;
		Q.pop();
		for(i=fir[x];i;i=nex[i]){
			if(d[x]+w[i]<d[to[i]]){
				d[to[i]]=d[x]+w[i];
				Q.push(make_pair(-d[to[i]],to[i]));
			}
		}
	}
	for(i=1;i<=n;i++)
		printf("%d ",d[i]);
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#define M make_pair
using namespace std;
typedef long long ll;
inline long long read(){
	long long _s=0;
	int _q=getchar(),_f=1;
	while(_q<48||_q>57){if(_q=='-')_f=-1;_q=getchar();}
	while(_q>47&&_q<58)_s=(_s<<3)+(_s<<1)+(_q^48),_q=getchar();
	return _s*_f;
}
const ll INF=500000000000000;
ll n,m,u,v,w,s,t;
vector<pair<ll,int> >mp[200005];
priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > >q;
ll dis[200005];
bool vis[200005];
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;i++)dis[i]=INF;
	for(int i=0;i<m;i++){
		u=read(),v=read(),w=read()*2;
		mp[u].push_back(M(w,v));
		mp[v].push_back(M(w,u));
	}
	for(int i=1;i<=n;i++){
		t=read();
		mp[0].push_back(M(t,i));
		mp[i].push_back(M(t,0));
	}
	q.push(M(0,0));dis[0]=0;
	while(!q.empty())
	{
		int f=q.top().second;
		q.pop();
		if(vis[f])continue;
		vis[f]=1;
		for(int i=0,temp=mp[f].size();i<temp;i++)
		{
			int dot=mp[f][i].second,lenth=dis[f]+mp[f][i].first;
			if(!vis[dot]&&dis[dot]>lenth)
			{
				q.push(M(lenth,dot));
				dis[dot]=lenth;
			}
		}
	}
	for(int i=1;i<=n;i++)
	    cout<<dis[i]<<' ';
    return 0;
}


#include<bits/stdc++.h>
#define N 200005
#define ll long long
#define maxn 0x3f3f3f3f
using namespace std;
ll head[N],dist[N],x[N],y[N],z[N],vist[N],cnt=0,n,m,ans[N],zz[N];
struct node{
	ll to,next,w;
}a[2*N];
ll read(){
	ll x=0,s=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')
		s=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*s;
}
void dj(ll x){
	for(int i=0;i<=n;i++)
	dist[i]=maxn;
	memset(vist,0,sizeof(vist));
	dist[x]=0;
	queue<int>q;
	q.pop();
	q.push(x);
	while(q.size())
{
	ll x=q.front();
	if(vist[x])
	continue;
	vist[x]=1;
	for(ll i=head[x];i;i=a[i].next)
	{
		int y=a[i].to;
		if(dist[y]>a[i].w+dist[x])
		dist[y]=a[i].w+dist[x];
		if(!vist[y])
		q.push(y);
	}
}
}
void add(ll x,ll y,ll z){
	a[++cnt].w=z;
	a[cnt].next=head[x];
	a[cnt].to=y;
	head[x]=cnt;
}
void work(){
	for(ll i=1;i<=m;i++){
	x[i]=read(),y[i]=read(),z[i]=read();
	add(x[i],y[i],z[i]);
	add(y[i],x[i],z[i]);
		}
	for(ll i=1;i<=n;i++)
	zz[i]=read();
	for(ll i=1;i<=n;i++)
	ans[i]=maxn;
	for(ll i=1;i<=n;i++){
		dj(i);
		for(ll j=1;j<=n;j++)
	ans[i]=min(zz[i],dist[j]+zz[j]);

	printf("%lld ",ans[i]);
	}

}
int main(){
	n=read(),m=read();
	work();
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define MAXN 400005
using namespace std;
long long n,m,dis[MAXN],vis[MAXN];
struct road{
	long long v,w;
	bool operator<(const road &b)const{
		return w>b.w;
	}
	road(long long ax,long long ay){
		v=ax;
		w=ay;
	}
	road(){}
};
vector<road> t[MAXN];
priority_queue<road> q;
int main(){
	scanf("%lld%lld",&n,&m);
	for(long long i=1;i<=m;i++){
		long long u,v,w;
		scanf("%lld%lld%lld",&u,&v,&w);
		t[u].push_back(road(v,w*2));
		t[v].push_back(road(u,w*2));
	}
	for(long long i=1;i<=n;i++){
		long long w;
		scanf("%lld",&w);
		t[0].push_back(road(i,w));
		dis[i]=1e18+9;
	}
	m+=n;
	q.push(road(0,0));
	while(!q.empty()){
		long long x=q.top().v;
		q.pop();
		if(vis[x]){
			continue;
		}
		vis[x]=1;
		for(long long i=0;i<t[x].size();i++){
			long long y=t[x][i].v;
			if(dis[y]>dis[x]+t[x][i].w){
				dis[y]=dis[x]+t[x][i].w;
				q.push(road(y,dis[y]));
			}
		}
	}
	for(long long i=1;i<=n;i++){
		cout<<dis[i]<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#define MP make_pair
#define fi first
#define se second
#define LL long long
using namespace std;
const LL N = 400005;
LL n,m,a[N],head[N],tot,dis[N];
struct edge{
	LL node,next,data;
}e[N<<2];
typedef pair<LL,LL> pll;
priority_queue<pll,vector<pll>,greater<pll> > q;
void add(LL x,LL y,LL z)
{
	e[++tot].node=y;
	e[tot].next=head[x];
	head[x]=tot;
	e[tot].data=z;
}
void dij()
{
	memset(dis,0x3f,sizeof(dis));
	dis[0]=0;
	q.push(MP(0,0));
	while(!q.empty())
	{
		LL u=q.top().se;
		if(dis[u]!=q.top().fi)
		{ q.pop(); continue; }
		q.pop();
		for(LL i=head[u];i;i=e[i].next)
		{
			LL v=e[i].node;
			if(dis[v]>dis[u]+e[i].data)
			{
				dis[v]=dis[u]+e[i].data;
				q.push(MP(dis[v],v));
			}
		}
	}
}
int main()
{
	scanf("%lld%lld",&n,&m);
	LL x,y,z;
	for(LL i=1;i<=m;i++)
	{
		scanf("%lld%lld%lld",&x,&y,&z);
		add(x,y,2*z); add(y,x,2*z);
	}
	for(LL i=1;i<=n;i++)
	{
		scanf("%lld",&z);
		add(0,i,z); //add(i,0,z);
	}
	dij();
	for(LL i=1;i<=n;i++)
	 printf("%lld ",dis[i]);
	return 0;
}


#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
inline long long read();
typedef pair<long, long> pll;
const long long N = 200001;
struct node {
    long long to, len;
    node(long long tt, long long ll)
        : to(tt)
        , len(ll)
    {
    }
    node() {}
};
vector<node> v[N];
long long n, m;
long long dist[N];
bool vis[N];
inline void dij()
{
    priority_queue<pll, vector<pll>, greater<pll>> q;
    for (long long i = 1; i <= n; ++i)
        q.push(make_pair(dist[i], i));
    while (!q.empty()) {
        long long cur = q.top().second;
        q.pop();
        if (vis[cur])
            continue;
        vis[cur] = true;
        for (node t : v[cur])
            if (dist[t.to] > dist[cur] + t.len) {
                dist[t.to] = dist[cur] + t.len;
                if (!vis[t.to])
                    q.push(make_pair(dist[t.to], t.to));
            }
    }
}
int main()
{
    n = read(), m = read();
    while (m--) {
        long long a = read(), b = read(), c = read();
        v[a].push_back(node(b, c * 2)), v[b].push_back(node(a, c * 2));
    }
    for (long long i = 1; i <= n; ++i)
        scanf("%lld", &dist[i]);
    dij();
    for (long long i = 1; i <= n; ++i)
        printf("%lld ", dist[i]);
    return 0;
}

inline long long read()
{
    long long s = 0;
    char ch = getchar();
    while (!isdigit(ch))
        ch = getchar();
    while (isdigit(ch))
        s = (s << 3) + (s << 1) + ch - '0', ch = getchar();
    return s;
}


#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const ll N=2*1e5+1;
const ll M=2*1e5+1;
priority_queue<pair<int, int> >Q;
ll n,m;
ll read()
{
	ll x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
struct edge{
	ll num;
	ll w;
};
vector<edge> q[N];
ll d[N];
void dijkstra()
{
	d[0]=0;
	Q.push(make_pair(0,0));
	while(!Q.empty())
	{
		ll x=Q.top().second;Q.pop();
		for(ll i=0;i<q[x].size();i++)
		{
			ll now=q[x][i].num;
			if(d[now]>d[x]+q[x][i].w)
			{
				d[now]=d[x]+q[x][i].w;
				Q.push(make_pair(-d[now],now));
			}
		}
	}
}
signed main()
{
	memset(d,0x3f,sizeof(d));
	n=read();
	m=read();
	for(ll i=1;i<=m;i++)
	{
		ll x=read(),y=read(),w=read();
		q[x].push_back((edge){y,w*2});
		q[y].push_back((edge){x,w*2});
	}
	for(ll i=1;i<=n;i++)
	{
		ll a=read();
		q[0].push_back((edge){i,a});
	}
	dijkstra();
	for(ll i=1;i<=n;i++)
		printf("%lld ",d[i]);
	return 0;
}


#include <queue>
#include <cstring>
#include <cstdio>
#define maxn 3000005
#define maxm 3000005
#define MAX 10000000000010
#define ll long long

using namespace std;

deque<int>q;
int n,m,tot,f,r,cnt,x,y;
bool vis[maxn];
ll z,now,sum,dis[maxn],w[maxm];
int v[maxn],Next[maxm],Head[maxn];

inline void addedge(int x,int y,ll z)
{
	v[++tot]=y,w[tot]=z;
	Next[tot]=Head[x],Head[x]=tot;
}

void spfa()
{
	q.push_back(n+1);
	dis[n+1]=0;
	vis[n+1]=true;
	cnt=1;
	while(!q.empty())
	{
		int x=q.front();
		while(dis[x]*cnt>sum)
		{
			q.pop_front();
			q.push_back(x);
			x=q.front();
		}
		for(int i=Head[x];i;i=Next[i])
		{
			if(dis[x]+w[i]<dis[v[i]])
			{
				dis[v[i]]=dis[x]+w[i];
				if(!vis[v[i]])
				{
					if(dis[v[i]]<dis[q.front()]) q.push_front(v[i]);
					else q.push_back(v[i]);
					vis[v[i]]=true;
					sum+=dis[v[i]];
					cnt++;
				}
			}
		}
		vis[x]=false;
		q.pop_front();
		cnt--;
		sum-=dis[x];
	}
}

int main ()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%lld",&x,&y,&z);
		addedge(x,y,z*2);addedge(y,x,z*2);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&now);
		addedge(n+1,i,now);
		dis[i]=MAX;
	}
	spfa();
	for(int i=1;i<=n;i++)
	  printf("%lld ",dis[i]);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const ll Inf=1e13;
ll dis[maxn];
int n,m,cnt,head[maxn];
bool vis[maxn];
struct Edge{int to,next;ll val;}e[maxn<<1];
void Add(int x,int y,ll z){
	e[++cnt].to=y;
	e[cnt].val=z;
	e[cnt].next=head[x];
	head[x]=cnt;
}
void Dij(int S){
	priority_queue<pair<ll,int> > q;
	for(int i=1;i<=n;++i)dis[i]=Inf;
	dis[S]=0;q.push(make_pair(0,S));
	while(!q.empty()){
		int x=q.top().second;q.pop();
		if(vis[x])continue;
		vis[x]=1;
		for(int i=head[x];i;i=e[i].next){
			int v=e[i].to;ll w=e[i].val;
			if(!vis[v]&&dis[v]>dis[x]+w){
				dis[v]=dis[x]+w;
				q.push(make_pair(-dis[v],v));
			}
		}
	}
}
int main(){
//	freopen("1.in","r",stdin);
	scanf("%d%d",&n,&m);
	int x,y;ll z;
	for(int i=1;i<=m;++i){
		scanf("%d%d%lld",&x,&y,&z);
		Add(x,y,z<<1);Add(y,x,z<<1);
	}
	for(int i=1;i<=n;++i){
		scanf("%lld",&z);
		Add(n+1,i,z);
	}
	Dij(n+1);
	for(int i=1;i<=n;++i)
		printf("%lld ",dis[i]);
	return 0;
}


#define Kafuu signed
#define Chino main

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>

#define maxn 200005
#define inf 0x3f3f3f3f
#define px putchar
#define pn px('\n')
#define ps px(' ')
#define pd puts("======================")
#define pj puts("++++++++++++++++++++++")

const int mod = 45989;

using namespace std;

inline int read(){
	int x=0,y=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')y=1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return y?-x:x;
}
template<typename T>
inline T read(){
	T x=0;
	int y=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')y=1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return y?-x:x;
}
struct edge{
	int pre,to;
	long long l;
}e[maxn<<2];
int h[maxn],num;
long long dis[maxn];
bool vis[maxn];
priority_queue<pair<long long,int>,vector<pair<long long,int> >,greater<pair<long long,int> > >q;
inline void add(int from,int to,long long l){e[++num]=(edge){h[from],to,l},h[from]=num;}
void DJ(int st){
	memset(dis,0x3f,sizeof dis);
	q.push(make_pair(dis[st]=0,st));
	while(!q.empty()){
		int node=q.top().second;
		q.pop();
		if(vis[node])continue;
		vis[node]=1;
		for(register int i=h[node];i;i=e[i].pre){
			int x=e[i].to;
			if(dis[x]>dis[node]+e[i].l)q.push(make_pair(dis[x]=dis[node]+e[i].l,x));
		}
	}
}
Kafuu Chino(){
	int n=read(),m=read(),x,y;
	long long z;
	while(m--)x=read(),y=read(),z=read<long long>()<<1,add(x,y,z),add(y,x,z);
	for(register int i=1;i<=n;++i)add(n+1,i,read<long long>());
	DJ(n+1);
	for(register int i=1;i<=n;++i)printf("%I64d ",dis[i]);
	pn;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
	ll ans=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9')
	{
		ans=(ans<<1)+(ans<<3)+(ch^48);
		ch=getchar();
	}
	return ans;
}
const int N=2e6+7;
int n,m;
struct edge
{
	int v;
	ll w;
	int nxt;
}e[N<<1];
int h[N],cnt;
void add_edge(int u,int v,ll w)
{
	++cnt;
	e[cnt]=(edge){v,w,h[u]};
	h[u]=cnt;
}
ll dis[N];
int vis[N];
priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > > q;
void dijkstra(int s)
{
	memset(dis,0x3f,sizeof(dis));
	memset(vis,0,sizeof(vis));
	dis[s]=0;
	q.push(make_pair(0,s));
	while(!q.empty())
	{
		int u=q.top().second;
		q.pop();
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=h[u];i;i=e[i].nxt)
		{
			int v=e[i].v;
			if(dis[v]>dis[u]+e[i].w)
			{
				dis[v]=dis[u]+e[i].w;
				q.push(make_pair(dis[v],v));
			}
		}
	}
}
int main()
{
	n=read(),m=read();
	for(int i=1;i<=m;++i)
	{
		int u=read(),v=read();
		ll w=read();
		add_edge(u,v,w<<1);
		add_edge(v,u,w<<1);
	}
	for(int i=1;i<=n;++i)
	{
		ll x=read();
		add_edge(0,i,x);
	}
	dijkstra(0);
	for(int i=1;i<=n;++i) printf("%lld ",dis[i]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define ll long long

const int maxn=400005;

ll nex[maxn],pre[maxn],to[maxn],dis[maxn],vis[maxn],w[maxn];
ll cnt,ans=2e9,ti;
queue<int>q;

void add(int x,int y,int z){
    to[++cnt]=y;
    pre[cnt]=nex[x];
    nex[x]=cnt;
    w[cnt]=z;
}
void SPFA(){
    memset(vis,0,sizeof(vis));
    q.push(0);vis[0]=1;
    dis[0]=0;
    while(!q.empty()){
        int cur=q.front();q.pop();
        vis[cur]=0;
        for(int i=nex[cur];i;i=pre[i]){
            if(dis[to[i]]>dis[cur]+w[i]){
                dis[to[i]]=dis[cur]+w[i];
                if(!vis[to[i]]){
                    q.push(to[i]);
                    vis[to[i]]=1;
                }
            }
        }
    }
}
int main(){
    int n,m;
    ll u,v,_w;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%lld%lld%lld",&u,&v,&_w);
        add(u,v,_w*2);add(v,u,_w*2);
    }
	memset(dis,0x3f3f3f3f,sizeof(dis));
    for(int i=1;i<=n;i++)
        scanf("%lld",&ti),add(0,i,ti),add(i,0,ti);
    SPFA();
    for(int i=1;i<=n;i++)printf("%lld ",dis[i]);
    return 0;
}


#include<queue>
#include<cstdio>
#include<iostream>
using namespace std;
struct cc{
    long long to,w,nex;
}e[400010];
long long head[400010],cnt;
long long n,m,s,num[400010];
bool vis[400010];
void add(int x,int y,int z)
{
    cnt++;
    e[cnt].to=y;
    e[cnt].w=z;
    e[cnt].nex=head[x];
    head[x]=cnt;
}
struct node{
    long long u,d;
    bool operator <(const node &h)const{
        return d>h.d;
    }
};
void DJ()
{

    priority_queue<node> q;
    for(int i=1;i<=n;i++)
    q.push((node){i,num[i]});
    while(!q.empty())
    {
        long long u=q.top().u,d=q.top().d;
        q.pop();
        if(vis[u]) continue;
        if(d!=num[u]) continue;
        for(int i=head[u];i;i=e[i].nex)
        {
            long long  v=e[i].to;

            if(num[v]>num[u]+e[i].w)
            {
                num[v]=num[u]+e[i].w;
                q.push((node){v,num[v]});
            }
        }
    }
}
int main()
{
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=m;i++)
    {
        long long a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        add(a,b,c*2);
        add(b,a,c*2);
    }
    for(int i=1;i<=n;i++)
        scanf("%lld",&num[i]);
    DJ();
    for(int i=1;i<=n;i++)
    	printf("%lld ",num[i]);
    return 0;
}


#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 1000050
#define ll long long
#define P(a,b) make_pair(a,b)
using namespace std;

ll head[inf<<1],dis[inf],vis[inf],va[inf],now,tot,n,m;

struct star{
	ll to,next,size;
}stars[inf<<1];

priority_queue< pair<ll,ll> > q;

void star_add(ll a,ll b,ll c)
{
	stars[++tot].next=head[a];
	stars[tot].to=b;
	stars[tot].size=c;
	head[a]=tot;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(ll i=1;i<=m;i++)
	{
		ll a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		star_add(a,b,2*c);
		star_add(b,a,2*c);
	}
	for(ll i=1;i<=n;i++)
	{
		scanf("%d",&va[i]);
		q.push( P(-va[i],i) );
		dis[i]=va[i];
	}
	while(!q.empty())
	{
		now=q.top().second;q.pop();
		if(vis[now])	continue;
		vis[now]=1;
		for(ll i=head[now];i;i=stars[i].next)
		{
			ll v=stars[i].to,cost=stars[i].size;
			if(dis[v]>dis[now]+cost)
			{
				dis[v]=dis[now]+cost;
				q.push( P(-dis[v],v) );
			}
		}
	}
	for(ll i=1;i<=n;i++)
		printf("%d ",dis[i]);
	return 0;
}


#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
queue<int> q;
vector<int> v[200005];
long long dis[500001],n,m,st;
bool in_queue[1000001];
int spfa()
{
	q.push(st);
	in_queue[st]=1;
	dis[st]=0;
	while(q.size())
	{
		int now=q.front();
	    q.pop();
	    in_queue[now]=0;
	    for(int i=0;i<v[now].size();i+=2)
	    {
	    	int y=v[now][i];
	    	int z=v[now][i+1];
	    	if(dis[y]>dis[now]+z)
	    	{
	    		dis[y]=dis[now]+z;
	    		if(in_queue[y]==0)
	    		{
	    			q.push(y);
	    			in_queue[y]=1;
				}
			}
		}
	}
}
int main()
{
   scanf("%d%d",&n,&m);
   for(int i=1;i<=n;i++)
   {
   	   dis[i]=1e9;
   }
   for(int i=1;i<=m;i++)
   {
   	   int x,y,z;
   	   scanf("%d%d%d",&x,&y,&z);
   	   v[x].push_back(y);
   	   v[x].push_back(z*2);
   	   v[y].push_back(x);
   	   v[y].push_back(z*2);
   }
   for(int i=1;i<=n;i++)
   {
   	 long long ad;
   	 scanf("%lld",&ad);
   	 v[0].push_back(i);
   	 v[0].push_back(ad);
   }
    st=0;
   spfa();
   for(int i=1;i<=n;i++)
   {
   	    if(dis[i]==0&&i!=st||dis[i]==1000000000)
   	    {
   	    	printf("2147483647 ");
   	    }
   	    else
   	    {
   	    	printf("%d ",dis[i]);
   	    }
   }

   return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define MAXN 210000+10
#define MAXM 800000+10
#define ll unsigned long long
#define INF 127
using namespace std;
ll read(){
	ll out=0;
	char c=getchar();
	while(c<48||c>57) c=getchar();
	while(c<=57&&c>=48){
		out=(out<<1)+(out<<3)+c-48;
		c=getchar();
	}
	return out;
}
void write(ll x){
	if(x>9) write(x/10);
	putchar(x%10+48);
}
int n,m,cnt;
int head[MAXN];
ll dis[MAXN];
struct Edge{int v,next;ll w;}edge[MAXM];
inline void addedge(int u,int v,ll w){
	edge[++cnt].v=v;
	edge[cnt].w=w;
	edge[cnt].next=head[u];
	head[u]=cnt;
}
void init(){
	memset(head,-1,sizeof(head));
	n=read();
	m=read();
	for(int i=1;i<=m;++i){
		int u=read();
		int v=read();
		ll w=read();
		addedge(u,v,w<<1);
		addedge(v,u,w<<1);
	}
	for(int i=1;i<=n;++i){
		ll w=read();
		addedge(0,i,w);
	}
}
struct Node{
	int id;ll d;
	bool operator<(const Node a)const{
		return d>a.d;
	}
};
void dij(){
	priority_queue<Node>q;
	memset(dis,INF,sizeof(dis));
	q.push(Node{0,0});
	dis[0]=0;
	while(!q.empty()){
		Node temp=q.top();
		q.pop();
		int u=temp.id;
		int d=temp.d;
		if(d!=dis[u]) continue;
		for(int i=head[u];~i;i=edge[i].next){
			int v=edge[i].v,w=edge[i].w;
			if(dis[v]>dis[u]+w){
				dis[v]=dis[u]+w;
				q.push(Node{v,dis[v]});
			}
		}
	}
}
int main(){
	init();
	dij();
	for(int i=1;i<=n;++i){
		write(dis[i]);
		putchar(32);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int MAXN = 100010 ;
int N ;
int a[MAXN] ;
int s[MAXN] ;
bool visit[1000100] ;

int main()
{
      memset(visit,false,sizeof(visit));
      scanf("%d",&N);
      for (int i=1;i<=N;i++)
            scanf("%d",&a[i]);
      s[N+1]=0;
      for (int i=N;i>=1;i--)
            s[i] = s[i+1] | a[i];
      int ans=0;

      for (int i=1;i<=N;i++){
            int now = 0  ;
            for (int k=i;k<=N;k++){
                  now |= a[k];
                  if (!visit[now]){
                        ans++;
                        visit[now]=1;
                  }
                  if (now >= s[i]) break;
            }
      }
      printf("%d\n",ans);
      return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int MAXN = 100010 ;
int N ;
int a[MAXN] ;
int s[MAXN] ;
bool visit[2000100] ;

int main()
{
      memset(visit,false,sizeof(visit));
      scanf("%d",&N);
      for (int i=1;i<=N;i++)
            scanf("%d",&a[i]);
      s[N+1]=0;
      for (int i=N;i>=1;i--)
            s[i] = s[i+1] | a[i];
      int ans=0;
      a[0]=-1;
      for (int i=1;i<=N;i++){
            if (a[i]==0){
                  ans++;
                  continue ;
            }
            int now = 0  ;
            for (int k=i;k<=N;k++){
                  if (now == a[k]) break ;
                  now |= a[k];
                  if (!visit[now]){
                        ans++;
                        visit[now]=1;
                  }
                  if (now >= s[i]) break;
            }
      }
      printf("%d\n",ans);
      return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int MAXN = 2000010 ;
int N ;
int a[MAXN] ;

int cur ;
int cnt[2];
int q[MAXN][2] ;
int visit[MAXN] ;
int ans ;

int main(){
      scanf("%d",&N);
      cur = 0 ;
      memset(visit , 0 , sizeof(visit));
      cnt[cur]=1 ; q[1][cur]=0; ans = 0;
      for (int i = 1 ; i <= N ; i++)
      {
            scanf("%d" , &a[i]);
            cur ^= 1 ; cnt[cur] = 1 ;
            for (int j = 1 ; j <= cnt[1-cur] ; j++){
                  int temp = (q[j][1-cur]|a[i]);
                  if (visit[temp]!=i){
                        if (visit[temp]==0) ans++ ;
                        visit[temp] = i ;
                        q[++cnt[cur]][cur] = temp ;
                  }
            }
      }
      printf("%d\n",ans);
      return 0 ;
}


#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int MAXN = 100010 ;
int N ;
int a[MAXN] ;
int s[MAXN] ;
bool visit[2000100] ;

int main()
{
      memset(visit,false,sizeof(visit));
      scanf("%d",&N);
      for (int i=1;i<=N;i++)
            scanf("%d",&a[i]);
      s[N+1]=0;
      for (int i=N;i>=1;i--)
            s[i] = s[i+1] | a[i];
      int ans=0;
      for (int i=1;i<=N;i++){
            int now=a[i];
            if (!visit[now]){
                  ans++;
                  visit[now]=1;
            }
            for (int k=i+1;k<=N;k++){
                  if ((now|a[k])==a[k]) break ;
                  now |= a[k];
                  if (!visit[now]){
                        ans++;
                        visit[now]=1;
                  }
                  if (now >= s[i]) break;
            }
      }
      printf("%d\n",ans);
      return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
using namespace std;

bool vis[1<<20];
int suffix[2][21],cnt[2];

bool exist(int b,int tmp){
	for (int i=0;i<cnt[tmp];i++)
		if (suffix[tmp][i]==b) return true;
	return false;
}

int main(){
	int n,a,tmp=0,ans=0;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		cnt[tmp]=0;
		suffix[tmp][cnt[tmp]++]=a;
		if (!vis[a]) vis[a]=true,ans++;
		for (int j=0;j<cnt[tmp^1];j++){
			int b=(a|suffix[tmp^1][j]);
			if (!exist(b,tmp)){
				suffix[tmp][cnt[tmp]++]=b;
				if (!vis[b]) vis[b]=true,ans++;
			}
		}
		tmp^=1;
	}
	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
using namespace std;

bool vis[2000005];
int suffix[2][2050],cnt[2];

bool exist(int b,int tmp){
	for (int i=0;i<cnt[tmp];i++)
		if (suffix[tmp][i]==b) return true;
	return false;
}

int main(){
	int n,a,tmp=0;
	scanf("%d",&n);
	for (int i=1;i<=n;i++,tmp^=1){
		scanf("%d",&a);
		cnt[tmp]=0;
		suffix[tmp][cnt[tmp]++]=a;
		vis[a]=true;
		for (int j=0;j<cnt[tmp^1];j++){
			int b=(a|suffix[tmp^1][j]);
			if (!exist(b,tmp)){
				suffix[tmp][cnt[tmp]++]=b;
				vis[b]=true;
			}
		}
	}
	int ans=0;
	for (int i=0;i<=1000000;i++)
		if (vis[i]) ans++;
	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define eps 1e-8

int vis[1000005];
int suffix[2][205],cnt[2];

bool exist(int b,int tmp){
	for (int i=0;i<cnt[tmp];i++)
		if (suffix[tmp][i]==b) return true;
	return false;
}

int main(){
	int n,a,tmp=0;
	scanf("%d",&n);
	for (int i=1;i<=n;i++,tmp^=1){
		scanf("%d",&a);
		suffix[tmp][cnt[tmp]++]=a;
		vis[a]=1;
		for (int j=0;j<cnt[tmp^1];j++){
			int b=(a|suffix[tmp^1][j]);
			if (!exist(b,tmp)){
				suffix[tmp][cnt[tmp]++]=b;
				vis[b]=1;
			}
		}
		cnt[tmp^1]=0;
	}
	int ans=0;
	for (int i=0;i<=1000000;i++)
		if (vis[i]) ans++;
	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
using namespace std;

int vis[1000005];
int suffix[2][205],cnt[2];

bool exist(int b,int tmp){
	for (int i=0;i<cnt[tmp];i++)
		if (suffix[tmp][i]==b) return true;
	return false;
}

int main(){
	memset(vis,0,sizeof(vis));
	memset(suffix,0,sizeof(suffix));
	memset(cnt,0,sizeof(cnt));
	int n,a,tmp=0;
	scanf("%d",&n);
	for (int i=1;i<=n;i++,tmp^=1){
		scanf("%d",&a);
		cnt[tmp]=0;
		suffix[tmp][cnt[tmp]++]=a;
		vis[a]=1;
		for (int j=0;j<cnt[tmp^1];j++){
			int b=(a|suffix[tmp^1][j]);
			if (!exist(b,tmp)){
				suffix[tmp][cnt[tmp]++]=b;
				vis[b]=1;
			}
		}
	}
	int ans=0;
	for (int i=0;i<=1000000;i++)
		if (vis[i]) ans++;
	printf("%d\n",ans);
	return 0;
}


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <stack>
using namespace std;

typedef long long int int64;

#define EPS 10e-9
#define INF 0x3f3f3f3f
#define REP(i,n) for(int i=0; i<(n); i++)

int n;
vector<int> v;
bool used[1048586];

int main()
{
	scanf("%d", &n);
	v.clear();
	int ant = -1;
	REP(i, n) {
		int x;
		scanf("%d", &x);
		if (x == ant) continue;
		v.push_back(x);
		ant = x;
	}
	memset(used, false, sizeof(used));
	for (int j = 0; j < (int) v.size(); j++) {
		int x = 0;
		for (int i = 0; i <= 20; i++) {
			if (j+i >= v.size()) break;
			x = x | v[j+i];
			used[x] = true;
		}
	}
	int64 res = 0;
	for (int i = 0; i <= 1048576; i++) {
		if (used[i]) res++;
	}
	//printf("%lld\n", res);
	cout << res << endl;
	return 0;
}