#include using namespace std; typedef long long int64; struct edge{ int to, cost; }; vector< int > visit; typedef vector< vector< edge > > Graph; void add_edge(Graph& info, int u, int v, int cost, bool flag = true){ info[u].push_back( (edge){ v, cost}); if(flag) info[v].push_back( (edge){ u, cost}); } bool check(const Graph& graph, const vector< int >& d, int pos, int idx){ if(pos == -1) return true; for(int i = 0; i < graph[idx].size(); i++){ if(graph[idx][i].cost == d[pos] && check(graph, d, pos - 1, graph[idx][i].to)) return true; } return false; } int main(){ int N, M, K; cin >> N >> M >> K; Graph graph(N); for(int i = 0; i < M; i++){ int a, b, c; cin >> a >> b >> c; add_edge( graph, a - 1, b - 1, c); } vector< int > d(K); for(int i = 0; i < K; i++){ cin >> d[i]; } for(int i = 0; i < N; i++){ for(int j = 0; j < graph[i].size(); j++){ if(graph[i][j].cost == d[K - 1] && check(graph, d, K - 2, graph[i][j].to)){ visit.push_back(i + 1); break; } } } cout << visit.size() << endl; for(vector< int >::const_iterator it = visit.begin(); it != visit.end(); it++){ cout << (it == visit.begin() ? "": " ") << *it; } cout << endl; }