#include <bits/stdc++.h>
using namespace std;
struct comp {
  bool operator()(const pair<int, int> &a, const pair<int, int> &b) {
    return a.second > b.second;
  }
};
vector<int> sum;
priority_queue<pair<int, int>, vector<pair<int, int> >, comp> Q;
vector<pair<int, int> > E[100010];
vector<bool> visited(100010, 0);
vector<int> dist(100010, 1000000010);
int mat[555][555];
bool vis[100010];
vector<int> adj[100010];
set<int> S;
int bs(int key) {
  int len = sum.size(), i, j;
  int l = 0, r = len - 1, ret;
  while (l <= r) {
    int mid = l + (r - l + 1) / 2;
    if (sum[mid] < key) {
      l = mid + 1;
    } else {
      ret = mid;
      r = mid - 1;
    }
  }
  return ret;
}
void dijkstra(int src, int end) {
  dist[src] = 0;
  Q.push(make_pair(src, 0));
  while (!Q.empty()) {
    int u = Q.top().first;
    Q.pop();
    if (visited[u] == 0) {
      int len = E[u].size();
      for (int i = 0; i < len; i++) {
        int v = E[u][i].first;
        int w = E[u][i].second;
        if (v >= src and v <= end) {
          if (dist[u] + w < dist[v] and visited[v] == 0) {
            dist[v] = dist[u] + w;
            Q.push(make_pair(v, dist[v]));
          }
        }
      }
      visited[u] = 1;
    }
  }
}
void dfs(int src) {
  int idx = bs(src);
  S.insert(idx);
  vis[src] = 1;
  int i, j, k, len = adj[src].size();
  for (i = 0; i < len; i++) {
    if (vis[adj[src][i]] == 0) {
      dfs(adj[src][i]);
    }
  }
}
int main() {
  int n, m, k, i, j;
  vector<int> vec;
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &k);
  sum.push_back(0);
  memset(vis, 0, sizeof(vis));
  for (i = 1; i <= k; i++) {
    int temp;
    scanf("%d", &temp);
    sum.push_back(sum[i - 1] + temp);
  }
  while (m--) {
    int u, v, x;
    scanf("%d", &u);
    scanf("%d", &v);
    scanf("%d", &x);
    E[u].push_back(make_pair(v, x));
    E[v].push_back(make_pair(u, x));
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  bool yes = 1;
  for (i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      S.clear();
      dfs(i);
      set<int>::iterator it;
      for (it = S.begin(); it != S.end(); it++) {
        int u = *it;
        for (j = sum[u - 1] + 1; j <= sum[u]; j++) {
          if (vis[j] == 0) {
            yes = 0;
            cout << "No" << endl;
            return 0;
          }
        }
      }
    }
  }
  for (i = 1; i <= k; i++) {
    int start = sum[i - 1] + 1, end = sum[i];
    dijkstra(start, end);
    for (j = start + 1; j <= end; j++) {
      if (dist[j] != 0) {
        vec.push_back(i);
        break;
      }
    }
  }
  for (i = 1; i <= k; i++) {
    for (j = 1; j <= k; j++) {
      if (i == j)
        mat[i][j] = 0;
      else
        mat[i][j] = 1000000010;
    }
  }
  for (i = 1; i <= n; i++) {
    int len = E[i].size();
    int idx1 = bs(i);
    for (j = 0; j < len; j++) {
      int v = E[i][j].first;
      int w = E[i][j].second;
      int idx2 = bs(v);
      if (idx1 != idx2) {
        mat[idx1][idx2] = min(mat[idx1][idx2], w);
      }
    }
  }
  for (int kk = 1; kk <= k; kk++) {
    for (i = 1; i <= k; i++) {
      for (j = 1; j <= k; j++) {
        mat[i][j] = min(mat[i][j], mat[i][kk] + mat[kk][j]);
      }
    }
  }
  int len = vec.size();
  for (i = 0; i < len; i++) {
    int u = vec[i];
    bool flag = 0;
    for (j = 1; j <= k; j++) {
      if (u != j) {
        if (mat[u][j] == 0) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  printf("Yes\n");
  for (i = 1; i <= k; i++) {
    for (j = 1; j <= k; j++) {
      if (mat[i][j] == 1000000010)
        printf("-1 ");
      else
        printf("%d ", mat[i][j]);
    }
    printf("\n");
  }
  return 0;
}
