#include #include #include using namespace std; struct edge{ int to, cost; edge(int to, int cost){ this->to = to; this->cost = cost; } }; void dfs(vector> &v, vector &d, set &ans, int k, int now, int count = 0){ if(count == k){ ans.insert(now + 1); return; } for(edge &e:v[now]){ if(e.cost == d[count]){ dfs(v, d, ans, k, e.to, count + 1); } } } int main(){ int n, m, k; cin >> n >> m >> k; vector> v(n); while(m--){ int a, b, c; cin >> a >> b >> c; a--; b--; v[a].emplace_back(edge(b, c)); v[b].emplace_back(edge(a, c)); } vector d(k); for(int &x:d) cin >> x; set ans; for(int i = 0; i < n; i++){ dfs(v, d, ans, k, i); } cout << ans.size() << endl; for(int x:ans) cout << x << ' '; cout << endl; return 0; }