#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10;
int n, m, c;
int h[N], w[N], e[N], ne[N], idx;
int d[N], q[N];
int s[N];
void add(int a, int b, int x)
{
e[idx] = b;
w[idx] = x;
ne[idx] = h[a];
h[a] = idx++;
}
void topsort()
{
int hh = 0, tt = -1;
for (int i = 1; i <= n; i++)
if (!d[i])
q[++tt] = i;
while (hh <= tt)
{
int t = q[hh++];
for (int i = h[t]; i != -1; i = ne[i])
{
int j = e[i];
s[j] = max(s[j], s[t] + w[j]);
if (--d[j] == 0)
q[++tt] = j;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(h, -1, sizeof h);
cin >> n >> m >> c;
for (int i = 1; i <= n; i++)
{
cin >> s[i];
}
for (int i = 1; i <= c; i++)
{
int a, b, x;
cin >> a >> b >> x;
add(a, b, x);
d[b]++;
}
topsort();
for (int i = 1; i <= n; i++)
{
cout << s[i] << endl;
}
return 0;
}