using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static private Magatro M = new Magatro(); static private void Main(string[]args) { M.Scan(); M.Solve(); } } public class Scanner { private string[] S; private int Index; private char Separator; public Scanner(char separator = ' ') { Index = 0; Separator = separator; } private string[] Line() { return Console.ReadLine().Split(Separator); } public string Next() { string result; if (S == null || Index >= S.Length) { S = Line(); Index = 0; } result = S[Index]; Index++; return result; } public int NextInt() { return int.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } } public class Magatro { private int N, M, K; private int[] d; private List[] Load; private List[] Fee; private HashSet Anser = new HashSet(); public void Scan() { Scanner sc = new Scanner(); N = sc.NextInt(); M = sc.NextInt(); K = sc.NextInt(); Load = new List[N]; Fee = new List[N]; for(int i = 0; i < N; i++) { Load[i] = new List(); Fee[i] = new List(); } for (int i = 0; i < M; i++) { int a = sc.NextInt(); int b = sc.NextInt(); int c = sc.NextInt(); Load[a - 1].Add(b-1); Load[b - 1].Add(a-1); Fee[a - 1].Add(c); Fee[b - 1].Add(c); } d = new int[K]; for(int i = 0; i < K; i++) { d[i] = sc.NextInt(); } } public void Solve() { for(int i = 0; i < N; i++) { HashSet[] to = new HashSet[K]; for(int j = 0; j < K; j++) { to[j] = new HashSet(); if (j == 0) { for (int k = 0; k < Load[i].Count; k++) { if (Fee[i][k] == d[j]) to[j].Add(Load[i][k]); } } else { foreach(int k in to[j - 1]) { for(int l = 0; l < Load[k].Count; l++) { if (Fee[k][l] == d[j]) to[j].Add(Load[k][l]); } } } } foreach(int a in to[K - 1]) { Anser.Add(a+1); } } int[] ans = Anser.ToArray(); Array.Sort(ans); Console.WriteLine(ans.Length); Console.WriteLine(string.Join(" ", ans)); } }