#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int n1, n2, n3;
int c[510];
int sc[510];
int pai[100010];
int type[100010];
int peso[100010];
int dp[510][510];
vector<pair<pair<int, int>, int> > edges;
int find(int i) { return pai[i] = (pai[i] == i) ? i : find(pai[i]); }
void join(int i, int j) {
  i = find(i);
  j = find(j);
  if (i == j) return;
  if (peso[i] < peso[j]) swap(i, j);
  pai[j] = i;
  if (peso[i] == peso[j]) peso[i]++;
}
void init() {
  for (int g = 1; g <= n; g++) {
    pai[g] = g;
    peso[g] = 0;
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  init();
  for (int g = 1; g <= k; g++) {
    scanf("%d", &c[g]);
    sc[g] = sc[g - 1] + c[g];
  }
  for (int g = 0; g < m; g++) {
    scanf("%d %d %d", &n1, &n2, &n3);
    edges.push_back(make_pair(make_pair(n1, n2), n3));
    if (n3 == 0) join(n1, n2);
  }
  for (int g = 1; g <= k; g++)
    for (int h = sc[g - 1] + 1; h <= sc[g]; h++) type[h] = g;
  bool error = false;
  for (int g = 1; g < n; g++)
    if (type[g] == type[g + 1] && find(g) != find(g + 1)) error = true;
  if (error) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  for (int g = 1; g <= k; g++)
    for (int h = 1; h <= k; h++) dp[g][h] = 1000000010;
  for (int g = 1; g <= k; g++) dp[g][g] = 0;
  for (int g = 0; g < m; g++) {
    int i = edges[g].first.first;
    int j = edges[g].first.second;
    int w = edges[g].second;
    i = type[i];
    j = type[j];
    if (i != j) dp[i][j] = dp[j][i] = min(dp[i][j], w);
  }
  for (int p = 1; p <= k; p++)
    for (int q = 1; q <= k; q++)
      for (int r = 1; r <= k; r++)
        dp[q][r] = min(dp[q][r], dp[q][p] + dp[p][r]);
  for (int q = 1; q <= k; q++) {
    for (int p = 1; p <= k; p++)
      printf("%d ", (dp[p][q] == 1000000010) ? -1 : dp[p][q]);
    printf("\n");
  }
}
