#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int llINF = (long long)(1e18) + 100;
const int MAXN = 100100;
const int MAXM = 1001000;
const long long int mod = 1e9 + 7;
const int LMAXN = 25;
int n, m, k, c[555], type[112345];
int id[112345], sz[112345];
int find(int a) { return a == id[a] ? a : id[a] = find(id[a]); }
void merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) return;
  if (sz[a] < sz[b]) swap(a, b);
  id[b] = a;
  sz[a] += sz[b];
}
vector<pair<int, int> > adj[112345];
vector<pair<int, int> > adj2[555];
int memo[555][555];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) cin >> c[i];
  int cnt = 1;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= c[i]; j++) type[cnt++] = i;
  for (int i = 1; i <= n; i++) id[i] = i, sz[i] = 1;
  int a, b, d;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> d;
    if (d == 0) {
      merge(a, b);
    }
    adj[a].push_back({b, d});
    adj[b].push_back({a, d});
  }
  for (int i = 1; i <= n - 1; i++) {
    if (type[i] == type[i + 1] and find(i) != find(i + 1)) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++)
    for (auto x : adj[i])
      if (type[i] != type[x.first]) {
        adj2[type[i]].push_back({type[x.first], x.second});
      }
  memset(memo, INF, sizeof(memo));
  for (int i = 1; i <= k; i++) memo[i][i] = 0;
  for (int i = 1; i <= k; i++)
    for (auto x : adj2[i]) memo[i][x.first] = min(memo[i][x.first], x.second);
  for (int l = 1; l <= k; l++)
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++)
        memo[i][j] = min(memo[i][j], memo[i][l] + memo[l][j]);
  cout << "Yes" << endl;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++)
      cout << (memo[i][j] == INF ? -1 : memo[i][j]) << ' ';
    cout << endl;
  }
}
