#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define INF (1 << 30) #define INFLL (1LL << 60) vector > edge[110]; vector ans; int his[1010] = {}; int main() { int n,m,k; int a,b,c; cin >> n >> m >> k; for(int i = 0;i < m;i++){ cin >> a >> b >> c; a--,b--; edge[a].push_back(make_pair(b,c)); edge[b].push_back(make_pair(a,c)); } for(int i = 0;i < k;i++){ cin >> his[i]; } bool memo[1010][101] = {}; bool used[110] = {}; for(int i = 0;i < n;i++){ queue > que; que.push(make_pair(i,0)); while(que.size()){ int now = que.front().first,how = que.front().second; que.pop(); if(how == k){ if(used[now]) continue; used[now] = true; ans.push_back(now + 1); continue; } if(memo[how][now]) continue; memo[how][now] = true; for(int i = 0;i < edge[now].size();i++){ if(his[how] != edge[now][i].second) { continue; } que.push(make_pair(edge[now][i].first,how + 1)); } } } sort(ans.begin(),ans.end()); cout << ans.size() << endl; for(int i = 0;i < ans.size();i++){ if(i != ans.size() - 1) cout << ans[i] << " "; else cout << ans[i]; } cout << endl; return 0; }