#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } struct edge{ int to, a; }; /** * 変数の意味は概ね[maspyさんの記事](https://maspypy.com/euler-tour-%E3%81%AE%E3%81%8A%E5%8B%89%E5%BC%B7#toc1)に準じています(ありがとうございます) */ class EulerTour{ public: vector> g; int root; int n; vector par; vector as; vector ord; vector in, out; EulerTour(vector> g, int root): g(g), root(root){ n = g.size(); par.resize(n); in.resize(n); out.resize(n); build(); } private: void build(){ vector seen(n, false); dfs(0, seen); } void dfs(int v, vector &seen){ seen[v] = true; in[v] = ord.size(); ord.push_back(v); int cnt = 0; for(auto [to, a]: g[v]){ if(seen[to]) continue; as.push_back(a); par[to] = v; dfs(to, seen); as.push_back(0); cnt++; } if(cnt > 0) { out[v] = ord.size(); ord.push_back(v); }else{ out[v] = ord.size()-1; } } }; int op(int a, int b){ return a^b; } int e(){ return 0; } int id(){ return -1; } int mapping(int l, int r) { if (l == id()) return r; return 0; } int composition(int l, int r) { if(l == id()) return r; if(r == id()) return l; return 0; } using Seg = atcoder::lazy_segtree; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector> g(n); for(int i = 0; i < n-1; i++){ int l, r, a; cin >> l >> r >> a; l--; r--; g[l].push_back(edge{r, a}); g[r].push_back(edge{l, a}); } auto et = EulerTour(g, 0); Seg seg(et.as); int q; cin >> q; while(q--){ int t, x; cin >> t >> x; x--; int l = et.in[x], r = et.out[x]; if(t == 1){ // cout << l << ' ' << r << endl; seg.apply(l-1, r, 0); }else{ cout << seg.prod(l, r) << endl; } } }