#include using namespace std; namespace { typedef double real; typedef long long ll; template ostream& operator<<(ostream& os, const vector& vs) { if (vs.empty()) return os << "[]"; os << vs[0]; for (int i = 1; i < vs.size(); i++) os << " " << vs[i]; return os; } template istream& operator>>(istream& is, vector& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } struct Edge { int from, to, cost; Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {} }; int N, M, K; vector E; vector D; void input() { cin >> N >> M >> K; E.clear(); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; E.push_back(Edge(a, b, c)); } D.clear(); D.resize(K); cin >> D; } void solve() { vector P[2]; P[0] = vector(N, true); P[1] = vector(N, false); for (int k = 0; k < K; k++) { int d = D[k]; for (int i = 0; i < M; i++) { const Edge& e = E[i]; if (e.cost == d) { if (P[0][e.from]) P[1][e.to] = true; if (P[0][e.to]) P[1][e.from] = true; } } swap(P[0], P[1]); fill(P[1].begin(), P[1].end(), false); } vector ans; for (int i = 0; i < N; i++) { if (P[0][i]) { ans.push_back(i + 1); } } cout << ans.size() << endl; cout << ans << endl; } } int main() { input(); solve(); return 0; }