import collections def read_data(): N, M, K = map(int, input().split()) Es = [collections.defaultdict(set) for i in range(N)] roads_v = collections.defaultdict(set) for m in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 Es[a][c].add(b) Es[b][c].add(a) roads_v[c].add(a) roads_v[c].add(b) ds = list(map(int, input().split())) return N, M, K, Es, roads_v, ds def solve(N, M, K, Es, roads_v, ds): candidates = roads_v[ds[0]] for d in ds[1:]: new_candidates = set() for src in candidates: new_candidates |= Es[src][d] candidates = new_candidates candidates = list(candidates) candidates.sort() candidates = [c + 1 for c in candidates] print(len(candidates)) print(*candidates) N, M, K, Es, roads_v, ds = read_data() solve(N, M, K, Es, roads_v, ds)