/
1790.test.cpp
53 lines (47 loc) · 1.05 KB
/
1790.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
#define PROBLEM "https://yukicoder.me/problems/no/1790"
#include "my_template.hpp"
#include "other/io.hpp"
#include "alg/monoid/xor.hpp"
#include "alg/monoid/max.hpp"
#include "graph/ds/lazy_tree_monoid.hpp"
struct ActedMonoid {
using Monoid_X = Monoid_Xor<ll>;
using Monoid_A = Monoid_Max<int>;
using X = typename Monoid_X::value_type;
using A = typename Monoid_A::value_type;
static constexpr X act(const X &x, const A &a, const ll &size) {
if (a == Monoid_A::unit()) return x;
return 0;
}
};
void solve() {
LL(N);
Graph<int, 0> G(N);
vc<ll> dat;
FOR(N - 1) {
LL(a, b, x);
--a, --b;
G.add(a, b);
dat.eb(x);
}
G.build();
Tree<decltype(G)> tree(G);
Lazy_Tree_Monoid<decltype(tree), ActedMonoid, 1> X(tree, dat);
LL(Q);
FOR(Q) {
LL(t, x);
--x;
if (t == 2) { print(X.prod_subtree(x)); }
if (t == 1) {
X.apply_subtree(x, 0);
if (x) X.apply_path(x, tree.parent[x], 0);
}
}
}
signed main() {
cout << fixed << setprecision(15);
ll T = 1;
// LL(T);
FOR(T) solve();
return 0;
}