#include #include #include #include #include #include using namespace std; int main() { int n, m, k; cin >> n >> m >> k; vector a(m), b(m), c(m); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i] >> c[i]; } vector< vector > possible(k + 1, vector(n + 1, false)); fill(possible[0].begin() + 1, possible[0].end(), true); int d, x, y; for (int i = 0; i < k; i++) { cin >> d; for (int j = 0; j < m; j++) { if (c[j] == d) { x = a[j]; y = b[j]; if (possible[i][x]) { possible[i + 1][y] = true; } if (possible[i][y]) { possible[i + 1][x] = true; } } } } vector ans; for (int i = 0; i <= n; i++) { if (possible[k][i]) { ans.push_back(i); } } cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { if (i != 0) { cout << " "; } cout << ans[i]; } cout << endl; return 0; }