import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; import java.util.List; import java.util.Queue; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class Main_yukicoder92 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); List> edges = new ArrayList>(); for (int i = 0; i < n; i++) { edges.add(new ArrayDeque()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; int c = sc.nextInt(); edges.get(a).add(new Edge(a, b, c)); edges.get(b).add(new Edge(b, a, c)); } int[] d = new int[k]; for (int i = 0; i < k; i++) { d[i] = sc.nextInt(); } Deque sts = new ArrayDeque(); Deque std = new ArrayDeque(); Deque stn = new ArrayDeque(); for (int i = 0; i < n; i++) { sts.push(i); std.push(0); stn.push(i); } Set ret = new TreeSet(); while (!sts.isEmpty()) { int st = sts.pop(); int di = std.pop(); int no = stn.pop(); if (di == k) { ret.add(st); continue; } for (Edge e : edges.get(no)) { if (e.w == d[k - 1 - di]) { sts.push(st); std.push(di + 1); stn.push(e.v); } } } System.out.println(ret.size()); boolean flag = false; for (int e : ret) { if (!flag) { System.out.printf("%d", e + 1); flag = true; } else { System.out.printf(" %d", e + 1); } } System.out.println(""); sc.close(); } private static class Edge { // int u; // from int v; // to int w; // cost Edge(int u, int v, int w) { // this.u = u; this.v = v; this.w = w; } } }