#include #include #include #include using namespace std; template string join(vector v, string str){ stringstream ss; for(int i = 0; i < v.size(); i++){ if(i) ss << str; ss << v[i]; } return ss.str(); } struct edge{ int to, cost; edge(int to, int cost){ this->to = to; this->cost = cost; } }; int main(){ int n, m, k; cin >> n >> m >> k; vector> e(n); while(m--){ int a, b, c; cin >> a >> b >> c; a--; b--; e[a].emplace_back(edge(b, c)); e[b].emplace_back(edge(a, c)); } int d[k]; for(int i = 0; i < k; i++) cin >> d[i]; vector> puni(k + 1, vector(n, false)); for(int i = 0; i < n; i++) puni[0][i] = true; for(int i = 1; i <= k; i++) for(int j = 0; j < n; j++) if(puni[i - 1][j]) for(auto& ee:e[j]) if(ee.cost == d[i - 1]) puni[i][ee.to] = true; for(int i = 0; i < k + 1; i++){ for(int j = 0; j < n; j++) cerr << puni[i][j] << ' '; cerr << endl; } vector ans; for(int i = 0; i < n; i++) if(puni[k][i]) ans.emplace_back(i + 1); cout << ans.size() << endl; cout << join(ans, " ") << endl; }