#include <bits/stdc++.h>
using namespace std;
const long long int oo = 1e16;
long long int n, m, k, u, v, w, c[501], b[501], mat[501][501], p[100007];
long long int gettype(long long int u) {
  long long int x = lower_bound(b + 1, b + k + 1, u) - b;
  return x;
}
int fa(int x) { return p[x] == x ? x : p[x] = fa(p[x]); }
int main() {
  std::cin >> n >> m >> k;
  for (long long int i = 0; i <= k; i++) {
    for (long long int j = 0; j <= k; j++) {
      mat[i][j] = oo;
    }
  }
  for (long long int i = 1; i <= k; i++) {
    std::cin >> c[i];
    b[i] = b[i - 1] + c[i];
  }
  for (int i = 0; i <= n; i++) {
    p[i] = i;
  }
  for (long long int i = 0; i < m; i++) {
    std::cin >> u >> v >> w;
    long long int tv = gettype(v), tu = gettype(u);
    mat[tv][tu] = mat[tu][tv] = min(mat[tu][tv], w);
    if (!w) p[fa(u)] = fa(v);
  }
  for (int i = 1; i <= k; i++) {
    set<int> se;
    for (int j = b[i - 1] + 1; j <= b[i]; j++) {
      se.insert(fa(j));
    }
    if (se.size() > 1) return 0 * printf("No\n");
    mat[i][i] = 0;
  }
  for (long long int p = 1; p <= k; p++) {
    for (long long int i = 1; i <= k; i++) {
      for (long long int j = 1; j <= k; j++) {
        mat[i][j] = min(mat[i][j], mat[i][p] + mat[p][j]);
      }
    }
  }
  printf("Yes\n");
  for (long long int i = 1; i <= k; i++) {
    mat[i][i] = 0;
    for (long long int j = 1; j <= k; j++) {
      if (mat[i][j] >= oo)
        printf("-1 ");
      else
        printf("%lld ", mat[i][j]);
    }
    printf("\n");
  }
}
