結果
問題 | No.92 逃走経路 |
ユーザー |
|
提出日時 | 2020-04-12 04:33:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 5,000 ms |
コード長 | 1,415 bytes |
コンパイル時間 | 1,504 ms |
コンパイル使用メモリ | 79,564 KB |
最終ジャッジ日時 | 2025-01-09 17:36:53 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <iostream>#include <numeric>#include <vector>template <class Cost = int>struct Edge {int src, dst;Cost cost;Edge(int src = -1, int dst = -1, Cost cost = 1): src(src), dst(dst), cost(cost){};bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }};template <class Cost = int>using Graph = std::vector<std::vector<Edge<Cost>>>;void solve() {int n, m, k;std::cin >> n >> m >> k;Graph<> graph(n);while (m--) {int u, v, c;std::cin >> u >> v >> c;--u, --v;graph[u].emplace_back(u, v, c);graph[v].emplace_back(v, u, c);}std::vector<bool> dp(n, true);auto ndp = dp;while (k--) {int d;std::cin >> d;std::fill(ndp.begin(), ndp.end(), false);for (int v = 0; v < n; ++v) {if (!dp[v]) continue;for (auto e : graph[v]) {if (e.cost == d) ndp[e.dst] = true;}}std::swap(dp, ndp);}std::cout << std::accumulate(dp.begin(), dp.end(), 0) << std::endl;for (int v = 0; v < n; ++v) {if (dp[v]) std::cout << v + 1 << " ";}std::cout << std::endl;}int main() {std::cin.tie(nullptr);std::ios::sync_with_stdio(false);solve();return 0;}