from collections import defaultdict N, M, K = map(int, input().split()) cost = [defaultdict(list) for _ in range(N)] for i in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 cost[a][c].append(b) cost[b][c].append(a) D = list(map(int, input().split())) ans = set() for i in range(N): # 出発点 positions = {i} next_positions = set() for j in range(K): for pos in positions: # pos から D[j] のコストで行ける場所 for nex in cost[pos][D[j]]: next_positions.add(nex) positions = next_positions next_positions = set() # K回の移動後になお、positionsにいる頂点が答え for pos in positions: ans.add(pos + 1) ans2 = sorted(ans) print(len(ans2)) print(*ans2)