from collections import defaultdict N,M,K = map(int,input().split()) G = [[] for _ in range(N)] for _ in range(M): a,b,c = map(int,input().split()) a -= 1 b -= 1 G[a].append((b, c)) G[b].append((a, c)) d = list(map(int,input().split())) S = set() for pos in range(N): for nxt,c in G[pos]: if c == d[0]: S.add(nxt) S = list(S) for i in range(1,K): T = set() for pos in S: for nxt,c in G[pos]: if c == d[i]: T.add(nxt) S = list(T) S.sort() N = len(S) print(N) print(*[S[i] + 1 for i in range(N)])