/
abc269ex.test.cpp
57 lines (49 loc) · 1.12 KB
/
abc269ex.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
#define PROBLEM "https://atcoder.jp/contests/abc269/tasks/abc269_Ex"
#include "my_template.hpp"
#include "other/io.hpp"
#include "graph/base.hpp"
#include "graph/tree.hpp"
#include "poly/convolution_all.hpp"
#include "poly/sum_of_prefix_suffix_products.hpp"
using mint = modint998;
void solve() {
LL(N);
Graph<int, 1> G(N);
FOR(v, 1, N) {
LL(p);
--p;
G.add(p, v);
}
G.build();
Tree<decltype(G)> tree(G);
using poly = vc<mint>;
auto dfs = [&](auto& dfs, int v) -> vc<mint> {
auto P = tree.heavy_path_at(v);
int n = len(P);
vc<poly> F(n);
FOR(i, n) {
int a = P[i];
vc<poly> polys;
for (auto&& e: G[a]) {
if (tree.head[e.to] == v) continue;
polys.eb(dfs(dfs, e.to));
}
F[i] = convolution_all(polys);
}
vc<poly> G(n);
FOR(i, n) G[i] = {mint(1)};
G.back() = {mint(0), mint(1)};
return sum_of_prefix_suffix_products(F, G);
};
auto f = dfs(dfs, 0);
f.erase(f.begin());
f.resize(N);
for (auto&& x: f) print(x);
}
signed main() {
cout << fixed << setprecision(15);
ll T = 1;
// LL(T);
FOR(T) solve();
return 0;
}