N,M,K = map(int,input().split()) G = {i:[] for i in range(1,N+1)} for _ in range(M): a,b,c= map(int,input().split()) G[a].append((b,c)) G[b].append((a,c)) D = list(map(int,input().split())) dp = [[0 for _ in range(K+1)] for _ in range(N+1)] for i in range(1,N+1): for k,c in G[i]: if c==D[0]: dp[i][1] = 1 break for j in range(2,K+1): for i in range(1,N+1): for k,c in G[i]: if c==D[j-1] and dp[k][j-1]==1: dp[i][j]=1 break A = [] for i in range(1,N+1): if dp[i][K]==1: A.append(i) print(len(A)) print(*A)