#include template T in() { abort(); return T(); } template<> std::string in() { std::string str; std::cin >> str; return str; } template<> int in() { int x; scanf("%d", &x); return x; } template void out(T x) { abort(); } template<> void out(const char* x) { printf("%s\n", x); } template<> void out(std::string x) { std::cout << x << std::endl; } template<> void out(int x) { printf("%d\n", x); } template<> void out(long x) { printf("%ld\n", x); } template<> void out(size_t x) { printf("%lu\n", x); } struct Edge { Edge() {} Edge(int from_, int to_, int cost_) : from(from_), to(to_), cost(cost_) {} int from; int to; int cost; }; int n, m, k; Edge edge[1024]; int d[1024]; int main() { n = in(); m = in(); k = in(); for(int i = 0; i < m; ++i) { edge[i].from = in(); edge[i].to = in(); edge[i].cost = in(); } for(int i = 0; i < k; ++i) { d[i] = in(); } bool flags[2][1024]; bool *xs = flags[0]; bool *ys = flags[1]; for(int i = 1; i <= n; ++i) { xs[i] = true; } for(int i = 0; i < k; ++i) { for(int j = 1; j <= n; ++j) ys[j] = false; for(int j = 0; j < m; ++j) { int from = edge[j].from; int to = edge[j].to; int cost = edge[j].cost; if( cost == d[i] ) { ys[to] = ys[to] or xs[from]; ys[from] = ys[from] or xs[to]; } } std::swap(xs, ys); } std::vector res; for(int i = 1; i <= n; ++i) { if( xs[i] ) res.push_back(i); } out(res.size()); printf("%d", res[0]); for(int i = 1; i < (int)res.size(); ++i) { printf(" %d", res[i]); } puts(""); return 0; }