#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000LL;
const double EPS = 1e-9;
const long long mod = 1000000007ll;
const int maxn = (int)100500 + 10;
int di[505][505];
int c[505], p[maxn];
int pa[maxn];
int par(int x) { return (x == pa[x]) ? x : pa[x] = par(pa[x]); }
int main() {
  int n, m, k;
  scanf("%d%d", &n, &m), scanf("%d", &k);
  int la = 1;
  for (int i = 0; i < (int)(k); ++i) {
    scanf("%d", &c[i]);
    for (int j = la; j < la + c[i]; j++) p[j] = i;
    la = la + c[i];
  }
  memset(di, 63, sizeof(di));
  for (int i = 0; i < (int)(n + 5); ++i) pa[i] = i;
  int u, v, cost;
  for (int i = 0; i < (int)(m); ++i) {
    scanf("%d%d", &u, &v), scanf("%d", &cost);
    {
      int tu = p[u];
      int tv = p[v];
      di[tu][tv] = di[tv][tu] = min(di[tu][tv], cost);
    }
    if (cost == 0) {
      u = par(u);
      v = par(v);
      if (u != v) {
        pa[u] = v;
      }
    }
  }
  la = 1;
  bool f = true;
  for (int i = 0; i < (int)(k); ++i) {
    if (c[i] > 1) {
      int sp = par(la);
      for (int j = la + 1; j < la + c[i]; j++)
        if (sp != par(j)) f = false;
    }
    la = la + c[i];
  }
  if (!f) {
    puts("No");
    return 0;
  }
  for (int o = 0; o < (int)(k); ++o)
    for (int i = 0; i < (int)(k); ++i)
      for (int j = 0; j < (int)(k); ++j)
        di[i][j] = min(di[i][j], di[i][o] + di[o][j]);
  puts("Yes");
  for (int i = 0; i < (int)(k); ++i) {
    for (int j = 0; j < (int)(k); ++j) {
      if (i == j) di[i][j] = 0;
      if (di[i][j] == 1061109567) di[i][j] = -1;
      printf("%d ", di[i][j]);
    }
    puts("");
  }
}
