#include <bits/stdc++.h>
using namespace std;
typedef struct A {
  int y, z;
  A() {}
  A(int _y, int _z) { y = _y, z = _z; }
} AA;
vector<AA> v[100005];
vector<int> st;
const int MAX = 1000000009;
int d[505][505], tp[100005], c[505], N, M, K, cc, L, R;
int vis[100005], id;
void dfs(int x) {
  if (x >= L && x <= R) {
    cc++;
  }
  vis[x] = id;
  for (int i = 0; i < v[x].size(); i++) {
    int y = v[x][i].y;
    if (vis[y] != id) dfs(y);
  }
}
int main() {
  for (; scanf(" %d %d %d", &N, &M, &K) == 3;) {
    for (int i = 0; i <= K; i++)
      for (int j = 0; j <= K; j++) d[i][j] = MAX;
    int now = 0;
    st.clear();
    for (int i = 0; i < K; i++) {
      scanf(" %d", &c[i]);
      st.push_back(now);
      for (int j = 0; j < c[i]; j++) tp[now++] = i;
    }
    for (int i = 0; i <= N; i++) v[i].clear(), vis[i] = -1;
    for (int i = 0, x, y, z; i < M && scanf(" %d %d %d", &x, &y, &z) == 3;
         i++) {
      if (z == 0) {
        v[x - 1].push_back(AA(y - 1, z));
        v[y - 1].push_back(AA(x - 1, z));
      }
      if (tp[x - 1] != tp[y - 1]) {
        d[tp[x - 1]][tp[y - 1]] = min(d[tp[x - 1]][tp[y - 1]], z);
        d[tp[y - 1]][tp[x - 1]] = min(d[tp[y - 1]][tp[x - 1]], z);
      }
    }
    int re = 1;
    for (int i = 0; i < st.size() && re == 1; i++) {
      cc = 0;
      L = st[i], R = st[i] + c[i] - 1;
      id = i;
      dfs(st[i]);
      if (cc != c[i]) re = 0;
    }
    if (re == 0) {
      printf("No\n");
      continue;
    }
    printf("Yes\n");
    for (int k = 0; k < K; k++)
      for (int i = 0; i < K; i++)
        for (int j = 0; j < K; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    for (int i = 0; i < K; i++) {
      for (int j = 0; j < K; j++) {
        if (d[i][j] == MAX) d[i][j] = -1;
        if (i == j) d[i][j] = 0;
        if (j == 0)
          printf("%d", d[i][j]);
        else
          printf(" %d", d[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}
