#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  UnionFind(int N) : parent(N) {
    for (int i = 0; i < N; i++) parent[i] = i;
  }
  int root(int x) {
    if (x != parent[x]) parent[x] = root(parent[x]);
    return parent[x];
  }
  void join(int x, int y) { parent[root(x)] = root(y); }
  vector<int> parent;
};
struct Edge {
  string id;
  int u, v, cost;
  Edge(int _v, int _u, int _cost) : v(_v), u(_u), cost(_cost) {}
  bool operator<(const Edge &b) const { return (cost < b.cost); }
};
bool ceroes(vector<vector<int> > &graph) { return false; }
const int INF = 214748364;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> c(k);
  vector<int> type(n + 1, -1);
  int last = 1, counter = 0;
  for (int i = 0; i < k; i++) {
    cin >> c[i];
    last += c[i];
    while (counter < last) type[counter++] = i;
  }
  vector<vector<int> > G(k, vector<int>(k, INF));
  UnionFind listGraphs(n);
  int cnt = 0;
  vector<int> first;
  for (int i = 0; i < k; i++) {
    first.push_back(cnt);
    cnt += c[i];
  }
  int ui, vi, xi;
  for (int i = 0; i < m; i++) {
    cin >> ui >> vi >> xi;
    int typeU = type[ui], typeV = type[vi];
    ui--;
    vi--;
    if (xi == 0) {
      if (listGraphs.root(ui) == listGraphs.root(vi)) continue;
      listGraphs.join(ui, vi);
      G[typeU][typeV] = G[typeV][typeU] = 0;
    } else {
      int minimum = min(xi, G[typeU][typeV]);
      G[typeU][typeV] = G[typeV][typeU] = minimum;
    }
  }
  bool correct = true;
  for (int i = 0; i < k; i++)
    for (int j = 0; j < c[i]; j++)
      if (listGraphs.root(first[i]) != listGraphs.root(j + first[i]))
        correct = false;
  if (!correct) {
    cout << "No" << endl;
    return 0;
  }
  for (int mid = 0; mid < k; mid++)
    for (int i = 0; i < k; i++)
      for (int j = 0; j < k; j++) G[i][j] = min(G[i][j], G[i][mid] + G[mid][j]);
  cout << "Yes" << endl;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < k; j++) {
      if (i == j)
        cout << "0 ";
      else if (G[i][j] >= INF)
        cout << "-1 ";
      else
        cout << G[i][j] << " ";
    }
    cout << endl;
  }
}
