n, m, k = map(int, input().split()) G = [[] for _ in range(n+1)] for i in range(k): a, b, c = map(int, input().split()) G[a].append((b, c)) G[b].append((a, c)) d = list(map(int, input().split())) print(G) visit = set(range(1, n+1)) for i in range(k): tmp = set() for j in visit: for (v, c) in G[j]: if c == d[i]: tmp.add(v) visit = tmp print(len(visit)) print(" ".join(map(str, visit)))