#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int MAXN = 100010;
int fa[MAXN], c[600], sum[600];
int a[550][550];
int p[MAXN];
int u[MAXN], v[MAXN], w[MAXN];
int ufa, vfa;
int getfather(int x) { return x == fa[x] ? x : fa[x] = getfather(fa[x]); }
int main() {
  int n, m, k;
  while (cin >> n >> m >> k) {
    for (int i = (1); i <= (k); i++) {
      scanf("%d", &c[i]);
      sum[i] = sum[i - 1] + c[i];
    }
    for (int i = (1); i <= (n); i++) fa[i] = i;
    for (int i = (1); i <= (m); i++) {
      scanf("%d%d%d", &u[i], &v[i], &w[i]);
      if (w[i] == 0) {
        ufa = getfather(u[i]);
        vfa = getfather(v[i]);
        fa[ufa] = vfa;
      }
    }
    bool yes = true;
    for (int i = (1); i <= (k); i++) {
      ufa = getfather(sum[i - 1] + 1);
      for (int j = (sum[i - 1] + 2); j <= (sum[i]); j++) {
        vfa = getfather(j);
        if (ufa != vfa) {
          yes = false;
          break;
        }
      }
    }
    if (!yes) {
      printf("No\n");
      continue;
    } else {
      printf("Yes\n");
      for (int i = (1); i <= (k); i++) {
        for (int j = (sum[i - 1] + 1); j <= (sum[i]); j++) p[j] = i;
        for (int j = (i + 1); j <= (k); j++) a[i][j] = a[j][i] = -1;
      }
      for (int i = (1); i <= (m); i++) {
        ufa = u[i];
        vfa = v[i];
        if (a[p[ufa]][p[vfa]] == -1)
          a[p[ufa]][p[vfa]] = a[p[vfa]][p[ufa]] = w[i];
        else {
          if (w[i] < a[p[ufa]][p[vfa]])
            a[p[ufa]][p[vfa]] = a[p[vfa]][p[ufa]] = w[i];
        }
      }
      for (int t = (1); t <= (k); t++)
        for (int i = (1); i <= (k); i++)
          for (int j = (1); j <= (k); j++) {
            if (a[i][t] != -1 && a[t][j] != -1)
              if (a[i][j] == -1 || a[i][j] > a[i][t] + a[t][j]) {
                a[i][j] = a[i][t] + a[t][j];
              }
          }
      for (int i = (1); i <= (k); i++) {
        printf("%d", a[i][1]);
        for (int j = (2); j <= (k); j++) {
          printf(" %d", a[i][j]);
        }
        puts("");
      }
    }
  }
  return 0;
}
