#include using namespace std; struct edge { int to, cost; }; typedef vector< vector< edge > > Graph; int N, M, K; Graph graph; int val[1000]; bool visited[100], dp[1000][1000]; void rec(int idx, int cnt) { if(cnt == K) { visited[idx] = true; } else if(!dp[idx][cnt]++) { for(int i = 0; i < graph[idx].size(); i++) { edge& e = graph[idx][i]; if(val[cnt] == e.cost) rec(e.to, cnt + 1); } } } int main() { fill_n( *dp, 1000 * 1000, false); cin >> N >> M >> K; graph.resize(N); for(int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; --a, --b; graph[a].push_back((edge){b, c}); graph[b].push_back((edge){a, c}); } for(int i = 0; i < K; i++) { cin >> val[i]; } for(int i = 0; i < N; i++) { for(int j = 0; j < graph[i].size(); j++) { edge&e = graph[i][j]; if(val[0] == e.cost) rec(i, 1); } } cout << count(visited, visited + N, true) << endl; bool first = false; for(int i = 0; i < N; i++) { if(visited[i]) { if(first++) cout << " "; cout << i + 1; } } cout << endl; }