結果
| 問題 |
No.1790 Subtree Deletion
|
| コンテスト | |
| ユーザー |
shiroha_F14
|
| 提出日時 | 2021-12-10 19:45:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,937 bytes |
| コンパイル時間 | 1,909 ms |
| コンパイル使用メモリ | 181,564 KB |
| 実行使用メモリ | 8,064 KB |
| 最終ジャッジ日時 | 2024-09-15 14:05:59 |
| 合計ジャッジ時間 | 4,678 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 RE * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/lazysegtree>
using namespace atcoder;
using ll = long long;
// Euler Tour
vector<int> vis;
vector<ll> edges(1, 0);
vector<vector<pair<int, ll>>> g(50000);
vector<int> in(50000);
vector<int> out(50000);
vector<int> seen(50000, false);
int t = 0;
void dfs(int p){
in[p] = t;
t++;
vis.push_back(p);
seen[p] = true;
for(auto v : g[p]){
if(seen[v.first]) continue;
edges.push_back(v.second);
dfs(v.first);
vis.push_back(p);
edges.push_back(0);
}
t++;
out[p] = t;
}
// lazy segtree
ll ID = 8000000000000000000;
ll op(ll a, ll b){
return a ^ b;
}
ll e(){
return 0;
}
ll mapping(ll f, ll x){
if(f == ID){
return x;
}else{
return f;
}
}
ll composition(ll f, ll g){
if(f == ID){
return g;
}else{
return f;
}
}
ll id(){
return ID;
}
// main
int main(){
int n; cin >> n;
assert(2 <= n && n <= 50000);
for(int i = 0; i < n - 1; i++){
int l, r; cin >> l >> r;
assert(1 <= l && l <= n && 1 <= r && r <= n);
ll a; cin >> a;
assert(0 <= a && a <= 1000000000000000000);
g[l - 1].push_back({r - 1, a});
g[r - 1].push_back({l - 1, a});
}
vis.reserve(n * 2);
edges.reserve(n * 2);
dfs(0);
edges.push_back(0);
int m = vis.size();
lazy_segtree<ll, op, e, ll, mapping, composition, id> seg(edges);
int q; cin >> q;
assert(1 <= q && q <= 50000);
for(int i = 0; i < q; i++){
int t; cin >> t;
assert(t == 1 || t == 2);
int x; cin >> x;
if(t == 1){
// delete
assert(2 <= x && x <= n);
seg.apply(in[x - 1], out[x - 1], 0);
}else{
// f(x)
assert(1 <= x && x <= n);
cout << seg.prod(in[x - 1] + 1, out[x - 1]) << endl;
}
}
}
shiroha_F14