#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 5005 + 5;
int a[N];
int dis[N][N];
int f[N * 1000], fa[N * 1000], vis[N], sum[N];
int num[N];
int n, m, k;
int find(int x) { return x == fa[x] ? fa[x] : fa[x] = find(fa[x]); }
bool judge(int l, int r) {
  int x = find(l);
  for (int i = l + 1; i <= r; i++) {
    if (find(i) != x) return false;
  }
  return true;
}
int main() {
  cin >> n >> m >> k;
  int cnt = 0;
  for (int i = 1; i <= k; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
    cnt++;
    for (int j = sum[i - 1] + 1; j <= sum[i]; j++) f[j] = cnt;
    num[cnt] = sum[i] - sum[i - 1];
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  memset(dis, INF, sizeof(dis));
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    dis[f[u]][f[v]] = dis[f[v]][f[u]] = min(dis[f[u]][f[v]], w);
    if (w == 0) {
      u = find(u);
      v = find(v);
      if (u != v) fa[v] = u;
    }
  }
  for (int i = 1; i <= k; i++) {
    if (!judge(sum[i - 1] + 1, sum[i])) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 1; i <= k; i++) dis[i][i] = 0;
  for (int l = 1; l <= k; l++)
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++)
        dis[i][j] = min(dis[i][j], dis[i][l] + dis[l][j]);
  cout << "Yes\n";
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++)
      cout << (dis[i][j] == INF ? -1 : dis[i][j]) << ' ';
    cout << "\n";
  }
  return 0;
}
