import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; import java.util.TreeSet; public class Main { static int N, M, K; static int[] A, B, C; static int[] D; public static int solve(){ int[][] dp = new int[K+1][N+1]; for (int i = 0; i < K+1; i++) { for (int j = 0; j < N+1; j++) { dp[i][j] = 0; } } for (int i = 0; i < M; i++) { if(C[i] == D[1]) dp[1][A[i]] = dp[1][B[i]] = 1; } for (int k = 2; k <= K; k++) { for (int i = 0; i < M; i++) { if(C[i] == D[k]) { if(dp[k-1][A[i]] == 1) dp[k][B[i]] = 1; if(dp[k-1][B[i]] == 1) dp[k][A[i]] = 1; } } } TreeSet ret = new TreeSet(); for (int i = 1; i <= N; i++) { if(dp[K][i] == 1) ret.add(new Integer(i)); } System.out.println(ret.size()); int count = 0; for (Integer i : ret) { System.out.print(i); count++; if(count != ret.size()) System.out.print(" "); } System.out.print("\n"); return 0; } public static void main(String[] args){ Scanner S = new Scanner(System.in); N = S.nextInt(); M = S.nextInt(); K = S.nextInt(); A = new int[M]; B = new int[M]; C = new int[M]; for (int i = 0; i < M; i++) { A[i] = S.nextInt(); B[i] = S.nextInt(); C[i] = S.nextInt(); } D = new int[K+1]; for (int i = 1; i < K+1; i++) { D[i] = S.nextInt(); } solve(); } }