// No.92 逃走経路 // https://yukicoder.me/problems/no/92 // #include #include #include #include using namespace std; struct connection { int to; int cost; }; vector solve(unsigned int N, vector> &cities, vector& logs); int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); unsigned int N, M, K; cin >> N >> M >> K; vector> cities(N+1); for (auto i = 0; i < M; ++i) { int a, b, c; cin >> a >> b >> c; cities[a].push_back(connection {b, c}); cities[b].push_back(connection {a, c}); } vector logs(K); for (auto i = 0; i < K; ++i) { cin >> logs[i]; } vector ans = solve(N, cities, logs); cout << ans.size() << endl; for (int i = 0; i < ans.size(); ++i) { string s = (i+1 >= ans.size()) ? "\n": " "; cout << ans[i] << s; } } vector solve(unsigned int N, vector> &cities, vector& logs) { unordered_set possibilities; for (auto i = 1; i <= N; ++i) possibilities.insert(i); for (auto l: logs) { unordered_set np; for (auto p: possibilities) { for (auto c: cities[p]) { if (c.cost == l) np.insert(c.to); } } possibilities = move(np); } vector ans; for (auto p: possibilities) ans.push_back(p); sort(ans.begin(), ans.end()); return ans; }