#include <bits/stdc++.h>
using namespace std;
const int M = 100100;
vector<int> A[M];
int dist[M], visited[M], f[M], Size[M], group[M], D[550][550];
int dfs(int u, int p) {
  int i, v, sum = 0;
  visited[u] = true;
  for (i = 0; i < A[u].size(); i++) {
    v = A[u][i];
    if (!visited[v]) {
      sum += dfs(v, p);
    }
  }
  return sum + (f[u] == f[p]);
}
int main() {
  int i, j, k, n, m, u, v, x;
  scanf("%d%d%d", &n, &m, &k);
  for (i = 1; i <= k; i++) scanf("%d", &group[i]);
  for (i = 2; i <= k; i++) group[i] += group[i - 1];
  group[0] = 0;
  for (i = 1; i <= k; i++)
    for (j = group[i - 1] + 1; j <= group[i]; j++) {
      f[j] = i;
      Size[j] = group[i] - group[i - 1];
    }
  for (i = 0; i < 550; i++) {
    for (j = 0; j < 550; j++) D[i][j] = 111111111;
    D[i][i] = 0;
  }
  while (m--) {
    scanf("%d%d%d", &u, &v, &x);
    if (x == 0) {
      A[u].push_back(v);
      A[v].push_back(u);
    }
    if (f[u] != f[v]) {
      D[f[u]][f[v]] = min(D[f[u]][f[v]], x);
      D[f[v]][f[u]] = min(D[f[v]][f[u]], x);
    }
  }
  memset((visited), (false), sizeof(visited));
  for (i = 1; i <= k; i++) {
    memset((visited), (false), sizeof(visited));
    j = group[i];
    if (dfs(j, j) != Size[j]) {
      printf("%s\n", "No");
      return 0;
    };
  }
  for (m = 1; m <= k; m++)
    for (i = 1; i <= k; i++)
      for (j = 1; j <= k; j++) D[i][j] = min(D[i][j], D[i][m] + D[m][j]);
  printf("Yes\n");
  for (i = 1; i <= k; i++) {
    for (j = 1; j <= k; j++)
      D[i][j] < 111111111 ? printf("%d ", D[i][j]) : printf("%d ", -1);
    printf("\n");
    ;
  }
  return 0;
}
