#include using namespace std; #define LOG(...) fprintf(stderr,__VA_ARGS__) //#define LOG(...) #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define REP(i,n) for(int i=0;i<(int)(n);++i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) typedef long long ll; typedef unsigned long long ull; typedef vector vb; typedef vector vi; typedef vector vll; typedef vector vvb; typedef vector vvi; typedef vector vvll; typedef pair pii; typedef pair pll; struct Edge { int to, cost; }; struct P { int town, k; }; int main() { int town_n, road_n, k; cin >> town_n >> road_n >> k; vector > E(town_n + 1); REP(i, road_n) { int a, b, c; cin >> a >> b >> c; E[a].push_back({ b, c }); E[b].push_back({ a, c }); } vi costs(k); REP(i, k) cin >> costs[i]; vi towns; queue

que; REP(i, town_n) { que.push({i+1, 0}); } while (!que.empty()) { P p = que.front(); que.pop(); if (p.k == k) { towns.push_back(p.town); } for (Edge& e : E[p.town]) { if (e.cost == costs[p.k]) { que.push({e.to, p.k+1}); } } } cout << towns.size() << endl; cout << towns[0]; FOR(i, 1, towns.size()) { cout << " " << towns[i]; } cout << endl; }