package main
import (
"bufio"
"fmt"
"os"
)
type DSU struct {
parent []int
}
func NewDSU(n int) *DSU {
p := make([]int, n+1)
for i := 1; i <= n; i++ {
p[i] = i
}
return &DSU{parent: p}
}
func (d *DSU) Find(i int) int {
if d.parent[i] == i {
return i
}
d.parent[i] = d.Find(d.parent[i])
return d.parent[i]
}
func (d *DSU) Union(i, j int) {
rootI := d.Find(i)
rootJ := d.Find(j)
if rootI != rootJ {
d.parent[rootI] = rootJ
}
}
func nextInt(in *bufio.Reader) int {
n := 0
c, err := in.ReadByte()
for err == nil && c <= ' ' {
c, err = in.ReadByte()
}
for err == nil && c > ' ' {
n = n*10 + int(c-'0')
c, err = in.ReadByte()
}
return n
}
func main() {
in := bufio.NewReader(os.Stdin)
out := bufio.NewWriter(os.Stdout)
defer out.Flush()
n := nextInt(in)
m := nextInt(in)
k := nextInt(in)
c := make([]int, k+1)
for i := 1; i <= k; i++ {
c[i] = nextInt(in)
}
typeArr := make([]int, n+1)
L := make([]int, k+1)
R := make([]int, k+1)
current_type := 1
current_count := 0
L[1] = 1
for i := 1; i <= n; i++ {
typeArr[i] = current_type
current_count++
if current_count == c[current_type] {
R[current_type] = i
if current_type < k {
L[current_type+1] = i + 1
}
current_type++
current_count = 0
}
}
dsu := NewDSU(n)
infinity := int(1e9)
D := make([][]int, k+1)
for i := 1; i <= k; i++ {
D[i] = make([]int, k+1)
for j := 1; j <= k; j++ {
if i == j {
D[i][j] = 0
} else {
D[i][j] = infinity
}
}
}
for i := 0; i < m; i++ {
u := nextInt(in)
v := nextInt(in)
x := nextInt(in)
if x == 0 {
dsu.Union(u, v)
}
tu := typeArr[u]
tv := typeArr[v]
if x < D[tu][tv] {
D[tu][tv] = x
D[tv][tu] = x
}
}
correct := true
for i := 1; i <= k; i++ {
if L[i] <= R[i] {
first := dsu.Find(L[i])
for j := L[i] + 1; j <= R[i]; j++ {
if dsu.Find(j) != first {
correct = false
break
}
}
}
if !correct {
break
}
}
if !correct {
fmt.Fprintln(out, "No")
return
}
for p := 1; p <= k; p++ {
for i := 1; i <= k; i++ {
if D[i][p] == infinity {
continue
}
for j := 1; j <= k; j++ {
if D[p][j] == infinity {
continue
}
if D[i][j] > D[i][p]+D[p][j] {
D[i][j] = D[i][p] + D[p][j]
}
}
}
}
fmt.Fprintln(out, "Yes")
for i := 1; i <= k; i++ {
for j := 1; j <= k; j++ {
val := D[i][j]
if val == infinity {
val = -1
}
if j > 1 {
fmt.Fprint(out, " ")
}
fmt.Fprint(out, val)
}
fmt.Fprintln(out)
}
}