#include <bits/stdc++.h>
using namespace std;
long long int inf = 1e18;
long long int p = 1e9 + 7;
long long int phi(long long int n) {
  long long int result = n;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      result -= result / i;
    }
  }
  if (n > 1) result -= result / n;
  return result;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
vector<vector<long long int>> adj(1e5 + 1);
long long int used[100001];
void dfs(long long int s) {
  used[s] = 1;
  for (auto x : adj[s]) {
    if (!used[x]) dfs(x);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int i, j, h, x, y, k, t, n, m, z;
  cin >> n >> m >> k;
  long long int arr[n + 1], temp[k + 1];
  long long int c[k + 1];
  long long int cur = 1;
  for (i = 1; i <= k; i++) {
    cin >> c[i];
    temp[i] = cur;
    for (j = 0; j < c[i]; j++) arr[cur++] = i;
  }
  long long int dp[k + 1][k + 1];
  for (i = 1; i <= k; i++) {
    for (j = 1; j <= k; j++) dp[i][j] = inf;
  }
  while (m--) {
    cin >> x >> y >> z;
    dp[arr[x]][arr[y]] = std::min(z, dp[arr[x]][arr[y]]);
    dp[arr[y]][arr[x]] = std::min(z, dp[arr[y]][arr[x]]);
    if (z == 0) {
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
  }
  for (i = 1; i <= k; i++) {
    memset(used, 0, sizeof(used));
    dfs(temp[i]);
    long long int t2 = 0;
    for (j = 0; j < c[i]; j++) t2 += used[j + temp[i]];
    if (t2 != c[i]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes\n";
  for (long long int l = 1; l <= k; l++) {
    for (i = 1; i <= k; i++) {
      for (j = 1; j <= k; j++) {
        if (dp[i][j] > (dp[i][l] + dp[l][j])) dp[i][j] = dp[i][l] + dp[l][j];
      }
    }
  }
  for (i = 1; i <= k; i++) {
    for (j = 1; j <= k; j++) {
      if (i == j)
        cout << "0 ";
      else if (dp[i][j] >= inf)
        cout << -1 << " ";
      else
        cout << dp[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
