#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, vector &ans, int k, int now, int count = 0){ if(count == k){ ans.emplace_back(now + 1); return; } for(edge &e:v[now]){ if(e.cost == d[count]){ dfs(v, d, ans, k, e.to, count + 1); } } } int main(){ cin.tie(0); ios::sync_with_stdio(false); 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; vector ans; for(int i = 0; i < n; i++){ dfs(v, d, ans, k, i); } sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); cout << ans.size() << endl; for(int x:ans) cout << x << ' '; cout << endl; return 0; }