package Main; import java.io.*; import java.util.*; import java.math.*; class Main { static int n , m , k; static int[] usedMoney; static String[][] memo; static ArrayList ans = new ArrayList(); public static void out (Object o) { System.out.println(o); } public static boolean check (int pos , int cnt) { if (cnt == k) return true; for (int i = 1; i <= n; i++) { if (memo[pos][i] == null) continue; String[] s = memo[pos][i].split(","); for (String item : s) { int l = Integer.parseInt(item); if (l != usedMoney[k - cnt - 1]) continue; if (check(i , cnt + 1)) return true; } } return false; } public static void solve () { for (int i = 1; i <= n; i++) if (check(i , 0)) ans.add(i); out(ans.size()); System.out.print(ans.get(0)); for (int i = 1; i < ans.size(); i++) System.out.print(" " + ans.get(i)); out(""); } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] line = br.readLine().split(" "); n = Integer.parseInt(line[0]); m = Integer.parseInt(line[1]); k = Integer.parseInt(line[2]); usedMoney = new int[k]; memo = new String[n + 1][n + 1]; for (int i = 0; i < m; i++) { line = br.readLine().split(" "); int j = Integer.parseInt(line[0]); int l = Integer.parseInt(line[1]); memo[j][l] = memo[j][l] == null ? line[2] : memo[j][l] + "," + line[2]; memo[l][j] = memo[l][j] == null ? line[2] : memo[l][j] + "," + line[2]; } String[] line2 = br.readLine().split(" "); for (int i = 0; i < k; i++) usedMoney[i] = Integer.parseInt(line2[i]); // long s = System.currentTimeMillis(); solve(); //long e = System.currentTimeMillis(); // out("time : " + (e - s) + "ms"); } }