#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, y, z;
int p[100010], G[505][505], v[100010];
int fnd(int x) {
  if (p[x] != x) return p[x] = fnd(p[x]);
  return p[x];
}
void un(int x, int y) { p[fnd(x)] = fnd(y); }
int main() {
  cin >> n >> m >> k;
  int cnt = 0;
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++) G[i][j] = 100010;
  for (int i = 0; i < k; i++) {
    cin >> x;
    for (int j = 0; j < x; j++) v[cnt++] = i;
  }
  for (int i = 0; i < n; i++) p[i] = i;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    x--;
    y--;
    if (!z) un(x, y);
    G[v[x]][v[y]] = min(z, G[v[x]][v[y]]);
    G[v[y]][v[x]] = min(z, G[v[y]][v[x]]);
  }
  int i;
  for (i = 1; i < n; i++)
    if (v[i] == v[i - 1] && fnd(i) != fnd(i - 1)) break;
  if (i < n)
    cout << "No\n";
  else {
    for (i = 0; i < k; i++) G[i][i] = 0;
    int j, l;
    cout << "Yes\n";
    for (l = 0; l < k; l++)
      for (i = 0; i < k; i++)
        for (j = 0; j < k; j++) G[i][j] = min(G[i][l] + G[l][j], G[i][j]);
    for (i = 0; i < k; i++) {
      for (j = 0; j < k; j++) {
        if (G[i][j] == 100010) G[i][j] = -1;
        cout << G[i][j] << " ";
      }
      cout << "\n";
    }
  }
}
