Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"./template/headers.hpp"
- //#define MULTI_TASKCASE
- using namespace abb;
- using namespace output;
- using namespace rit;
- using namespace wit;
- inline void init() {
- }
- inline void solve() {
- int n;
- while (cin >> n) {
- V<V<int>> edge(n);
- for (int i = 1; i < n; i++) {
- static int a, b; fin >> a >> b;
- edge[a].emplace_back(b);
- edge[b].emplace_back(a);
- }
- int t = 0;
- V<P<int>> lr(n);
- F<void(int, int)> dfs = [&](int cur, int pre) {
- lr[cur].first = t++;
- for (const auto& i : edge[cur])
- if (i != pre) dfs(i, cur);
- lr[cur].second = t;
- }; dfs(0, 0);
- V<ll> bit(t + 1, 0);
- auto lowbit = [](int x) {return x & -x;};
- auto increase = [&](int p, int x) {
- p++;
- while (p <= t)
- bit[p] += x, p += lowbit(p);
- };
- auto presum = [&](int p) {
- p++;
- int ret = 0;
- while (p > 0)
- ret += bit[p], p -= lowbit(p);
- return ret;
- };
- int m; fin >> m;
- while (m--) {
- static int p, x; fin >> p >> x;
- increase(lr[p].first, x);
- increase(lr[p].second, -x);
- cout << presum(lr[p].first) << endl;
- }
- }
- }
- main() {
- ios::sync_with_stdio(false);
- init();
- int t = 1;
- #ifdef MULTI_TASKCASE
- cin >> t; cin.ignore();
- #endif
- while (t--) solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement