N,M,K = [int(i) for i in input().split()] a = [0]*M b = [0]*M c = [0]*M for i in range(M): a[i],b[i],c[i] = map(int, input().split()) candidates = set(range(1,N+1)) for k in map(int, input().split()): new_candidates = set([]) for i in range(M): if c[i] == k: if a[i] in candidates: new_candidates.add(b[i]) if b[i] in candidates: new_candidates.add(a[i]) candidates = new_candidates print(len(candidates)) print(" ".join([str(i) for i in candidates]))