#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, K = 505, INF = K * (1e4 + 5);
int n, m, k;
int c[N], a[N], visit[N];
int w[K][K];
vector<pair<int, int>> edges[N];
vector<int> colors;
void dfs(int s) {
  visit[s] = 1;
  colors.push_back(a[s]);
  for (auto x : edges[s]) {
    int nxt = x.first;
    int w = x.second;
    if (visit[nxt] || w) continue;
    dfs(nxt);
  }
}
vector<vector<int>> ffloyd(int M) {
  vector<vector<int>> dist(M, vector<int>(M, INF));
  for (int i = 0; i < M; i++)
    for (int j = 0; j < M; j++) dist[i][j] = w[i][j];
  for (int k = 0; k < M; k++) {
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < M; j++) {
        if (dist[i][k] < INF && dist[k][j] < INF)
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  return dist;
}
void solve() {
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) cin >> c[i];
  int col = 0;
  for (int i = 0, id = 0; i < k; i++) {
    for (int j = 0; j < c[i]; j++) a[id++] = col;
    col++;
  }
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++)
      if (i != j) w[i][j] = INF;
  while (m--) {
    int u, v, x;
    cin >> u >> v >> x;
    u--;
    v--;
    edges[u].push_back({v, x});
    edges[v].push_back({u, x});
    u = a[u], v = a[v];
    if (u == v) continue;
    w[u][v] = min(w[u][v], x);
    w[v][u] = min(w[v][u], x);
  }
  int fail = 0;
  for (int i = 0; i < n; i++) {
    if (!visit[i]) {
      dfs(i);
      sort(colors.begin(), colors.end());
      int count = 1;
      for (int i = 1; i < colors.size(); i++) {
        if (colors[i] == colors[i - 1]) {
          count++;
          continue;
        }
        if (c[colors[i - 1]] != count) {
          fail = 1;
          break;
        }
        count = 1;
      }
      if (c[colors.back()] != count) {
        fail = 1;
        break;
      }
      colors.clear();
    }
  }
  if (fail) {
    cout << "No\n";
    return;
  }
  cout << "Yes\n";
  vector<vector<int>> dist = ffloyd(k);
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < k; j++) {
      if (dist[i][j] == INF) dist[i][j] = -1;
      cout << dist[i][j] << " ";
    }
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
