from collections import defaultdict
N,M,K = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append((b, c))
    G[b].append((a, c))
d = list(map(int,input().split()))
S = [i for i in range(N)]
for i in range(K):
    T = set()
    for pos in S:
        for nxt,c in G[pos]:
            if c == d[i]:
                T.add(nxt)
    S = list(T)
S.sort()
N = len(S)
print(N)
print(*[S[i] + 1 for i in range(N)])