/
yuki-2588.test.cpp
71 lines (65 loc) · 1.61 KB
/
yuki-2588.test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#define PROBLEM "https://yukicoder.me/problems/no/2588"
//
#include "../../template/template.hpp"
//
#include "../../data-structure/union-find.hpp"
#include "../../segment-tree/segment-tree.hpp"
#include "../../tree/auxiliary-tree.hpp"
#include "../../tree/heavy-light-decomposition.hpp"
#include "../../tree/tree-query.hpp"
//
#include "../../modint/montgomery-modint.hpp"
#include "../../modulo/binomial.hpp"
//
using namespace Nyaan;
using mint = LazyMontgomeryModInt<998244353>;
// using mint = LazyMontgomeryModInt<1000000007>;
using vm = vector<mint>;
using vvm = vector<vm>;
Binomial<mint> C;
using namespace Nyaan;
void q() {
inl(N, M);
auto G = graph(N, M);
vvi g(N);
{
vi mx = mkiota(N);
UnionFind uf(N);
rep(i, N) each(j, G[i]) {
if (j < i and !uf.same(i, j)) {
int k = mx[uf.find(j)];
g[i].push_back(k);
g[k].push_back(i);
uf.unite(i, k);
mx[uf.find(i)] = i;
}
}
}
HeavyLightDecomposition hld(g, N - 1);
Tree tree(g, N - 1);
SegmentTree dp(
N, [](mint a, mint b) { return a + b; }, mint{});
AuxiliaryTree auxgen(g, N - 1);
rep(i, N) {
mint cur = 1;
vi chds;
chds.push_back(i);
each(j, G[i]) {
if (j < i) chds.push_back(j);
}
auto [aux, mp] = auxgen.get(chds);
rep(ii, sz(aux)) each(j, aux[ii]) {
int l = mp[ii], c = mp[j];
int nxt = tree.nxt(l, c);
hld.path_query(nxt, c, true,
[&](int u, int v) { cur += dp.query(u, v); });
}
dp.update(hld.idx(i).fi, cur);
}
out(dp.query(0, N));
}
void Nyaan::solve() {
int t = 1;
// in(t);
while (t--) q();
}