#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 200005;
int N, Q;
int A[MAXN]; // Initial state of lights
vector<int> adj[MAXN]; // Adjacency list for the tree
int in[MAXN], out[MAXN], euler[MAXN]; // Euler Tour data
int segTree[4 * MAXN], lazy[4 * MAXN]; // Segment tree and lazy array
int timer = 0;
// DFS to perform Euler Tour
void dfs(int node, int parent) {
in[node] = ++timer;
euler[timer] = A[node];
for (int neighbor : adj[node]) {
if (neighbor != parent) {
dfs(neighbor, node);
}
}
out[node] = timer;
}
// Segment tree build
void build(int node, int start, int end) {
if (start == end) {
segTree[node] = euler[start];
} else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
segTree[node] = segTree[2 * node] + segTree[2 * node + 1];
}
}
// Propagate lazy values
void propagate(int node, int start, int end) {
if (lazy[node]) {
segTree[node] = (end - start + 1) - segTree[node]; // Toggle
if (start != end) {
lazy[2 * node] ^= 1;
lazy[2 * node + 1] ^= 1;
}
lazy[node] = 0;
}
}
// Update range with lazy propagation
void update(int node, int start, int end, int l, int r) {
propagate(node, start, end);
if (start > r || end < l)
return;
if (start >= l && end <= r) {
lazy[node] ^= 1;
propagate(node, start, end);
return;
}
int mid = (start + end) / 2;
update(2 * node, start, mid, l, r);
update(2 * node + 1, mid + 1, end, l, r);
segTree[node] = segTree[2 * node] + segTree[2 * node + 1];
}
// Query range with lazy propagation
int query(int node, int start, int end, int l, int r) {
propagate(node, start, end);
if (start > r || end < l)
return 0;
if (start >= l && end <= r)
return segTree[node];
int mid = (start + end) / 2;
return query(2 * node, start, mid, l, r) + query(2 * node + 1, mid + 1, end, l, r);
}
int main() {
// Input reading
cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> A[i];
}
for (int i = 0; i < N - 1; ++i) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
// DFS to flatten the tree
dfs(1, -1);
// Build the segment tree
build(1, 1, N);
cin >> Q;
while (Q--) {
int type, K;
cin >> type >> K;
if (type == 1) {
// Toggle the lights in the subtree of K
update(1, 1, N, in[K], out[K]);
} else if (type == 2) {
// Count the lights on in the subtree of K
cout << query(1, 1, N, in[K], out[K]) << '\n';
}
}
return 0;
}