#include #include #include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) using namespace std; int main() { // input int n, m, k; cin >> n >> m >> k; vector > > g(n); repeat (i,m) { int a, b, c; cin >> a >> b >> c; -- a; -- b; g[a][c].push_back(b); g[b][c].push_back(a); } vector ds(k); repeat (i,k) cin >> ds[i]; // search set xs; repeat (i,n) xs.insert(i); for (int d : ds) { set ys; for (int x : xs) { if (g[x].count(d)) for (int y : g[x][d]) { ys.insert(y); } } xs = ys; } // output cout << xs.size() << endl; for (int x : xs) cout << x + 1 << ' '; cout << endl; return 0; }