def check(i_, v_): if i_ == K: ans.append(v_) return True for (v, c) in G[v_]: if c == d[i_]: if check(i_ + 1, v): return True return False N, M, K = map(int, input().split()) G = [[] for _ in range(N + 1)] for _ in range(M): a, b, c = map(int, input().split()) G[a].append((b, c)) G[b].append((a, c)) d = list(map(int, input().split())) """ print("d=") print(d) print("G=") print(G) """ ans = [] for i in range(1, N + 1): check(0, i) print(len(ans)) ans.sort() print(' '.join(map(str, ans)))