#define _CRT_SECURE_NO_WARNINGS //#define _GLIBCXX_DEBUG #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; i ostream & operator<<(ostream & os, vector const &); template typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple const &){} template typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple const & t){ os << (n==0?"":" ") << get(t); _ot(os, t); } template ostream & operator<<(ostream & os, tuple const & t){ _ot<0>(os, t); return os; } template ostream & operator<<(ostream & os, pair const & p){ return os << "(" << p.first << ", " << p.second << ") "; } template ostream & operator<<(ostream & os, vector const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; } #ifdef DEBUG #define dump(...) (cerr<<#__VA_ARGS__<<" = "< f.weight : // !!INVERSE!! e.src != f.src ? e.src < f.src : e.dst < f.dst; } typedef vector Edges; typedef vector Graph; typedef vector Array; typedef vector Matrix; int main(){ int N,M,K; while(cin>>N>>M>>K){ Edges es(M*2); rep(i,M){ int a,b,c; cin >> a >> b >> c; es[i] = Edge(a,b,c); es[i+M] = Edge(b,a,c); } int d; cin >> d; set s; for(auto & e : es){ if(e.weight == d){ s.insert(e.src); s.insert(e.dst); } } rep(i,K-1){ set t; cin >> d; for(auto & e : es){ if(e.weight == d){ if(s.count(e.src)){ t.insert(e.dst); } if(s.count(e.dst)){ t.insert(e.src); } } } swap(s,t); } cout << s.size() << endl; cout << vi(all(s)) << endl; } }