#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, K = 500 + 5, INF = 1e9;
int k, type[N], d[K][K], markt[K];
bool mark[N];
vector<int> G[N];
void FloydWarshall() {
  for (int x = 0; x < k; x++)
    for (int i = 0; i < k; i++)
      for (int j = 0; j < k; j++)
        if (d[i][x] != INF && d[x][j] != INF)
          d[i][j] = min(d[i][x] + d[x][j], d[i][j]);
}
void DFS(int r, int cnt) {
  mark[r] = true;
  markt[type[r]] = cnt;
  for (int v : G[r])
    if (!mark[v] && (markt[type[v]] == cnt || mark[type[v]] == 0)) DFS(v, cnt);
}
int main() {
  int n, m;
  cin >> n >> m >> k;
  for (int i = 0, j = 0; i < k; i++) {
    int c;
    cin >> c;
    while (c--) type[j++] = i;
  }
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++)
      if (i != j)
        d[i][j] = INF;
      else
        d[i][j] = 0;
  while (m--) {
    int u, v, x, p, q;
    cin >> u >> v >> x;
    u--, v--;
    p = type[u], q = type[v];
    d[p][q] = d[q][p] = min(x, d[p][q]);
    if (x == 0) {
      G[u].push_back(v);
      G[v].push_back(u);
    }
  }
  for (int i = 0, j = 1; i < n; i++)
    if (!mark[i])
      if (!markt[type[i]])
        DFS(i, j++);
      else {
        cout << "No\n";
        return 0;
      }
  cout << "Yes\n";
  FloydWarshall();
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < k; j++)
      if (d[i][j] == INF)
        cout << -1 << ' ';
      else
        cout << d[i][j] << ' ';
    cout << '\n';
  }
  return 0;
}
