#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mid (l + ((r - l) / 2))
#define F first
#define S second
void solve()
{
int64_t n, m, x, y, z, p = 1 ;
cin >> n >> m ;
vector<int64_t> a(n + 1), an(n + 1) ;
for(int64_t i = 1 ; i <= n ; i++) cin >> a[i] ;
vector<vector<pair<int64_t , int64_t>>> adj(n + 1) ;
for(int64_t i = 1 ; i <= m ; i++)
{
cin >> x >> y >> z ;
adj[x].pb({y , z}), adj[y].pb({x , z}) ;
}
vector<bool> vs(n + 1) ;
priority_queue<pair<int64_t , int64_t>> q ;
for(int64_t i = 1 ; i <= n ; i++) if(a[i] > a[p]) p = i ;
for(int64_t i = 1 ; i <= n ; i++) if(a[i] == a[p]) q.push({a[i] , i}) ;
for(int64_t i = 1 ; i <= n ; i++) an[i] = a[i] ;
while(q.size() != 0)
{
x = q.top().S, y = q.top().F, q.pop(), an[x] = max(an[x] , y) ;
//cout << x << " : " << y << " : " << z << " : " << vs[x] << endl;
if(vs[x] == 1) continue ;
vs[x] = 1 ;
for(auto it : adj[x])
{
if(an[x] - it.S > an[it.F])
{
q.push({an[x] - it.S , it.F}) ;
}
}
}
for(int64_t i = 1 ; i <= n ; i++) cout << an[i] << endl;
/*
* 4 5
6 5 9 2
1 2 0
3 2 3
4 3 6
1 3 5
2 4 2
*/
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1 ;
//cin >> tt;
while (tt--) solve() ;
}