#include <bits/stdc++.h>
using namespace std;
const long long inf = 9223372036854775807;
vector<vector<pair<int, long long>>> gr;
vector<long long> d;
int n;
void Dijkstra() {
  d.resize(n);
  priority_queue<pair<long long, int>> q;
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
    q.push(make_pair(d[i], i));
  }
  while (!q.empty()) {
    int v = q.top().second;
    long long ok = -q.top().first;
    q.pop();
    if (ok > d[v]) {
      continue;
    }
    for (int j = 0; j < gr[v].size(); ++j) {
      int to = gr[v][j].first;
      long long len = gr[v][j].second;
      if (d[v] + len < d[to]) {
        d[to] = d[v] + len;
        q.push(make_pair(-d[to], to));
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << d[i] << ' ';
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int m;
  cin >> n >> m;
  gr.resize(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    long long a;
    cin >> u >> v >> a;
    gr[u - 1].push_back(make_pair(v - 1, 2 * a));
    gr[v - 1].push_back(make_pair(u - 1, 2 * a));
  }
  Dijkstra();
  return 0;
}
