using System.Linq; using System.Collections.Generic; using System; public class Edge { public int to { get; set; } public int fee { get; set; } } public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var m = int.Parse(line[1]); var k = int.Parse(line[2]); var aa = new List[n]; for (int i = 0; i < n; i++) aa[i] = new List(); for (int i = 0; i < m; i++) { line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]) - 1; var b = int.Parse(line[1]) - 1; var c = int.Parse(line[2]); aa[a].Add(new Edge { to = b, fee = c }); aa[b].Add(new Edge { to = a, fee = c }); } getAns(n, m, aa); } static void getAns(int n, int m, List[] aa) { string[] line = Console.ReadLine().Trim().Split(' '); var k = Array.ConvertAll(line, int.Parse); var ans = Enumerable.Range(0, n).ToList(); foreach (var x in k) { var ans2 = new List(); foreach (var y in ans) { foreach (var z in aa[y]) { if (z.fee == x) ans2.Add(z.to); } } ans = ans2; } ans.Sort(); var ans3 = new List(); foreach (var x in ans) ans3.Add(x + 1); Console.WriteLine(ans3.Count()); Console.WriteLine(string.Join(" ", ans3)); } }