#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n, m, k; cin >> n >> m >> k; vector Graph(n, vector>(0)); rep(_, m) { int a, b, c; cin >> a >> b >> c; --a, --b; Graph[a].push_back({ b, c }); Graph[b].push_back({ a, c }); } set cand; rep(_, k) { int d; cin >> d; if (_ == 0) { rep(i, n) { bool ok = false; for (auto [__, cost] : Graph[i]) { if (cost == d) ok = true; } if (ok) cand.insert(i); } } else { set nCand; for (int i : cand) { for (auto [j, cost] : Graph[i]) { if (cost == d) nCand.insert(j); } } swap(cand, nCand); } } cout << cand.size() << endl; for (auto x : cand) cout << x + 1 << ' '; cout << endl; return 0; }