結果
| 問題 | No.1790 Subtree Deletion | 
| コンテスト | |
| ユーザー |  Nachia | 
| 提出日時 | 2021-12-10 20:37:09 | 
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) | 
| 結果 | 
                                TLE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 2,003 bytes | 
| コンパイル時間 | 2,918 ms | 
| コンパイル使用メモリ | 115,148 KB | 
| 最終ジャッジ日時 | 2025-01-26 07:29:19 | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 9 TLE * 3 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
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++)
struct Edge{ int u,v; u64 a; };
int N;
vector<Edge> edges;
vector<vector<int>> E;
vector<u64> A;
vector<int> I;
vector<int> depth;
vector<int> in_time;
vector<int> out_time;
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();
}
vector<u64> permute_A;
vector<int> erase_visited;
void erase_dfs(int p){
    if(erase_visited[p]) return;
    erase_visited[p] = 1;
    permute_A[in_time[p]] = 0;
    for(int e : E[p]) erase_dfs(e);
}
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);
    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);
    permute_A.assign(N, 0);
    rep(i,N) permute_A[in_time[i]] = A[i];
    
    cin >> Q;
    rep(queryid, Q){
        int t; cin >> t;
        if(t == 1){
            int x; cin >> x; x--;
            erase_dfs(x);
        }
        if(t == 2){
            int x; cin >> x; x--;
            int l = in_time[x] + 1;
            int r = out_time[x];
            u64 ans = 0;
            for(int i=l; i<r; i++) ans ^= permute_A[i];
            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;
            
            
            
        