#include #include #include #include using namespace std; int main(){ int n, m, k, a, b, c; cin >> n >> m >> k; map>> pay; for(int i = 0; i < m; i++){ cin >> a >> b >> c; pay[c].push_back(make_pair(a,b)); pay[c].push_back(make_pair(b,a)); } set pos; cin >> a; for(pair p : pay[a]){ pos.insert(p.second); } for(int i = 1; i < k; i++){ cin >> a; set after; for(int j = 0; j < pay[a].size(); j++){ pair p = pay[a][j]; if(pos.find(p.first)!=pos.end()) after.insert(p.second); } pos = after; // cout << "after " << a << endl; // for(auto p : pos){ // cout << p << endl; // } } set::iterator it = pos.begin(); cout << pos.size() << endl; for(int i = 0; i < pos.size(); i++){ if(i) cout << " "; cout << *it; it++; } cout << endl; return 0; }