結果
問題 | No.2588 Increasing Record |
ユーザー | suisen |
提出日時 | 2023-12-23 20:21:54 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,418 bytes |
コンパイル時間 | 1,289 ms |
コンパイル使用メモリ | 113,020 KB |
実行使用メモリ | 41,384 KB |
最終ジャッジ日時 | 2024-09-27 12:36:33 |
合計ジャッジ時間 | 9,278 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | WA | - |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 121 ms
15,360 KB |
testcase_13 | AC | 120 ms
15,360 KB |
testcase_14 | AC | 121 ms
15,488 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 179 ms
27,700 KB |
testcase_31 | WA | - |
testcase_32 | AC | 261 ms
38,988 KB |
testcase_33 | AC | 265 ms
40,188 KB |
testcase_34 | AC | 260 ms
40,184 KB |
testcase_35 | AC | 261 ms
40,132 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | AC | 137 ms
31,572 KB |
testcase_40 | AC | 153 ms
32,672 KB |
testcase_41 | AC | 163 ms
34,708 KB |
testcase_42 | AC | 178 ms
36,512 KB |
testcase_43 | AC | 186 ms
41,384 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
ソースコード
#include <deque> #include <iostream> #include <utility> #include <vector> #include <atcoder/modint> using mint = atcoder::modint998244353; std::vector<mint> naive(int n, const std::vector<std::pair<int, int>>& edges) { std::vector<std::vector<int>> g(n); for (const auto& [u, v] : edges) { g[u].push_back(v); g[v].push_back(u); } std::vector<mint> f(n, 1); for (int x = 0; x < n; ++x) { std::vector<int8_t> vis(n); vis[x] = true; std::deque<int> dq{ x }; while (dq.size()) { int u = dq.front(); dq.pop_front(); for (int v : g[u]) if (not vis[v]) { vis[v] = true; if (v < x) { dq.push_back(v); } if (v > x) { f[v] += f[x]; } } } } return f; } #include <atcoder/dsu> #include <algorithm> #include <set> std::vector<mint> solve(int n, const std::vector<std::pair<int, int>>& edges) { atcoder::dsu uf(n); std::vector<std::vector<int>> ts(n); for (const auto& [u, v] : edges) { ts[u].push_back(v); } std::vector<std::set<int>> neighbors(n); std::vector<mint> lazy(n); for (const auto& [u, v] : edges) { neighbors[v].insert(u); } std::vector<mint> f(n, 1); for (int s = 0; s < n; ++s) { std::set<int> cmps_set; for (int t : ts[s]) { cmps_set.insert(uf.leader(t)); } std::vector<int> cmps(cmps_set.begin(), cmps_set.end()); for (int t : cmps) { uf.merge(s, t); f[s] += lazy[t]; lazy[s] += lazy[t]; } lazy[s] += f[s]; if (cmps.empty()) continue; auto argmax = *std::max_element(cmps.begin(), cmps.end(), [&](int i, int j) { return neighbors[i].size() < neighbors[j].size(); }); for (int t : cmps) if (t != argmax) { lazy[s] -= lazy[t]; } if (neighbors[argmax].size() < neighbors[s].size()) { argmax = s; } for (int t : cmps) if (t != argmax) { for (int neighbor : neighbors[t]) if (neighbor != s) { f[neighbor] += lazy[t]; if (neighbors[argmax].count(neighbor)) { continue; } f[neighbor] -= lazy[argmax]; neighbors[argmax].insert(neighbor); } } if (s != argmax) { for (int neighbor : neighbors[s]) if (neighbor != s) { if (neighbors[argmax].count(neighbor)) { continue; } f[neighbor] -= lazy[argmax]; neighbors[argmax].insert(neighbor); } } int root = uf.leader(s); std::swap(lazy[root], lazy[s]); std::swap(neighbors[root], neighbors[argmax]); neighbors[root].erase(s); } return f; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m; std::cin >> n >> m; std::vector<std::pair<int, int>> edges(m); for (auto& [u, v] : edges) { std::cin >> u >> v; --u, --v; if (u < v) { std::swap(u, v); } } mint ans = 0; for (const auto& e : solve(n, edges)) { ans += e; } std::cout << ans.val() << std::endl; }