#include <bits/stdc++.h>
using namespace std;
int N, K, M, c[500], d[500][500], nodesk[100000], sets[100000];
const int INF = INT_MAX / 2;
int find(int i) {
  if (sets[i] == i) return i;
  return sets[i] = find(sets[i]);
}
void merge(int i, int j) {
  i = find(i);
  j = find(j);
  sets[i] = j;
}
int main() {
  cin >> N >> M >> K;
  int ck = 0;
  for (int i = 0; i < K; ++i) {
    cin >> c[i];
    for (int o = 0; o < c[i]; ++o) {
      nodesk[ck++] = i;
    }
  }
  for (int i = 0; i < K; ++i) {
    for (int j = 0; j < K; ++j) {
      d[i][j] = INF;
    }
    if (c[i] == 1) d[i][i] = 0;
  }
  for (int i = 0; i < N; ++i) {
    sets[i] = i;
  }
  int u, v, x;
  for (int i = 0; i < M; ++i) {
    cin >> u >> v >> x;
    --u;
    --v;
    if (x < d[nodesk[u]][nodesk[v]]) {
      d[nodesk[u]][nodesk[v]] = x;
      d[nodesk[v]][nodesk[u]] = x;
    }
    if (!x) {
      merge(u, v);
    }
  }
  ck = 0;
  for (int i = 0; i < K; ++i) {
    int curset = find(ck);
    for (int o = 0; o < c[i]; ++o, ++ck) {
      if (find(ck) != curset) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  for (int k = 0; k < K; ++k) {
    for (int i = 0; i < K; ++i) {
      for (int j = 0; j < K; ++j) {
        if (d[i][k] + d[k][j] < d[i][j]) {
          d[i][j] = d[i][k] + d[k][j];
        }
      }
    }
  }
  cout << "Yes" << '\n';
  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;
}
