import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, m, k = map(int, input().split()) g = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) a, b = a-1, b-1 g[a].append((c, b)) g[b].append((c, a)) D = list(map(int, input().split())) dp = [True]*n for i, d in enumerate(D): nx = [False]*n for v in range(n): if not dp[v]: continue for c, u in g[v]: if c == d: nx[u] = True dp = nx ans = [] for v in range(n): if dp[v]: ans.append(v+1) print(len(ans)) print(*ans)