#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long M = 505;
const long long inf = 1e9;
long long n, m, k, grp = 0;
long long c[M], vis[N], comp[N];
long long d[M][M];
vector<long long> g[N];
long long get(long long x) {
  auto it = lower_bound(c + 1, c + k + 1, x) - c;
  return it;
}
void dfs(long long u) {
  if (vis[u]) return;
  vis[u] = 1;
  comp[u] = grp;
  for (auto &it : g[u]) dfs(it);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m >> k;
  for (long long i = 1; i <= k; i++) {
    cin >> c[i];
    c[i] += c[i - 1];
    for (long long j = 1; j <= k; j++) d[i][j] = inf;
  }
  for (long long i = 1; i <= m; i++) {
    long long u, v, x;
    cin >> u >> v >> x;
    long long uu = get(u);
    long long vv = get(v);
    d[uu][vv] = min(d[uu][vv], x);
    d[vv][uu] = min(d[vv][uu], x);
    if (x == 0) {
      g[u].push_back(v);
      g[v].push_back(u);
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i);
      grp++;
    }
  }
  bool check = 1;
  for (long long i = 1; i <= k; i++) {
    d[i][i] = 0;
    long long val = -1;
    for (long long j = c[i - 1] + 1; j <= c[i]; j++) {
      if (val == -1)
        val = comp[j];
      else {
        if (val != comp[j]) {
          check = 0;
          break;
        }
      }
    }
  }
  if (!check) {
    cout << "No";
    return 0;
  }
  cout << "Yes"
       << "\n";
  for (long long mid = 1; mid <= k; mid++) {
    for (long long i = 1; i <= k; i++) {
      for (long long j = 1; j <= k; j++) {
        if (d[i][j] > d[i][mid] + d[mid][j])
          d[i][j] = min(d[i][j], d[i][mid] + d[mid][j]);
      }
    }
  }
  for (long long i = 1; i <= k; i++) {
    for (long long j = 1; j <= k; j++) {
      if (d[i][j] >= inf) d[i][j] = -1;
      cout << d[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
