loj144

#include <cstdio>
#define int long long
using namespace std;
#define N 1000005
int n, m, r, cnt, in[N], out[N], c[N], w[N];
inline int lowbit(int x) { return x & (-x); }
struct edge {
    int to, next;
} e[N << 1];
int head[N], tot;
inline void add(int u, int v) {
    e[++tot] = (edge){ v, head[u] };
    head[u] = tot;
}
void dfs(int u, int f) {
    in[u] = ++cnt;
    for (int i = head[u]; i; i = e[i].next) {
        int v = e[i].to;
        if (v == f)
            continue;
        dfs(v, u);
    }
    out[u] = cnt;
}
inline void update(int x, int a) {
    for (; x <= n; x += lowbit(x)) c[x] += a;
}
inline int ask(int x) {
    int ans = 0;
    for (; x; x -= lowbit(x)) ans += c[x];
    return ans;
}
signed main() {
    scanf("%lld%lld%lld", &n, &m, &r);
    int op, u, v;
    for (int i = 1; i <= n; ++i) scanf("%lld", &w[i]);
    for (int i = 1; i < n; ++i) {
        scanf("%lld%lld", &u, &v);
        add(u, v);
        add(v, u);
    }
    dfs(r, 0);
    for (int i = 1; i <= n; ++i) update(in[i], w[i]);
    while (m--) {
        scanf("%lld%lld", &op, &u);
        if (op == 1) {
            scanf("%lld", &v);
            update(in[u], v);
        } else
            printf("%lld\n", ask(out[u]) - ask(in[u] - 1));
    }
}

posted @ 2020-09-13 10:51  INFP  阅读(103)  评论(0编辑  收藏  举报