#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x) {
  short f = 1;
  char ch = getchar();
  x = 0;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x *= f;
}
long long head[1000010], ver[1000010], Next[1000010], edge[1000010], tot;
void add(long long x, long long y, long long z) {
  ver[++tot] = y;
  Next[tot] = head[x];
  head[x] = tot;
  edge[tot] = z;
}
long long n, m;
long long x, y, z;
long long d[1000010];
bool v[1000010];
priority_queue<pair<long long, long long> > q;
void DJ(long long x) {
  memset(v, 0, sizeof v);
  memset(d, 0x3f, sizeof d);
  d[x] = 0;
  q.push(make_pair(0, x));
  while (!q.empty()) {
    x = q.top().second, q.pop();
    if (v[x]) continue;
    v[x] = 1;
    for (long long i = head[x]; i; i = Next[i]) {
      long long y = ver[i], z = edge[i];
      if (d[y] > d[x] + z) {
        d[y] = d[x] + z;
        q.push(make_pair(-d[y], y));
      }
    }
  }
}
signed main() {
  read(n), read(m);
  while (m--) {
    read(x), read(y), read(z);
    z <<= 1ll;
    add(x, y, z), add(y, x, z);
  }
  for (long long i = 1; i <= n; i++) {
    read(x);
    add(0, i, x);
  }
  DJ(0);
  for (long long i = 1; i <= n; i++) printf("%lld ", d[i]);
}
