import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); HashMap>> route = new HashMap<>(); for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); if (!route.containsKey(c)) { route.put(c, new HashMap<>()); } if (!route.get(c).containsKey(a)) { route.get(c).put(a, new ArrayList<>()); } route.get(c).get(a).add(b); if (!route.get(c).containsKey(b)) { route.get(c).put(b, new ArrayList<>()); } route.get(c).get(b).add(a); } ArrayList> currents = new ArrayList<>(); for (int i = 0; i <= k; i++) { currents.add(new TreeSet<>()); } for (int i = 1; i <= n; i++) { currents.get(0).add(i); } for (int i = 0; i < k; i++) { int x = sc.nextInt(); HashMap> tmp = route.get(x); if (tmp == null) { break; } for (int y : currents.get(i)) { if (tmp.containsKey(y)) { currents.get(i + 1).addAll(tmp.get(y)); } } } StringBuilder sb = new StringBuilder(); sb.append(currents.get(k).size()).append("\n"); boolean isFirst = true; for (int x : currents.get(k)) { if (isFirst) { isFirst = false; } else { sb.append(" "); } sb.append(x); } System.out.println(sb); } }