N, M, K = [int(i) for i in input().strip().split(" ")] fee = {} for i in range(M): a, b, c = [int(i) for i in input().strip().split(" ")] if fee.get(c): fee[c].append((a,b)) else: fee[c] = [(a,b)] D = [int(i) for i in input().strip().split(" ")] cur = set([]) towns = fee[D[0]] for town in towns: cur.add(town[0]) cur.add(town[1]) next = set([]) for d in D[1:]: towns = fee[d] for town in towns: if town[0] in cur: next.add(town[1]) if town[1] in cur: next.add(town[0]) cur = next next = set([]) cur = list(cur) print(len(cur)) print(" ".join([str(i) for i in cur]))