#include <bits/stdc++.h>
using namespace std;
int parent[100010];
int size[100010];
int d[510][510];
int c[510];
int prefix[510];
int INF = 1e8;
int tc[100010][510];
int k;
bool mark[510];
int find(int node) {
  if (parent[parent[node]] != parent[node]) {
    parent[node] = find(parent[node]);
  }
  return parent[node];
}
void merge(int a, int b) {
  int pa = find(a);
  int pb = find(b);
  if (size[pa] > size[pb]) {
    parent[pb] = pa;
    size[pa] += size[pb];
    for (int m = 1; m <= k; m++) {
      tc[pa][m] += tc[pb][m];
    }
  } else {
    parent[pa] = pb;
    size[pb] += size[pa];
    for (int m = 1; m <= k; m++) {
      tc[pb][m] += tc[pa][m];
    }
  }
}
int type(int node) {
  int lo = 1;
  int hi = k;
  while (hi - lo > 3) {
    int mid = lo + hi;
    mid /= 2;
    if (prefix[mid] == node) {
      return mid;
    } else if (prefix[mid] < node)
      lo = mid + 1;
    else
      hi = mid;
  }
  while (prefix[lo] < node) {
    lo++;
  }
  return lo;
}
int main() {
  int n, m;
  scanf("%d %d %d", &n, &m, &k);
  prefix[0] = 0;
  for (int i = 1; i <= k; i++) {
    scanf("%d", &c[i]);
    mark[i] = false;
    prefix[i] = prefix[i - 1] + c[i];
  }
  for (int i = 1; i <= n; i++) {
    parent[i] = i;
    size[i] = 1;
    tc[i][type(i)] = 1;
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      if (i == j)
        d[i][i] = 0;
      else
        d[i][j] = INF;
    }
  }
  for (int i = 0; i < m; i++) {
    int u, v, x;
    scanf("%d %d %d", &u, &v, &x);
    int ta = type(u);
    int tb = type(v);
    if (x == 0) {
      merge(u, v);
    }
    if (ta != tb) {
      if (x < d[ta][tb]) {
        d[ta][tb] = x;
        d[tb][ta] = x;
      }
    }
  }
  bool flag = true;
  for (int i = 1; i <= n; i++) {
    if (find(i) == i) {
      for (int l = 1; l <= k; l++) {
        if (tc[i][l] == c[l]) mark[l] = true;
      }
    }
  }
  for (int i = 1; i <= k; i++) {
    if (!mark[i]) flag = false;
  }
  if (!flag)
    printf("No\n");
  else {
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int l = 1; l <= k; l++) {
          d[j][l] = min(d[j][l], d[j][i] + d[i][l]);
        }
      }
    }
    printf("Yes\n");
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        if (d[i][j] == INF)
          printf("-1 ");
        else
          printf("%d ", d[i][j]);
      }
      printf("\n");
    }
  }
}
