#include <bits/stdc++.h>
using namespace std;
queue<int> que;
vector<int> edge[200000];
const int oo = 1000000001;
int tim = 0, vis[200000], n, m, k, d[1000][1000], group[200000], father[1000];
void bfs(int pos) {
  vis[pos] = ++tim;
  que.push(pos);
  while (!que.empty()) {
    int cur = que.front();
    que.pop();
    for (int i = 0; i < edge[cur].size(); i++)
      if (!vis[edge[cur][i]]) {
        vis[edge[cur][i]] = tim;
        que.push(edge[cur][i]);
      }
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= k; j++)
      if (i != j) d[i][j] = oo;
  int num = 1, c, u, v, x;
  for (int i = 1; i <= k; i++) {
    cin >> c;
    father[i] = num;
    for (int j = num; j < num + c; j++) group[j] = i;
    num += c;
  }
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> x;
    d[group[u]][group[v]] = d[group[v]][group[u]] =
        min(d[group[u]][group[v]], x);
    if (!x) {
      edge[u].push_back(v);
      edge[v].push_back(u);
    }
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) bfs(i);
  for (int i = 1; i <= n; i++)
    if (vis[i] != vis[father[group[i]]]) {
      cout << "No" << endl;
      return 0;
    }
  cout << "Yes" << endl;
  for (int l = 1; l <= k; l++)
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) d[i][j] = min(d[i][j], d[i][l] + d[l][j]);
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++)
      if (d[i][j] == oo)
        cout << -1 << " ";
      else
        cout << d[i][j] << " ";
    cout << endl;
  }
  return 0;
}
