#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const int MOD = 1000000000 + 7;
const int INF = 1000000000;
int n, m, k;
int num[N];
int a[505][505];
int father[N];
int getf(int u) { return u == father[u] ? u : father[u] = getf(father[u]); }
void solve() {
  cin >> n >> m >> k;
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < k; ++j) {
      a[i][j] = INF;
    }
  }
  int sum = 0, tot;
  for (int i = 0; i < k; ++i) {
    scanf("%d", &tot);
    for (int j = sum; j < sum + tot; ++j) {
      num[j] = i;
    }
    sum += tot;
  }
  for (int i = 0; i < n; ++i) {
    father[i] = i;
  }
  int u, v, w;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    --u, --v;
    a[num[u]][num[v]] = min(a[num[u]][num[v]], w);
    a[num[v]][num[u]] = a[num[u]][num[v]];
    if (w == 0) {
      u = getf(u);
      v = getf(v);
      if (u != v) {
        father[u] = v;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i && num[i] == num[i - 1] && getf(i) != getf(i - 1)) {
      cout << "No" << endl;
      return;
    }
  }
  for (int kk = 0; kk < k; ++kk) {
    a[kk][kk] = 0;
  }
  for (int kk = 0; kk < k; kk++) {
    for (int i = 0; i < k; ++i) {
      for (int j = 0; j < k; ++j) {
        a[i][j] = min(a[i][j], a[i][kk] + a[kk][j]);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < k; ++j) {
      printf("%d ", a[i][j] >= INF ? -1 : a[i][j]);
    }
    printf("\n");
  }
}
int main() {
  solve();
  return 0;
}
