#include "bits/stdc++.h" using namespace std; bool now[1000]; bool nex[1000]; int main(){ int N, M, K; cin >> N >> M >> K; vector a(M), b(M), c(M); for (int i = 0; i < M; i++) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; } vector d(K); for (int i = 0; i < K; i++) { cin >> d[i]; } for (int i = 0; i < N; i++) { now[i] = true; nex[i] = false; } for (int i = 0; i < K; i++) { for (int j = 0; j < M; j++) { if (c[j] != d[i]) continue; nex[a[i]] |= now[b[i]]; nex[b[i]] |= now[a[i]]; } for (int j = 0; j < N; j++) { now[j] = nex[j]; nex[j] = false; } } int count = 0; for (int i = 0; i < N; i++) { if (now[i]){ count++; } } cout << count << endl; for (int i = 0; i < N; i++) { if (now[i]){ if (--count) cout << (i + 1) << " "; else cout << (i + 1) << endl; } } }