from collections import defaultdict N,M,K=map(int,input().split()) E=defaultdict(list) for _ in range(M): a,b,c=map(int,input().split()) E[c].append((a,b)) D=map(int,input().split()) S=set(range(1,N+1)) for d in D: T=set() for u,v in E[d]: if u in S: T.add(v) if v in S: T.add(u) S=T.copy() print(len(S)) print(*sorted(S))