from collections import defaultdict def main(): N, M, K = map(int, input().split()) # 料金ごとに道路をまとめる edges_by_cost = defaultdict(list) for _ in range(M): a, b, c = map(int, input().split()) edges_by_cost[c].append((a, b)) d = list(map(int, input().split())) # 1回目の通行料金 possible = set() for a, b in edges_by_cost[d[0]]: possible.add(a) possible.add(b) # 2回目以降 for i in range(1, K): next_possible = set() for a, b in edges_by_cost[d[i]]: if a in possible: next_possible.add(b) if b in possible: next_possible.add(a) possible = next_possible # 出力 result = sorted(possible) print(len(result)) print(" ".join(map(str, result))) if __name__ == "__main__": main()