#include #include using namespace std; using namespace atcoder; const int64_t INF = 1E18 + 7; int64_t op(int64_t u, int64_t v) { return min(u, v); } int64_t e() { return INF; } int64_t mapping(int64_t s, int64_t e) { return s + e; } int64_t compose(int64_t s, int64_t e) { return s + e; } int64_t id() { return 0; } bool f(int64_t v) { return v > 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; vector>> adj(n); for (int i = 1; i < n; i++) { int u, v; int64_t c; cin >> u >> v >> c; u--; v--; adj[u].push_back({v, c}); adj[v].push_back({u, c}); } vector in(n), rt = {0}, col(n), pat, par(n); lazy_segtree seg(n); { // HLD vector sub(n); vector> mc(n, {-1, 0}); function DFS = [&](int u, int p) { par[u] = p; sub[u] = 1; if (u != 0) { adj[u].erase(lower_bound(adj[u].begin(), adj[u].end(), pair(p, 0L))); } for (auto [v, c] : adj[u]) { DFS(v, u); sub[u] += sub[v]; if (mc[u].first == -1 || sub[v] > sub[mc[u].first]) { mc[u] = {v, c}; } } }; DFS(0, -1); int tot = 0, pos = 0; function DFS_2 = [&](int u, int64_t w) { col[u] = tot; pat.push_back(u); in[u] = pos++; seg.set(in[u], w); if (mc[u].first != -1) { DFS_2(mc[u].first, mc[u].second); } for (auto [v, c] : adj[u]) { if (v != mc[u].first) { tot++; rt.push_back(v); DFS_2(v, c); } } }; DFS_2(0, INF); }; vector off(n); vector cur(n); int ans = n; auto update = [&](int u, int64_t x) { cur[u] += x; while (u != -1) { seg.apply(in[rt[col[u]]], in[u] + 1, -x); u = par[rt[col[u]]]; } }; function remove_from_tree = [&](int u) { update(u, -cur[u]); ans--; off[u] = true; for (auto [v, _] : adj[u]) { if (!off[v]) { remove_from_tree(v); } } }; while (q--) { int t; cin >> t; if (t == 1) { int u, x; cin >> u >> x; u--; if (!off[u]) { update(u, x); } int l = seg.min_left(n, f); if (l != 0) { assert(!off[pat[l - 1]]); remove_from_tree(pat[l - 1]); } } else { cout << ans << '\n'; } } }