#include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) namespace rq{ u64 op(u64 a, u64 b){ return a^b; } u64 e(){ return 0; } using rq = atcoder::segtree; } struct Edge{ int u,v; u64 a; }; int N; vector edges; vector> E; vector A; vector I; vector depth; vector in_time; vector out_time; vector out_time_from_in; void dfs(int p = 0, int pre = -1){ in_time[p] = I.size(); I.push_back(p); for(int e : E[p]) if(e != pre){ depth[e] = depth[p] + 1; dfs(e,p); } out_time[p] = I.size(); } rq::rq sum_A; vector erase_visited; int Q; int main() { cin >> N; edges.resize(N-1); E.resize(N); rep(i,N-1){ int u,v; cin >> u >> v; u--; v--; u64 a; cin >> a; edges[i] = {u,v,a}; E[u].push_back(v); E[v].push_back(u); } depth.assign(N, 0); in_time.assign(N, 0); out_time.assign(N, 0); out_time_from_in.resize(N); rep(i,N) out_time_from_in[in_time[i]] = out_time[i]; dfs(); E.clear(); E.resize(N); A.assign(N, 0); for(auto e : edges){ if(depth[e.u] > depth[e.v]) swap(e.u, e.v); A[e.v] = e.a; E[e.u].push_back(e.v); } erase_visited.assign(N, 0); vector sum_A_tmp(N, 0); rep(i,N) sum_A_tmp[in_time[i]] = A[i]; sum_A = rq::rq(sum_A_tmp); cin >> Q; rep(queryid, Q){ int t; cin >> t; if(t == 1){ int x; cin >> x; x--; for(int p=in_time[x]; p> x; x--; int l = in_time[x] + 1; int r = out_time[x]; u64 ans = sum_A.prod(l,r); cout << ans << "\n"; } } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;