from collections import defaultdict, deque n, m, k = map(int, input().split()) edge = defaultdict(list) for _ in range(m): a, b, c = map(int, input().split()) edge[a].append((b, c)) edge[b].append((a, c)) D = [0] + list(map(int, input().split())) Que = deque() for i in range(1, n + 1): Que.append((i, 0)) ANS = [] Seen = [[False for _ in range(n + 1)] for _ in range(k + 1)] while Que: cp, cnt = Que.popleft() if cnt == k: ANS.append(cp) continue for np, c in edge[cp]: if D[cnt + 1] != c: continue if Seen[cnt + 1][np]: continue Seen[cnt + 1][np] = True Que.append((np, cnt + 1)) ANS.sort() print(len(ANS)) print(*ANS)