# -*- coding: utf-8 -*- from collections import deque N,M,K = map(int, input().split()) a = [-1] b = [-1] c = [-1] for i in range(M): s,t,u = map(int, input().split()) a.append(s) b.append(t) c.append(u) d = list(map(int, input().split())) answer = [] # スタート町のセット start_towns = deque() end_towns = deque() for i in range(1, M+1): if d[0]==c[i]: start_towns.append(a[i]) start_towns.append(b[i]) # スタート町を起点に1ステップずつ幅優先探索 for i in range(1, K): es_cost = d[i] while len(start_towns) > 0: town = start_towns.popleft() for j in range(1,M+1): if c[j]==es_cost and town == a[j]: end_towns.append(b[j]) elif c[j]==es_cost and town == b[j]: end_towns.append(a[j]) if i < K-1: start_towns = end_towns end_towns = deque() # end_townsが答え for t in end_towns: answer.append(t) answer.sort() print(len(answer)) answer_str = str(answer[0]) for i in range(1, len(answer)): answer_str += ' ' + str(answer[i]) print(answer_str)