#include #include #include #include #include #include #include #include using namespace std; #define FOR(i, s, e) for (int i = (s); i <= (e); i++) int N; int M; int K; struct edge{ int a; int b; int cost; }; edge edges[1000]; int d[1000]; bool dp[1010][110]; int main() { cin >> N >> M >> K; FOR(i,0,M - 1) { edge & e = edges[i]; cin >> e.a >> e.b >> e.cost; } FOR(i,1,K) { cin >> d[i]; } FOR(i,0,1009) { FOR(j,0,109) { dp[i][j] = false; } } FOR(i,0,109) { dp[0][i] = true; } FOR(i,1,K) { for(edge e : edges) { if(e.cost == d[i]) { dp[i][e.a] = dp[i][e.a] || dp[i - 1][e.b]; dp[i][e.b] = dp[i][e.b] || dp[i - 1][e.a]; } } } stringstream result; int cou = 0; FOR(i,1,N) { if(dp[K][i]) { result << i << " "; cou++; } } cout << cou << endl; cout << result.str(); return 0; }