結果

問題 No.2588 Increasing Record
ユーザー KudeKude
提出日時 2023-12-16 01:01:03
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 748 ms / 3,000 ms
コード長 2,122 bytes
コンパイル時間 3,624 ms
コンパイル使用メモリ 286,820 KB
実行使用メモリ 45,440 KB
最終ジャッジ日時 2024-09-27 06:46:30
合計ジャッジ時間 19,698 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
VVI to(n);
rep(_, m) {
int u, v;
cin >> u >> v;
u--, v--;
to[u].emplace_back(v);
to[v].emplace_back(u);
}
vector<pair<map<int, mint>, mint>> dp(n);
mint ans;
dsu uf(n);
rep(v, n) {
dp[v].first[v] = 1;
int vl = v;
for (int u : to[v]) if (u < v) {
int ul = uf.leader(u);
if (ul == vl) continue;
if (dp[ul].first.size() > dp[vl].first.size()) {
swap(dp[ul], dp[vl]);
}
for (auto [i, c] : dp[ul].first) {
auto it = dp[vl].first.find(i);
if (it == dp[vl].first.end()) dp[vl].first[i] = c + dp[ul].second - dp[vl].second;
else {
it->second += c + dp[ul].second;
}
}
// if (v == 2) exit(0);
dp[ul].first.clear();
int l = uf.merge(ul, vl);
if (vl != l) {
dp[l] = move(dp[vl]);
vl = l;
}
}
mint val = dp[vl].first[v] + dp[vl].second;
ans += val;
// cout << v << ' ' << val.val() << endl;
for (int u : to[v]) if (u > v) {
auto it = dp[vl].first.find(u);
if (it == dp[vl].first.end()) dp[vl].first[u] = -dp[vl].second;
}
dp[vl].second += val;
// if (v == 1) cout << (dp[vl].first[2] + dp[vl].second).val() << endl, exit(0);
}
cout << ans.val() << '\n';
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0