import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd1 = readln.split.to!(size_t[]), n = rd1[0], m = rd1[1], k = rd1[2]; int[][int][int] buf; foreach (_; m.iota) { auto rd2 = readln.split.to!(int[]), a = rd2[0] - 1, b = rd2[1] - 1, c = rd2[2]; buf[c][a] ~= b; buf[c][b] ~= a; } auto di = readln.split.to!(int[]); auto ei = buf[di.front].keys.sort().uniq(); foreach (d; di.drop(1)) { int[] fi; foreach (e; ei) if (e in buf[d]) fi ~= buf[d][e]; ei = fi.sort().uniq(); } writeln(ei.array.length); writeln(ei.map!"a + 1".map!(to!string).join(" ")); }