#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, m, k;
int a[maxn], d[510][510];
int c[maxn];
int ans, ct, cnt, tmp, flag;
char s[maxn];
int fa[maxn];
int find(int x) { return fa[x] == -1 ? x : fa[x] = find(fa[x]); }
void un(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  if (fx != fy) fa[fx] = fy;
}
int main() {
  int T, cas = 1;
  while (scanf("%d%d%d", &n, &m, &k) != EOF) {
    for (int i = 0; i <= n; i++) {
      c[i] = 0;
      fa[i] = -1;
    }
    for (int i = 0; i <= k; i++)
      for (int j = 0; j <= k; j++) d[i][j] = 0x3f3f3f3f;
    int pos = 1;
    for (int i = 1; i <= k; i++) {
      int x;
      scanf("%d", &x);
      for (int j = 0; j < x; j++) {
        c[pos++] = i;
      }
    }
    for (int i = 0; i < m; i++) {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      if (z == 0) un(x, y);
      int xx = c[x], yy = c[y];
      d[xx][yy] = min(d[xx][yy], z);
      d[yy][xx] = min(d[yy][xx], z);
    }
    int ff, fg = 1;
    for (int i = 1; i <= n; i++) {
      if (c[i] != c[i - 1]) ff = find(i);
      if (find(i) != ff) {
        fg = 0;
        break;
      }
    }
    if (!fg) {
      puts("No");
      continue;
    }
    for (int t = 1; t <= k; t++)
      for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++)
          if (d[i][t] < 0x3f3f3f3f && d[t][j] < 0x3f3f3f3f &&
              d[i][j] > d[i][t] + d[t][j])
            d[i][j] = d[i][t] + d[t][j];
    puts("Yes");
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) {
        if (i == j)
          printf("0");
        else if (d[i][j] == 0x3f3f3f3f)
          printf("-1");
        else
          printf("%d", d[i][j]);
        printf("%c", j == k ? '\n' : ' ');
      }
  }
  return 0;
}
