using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; class mainClass { static Scanner sc; static bool defret = false; public static void Main(string[] args) { sc = new Scanner(); while (pre()) solve(); } static bool pre() { defret = !defret; return defret; } static void solve() { var vec = sc.nextIntArray(); int N = vec[0], M = vec[1], K = vec[2]; var abc = new Tuple[M]; int[,] cost = new int[N, N]; List[] graph = new List[N]; for (int i = 0; i < N; i++) { graph[i] = new List(); } for (int i = 0; i < M; i++) { vec = sc.nextIntArray(); vec[0]--;vec[1]--; graph[vec[0]].Add(vec[1]); graph[vec[1]].Add(vec[0]); cost[vec[0], vec[1]] = vec[2]; cost[vec[1], vec[0]] = vec[2]; abc[i] = Tuple.Create(vec[0], vec[1], vec[2]); } int[] d = sc.nextIntArray(); bool[, ] dp = new bool[K, N];//[i][j] = i回目にjいる可能性があるか? foreach (var e in abc) { if (e.Item3 == d[0]) { dp[0, e.Item1] = true; dp[0, e.Item2] = true; } } for (int i = 0; i < K - 1; i++) { for (int j = 0; j < N; j++) { if (!dp[i, j]) continue; foreach (var e in graph[j]) { if (cost[j, e] == d[i + 1]) { dp[i + 1, e] = true; } } } } int ans = 0; List ansList = new List(); for (int i = 0; i < N; i++) { if (dp[K - 1, i]) { ans++; ansList.Add(i + 1); } } Console.WriteLine(ans); for (int i = 0; i < ansList.Count; i++) { Console.Write(ansList[i]); Console.Write((i == (int)ansList.Count - 1 ? "\n" : " ")); } } } public class Scanner { public Scanner() { } public string next() { return Console.ReadLine(); } public int nextInt() { return int.Parse(next()); } public double nextDouble() { return double.Parse(next()); } public long nextLong() { return long.Parse(next()); } public string[] nextArray() { return next().Split(' '); } public int[] nextIntArray() { return Array.ConvertAll(nextArray(), e => int.Parse(e)); } public long[] nextLongArray() { return Array.ConvertAll(nextArray(), e => long.Parse(e)); } public double[] nextDoubleArray() { return Array.ConvertAll(nextArray(), e => double.Parse(e)); } }