from collections import defaultdict def solve(): n, m, k = map(int, input().split()) mip = defaultdict(list) mpi = defaultdict(list) for i in range(m): a, b, c = map(int, input().split()) mpi[c, a].append(b) mpi[c, b].append(a) mip[c].append((a, b)) d = tuple(map(int, input().split())) v = (set(), set()) for a in mip[d[0]]: v[0].add(a[0]) v[0].add(a[1]) if k == 1: return v[0] a1 = 0 a2 = 1 for i in range(1, k): for x in v[a1]: for b in mpi[d[i], x]: v[a2].add(b) v[a1].clear() a1, a2 = a2, a1 return v[a1] v = sorted(solve()) print(len(v)) print(*v)