from queue import Queue used = set() n, m, k = map(int, input().split()) node = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) node[a-1].append((b-1, c)) node[b-1].append((a-1, c)) d = list(map(int, input().split())) qu = Queue() for i in range(n): qu.put((i, 0)) used.add((i, 0)) res = [] while not qu.empty(): (p, t) = qu.get() if t == k: res.append(p) continue for (np, c) in node[p]: nt = (np, t+1) if d[t] != c or nt in used: continue used.add(nt) qu.put(nt) res.sort() print(len(res)) ans = "" for i in res: ans += str(i+1)+" " print(ans.strip())