結果
| 問題 |
No.1790 Subtree Deletion
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-12-30 17:32:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,289 bytes |
| コンパイル時間 | 1,770 ms |
| コンパイル使用メモリ | 129,336 KB |
| 最終ジャッジ日時 | 2025-01-27 07:40:19 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | WA * 12 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/segtree>
#include <atcoder/lazysegtree>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
return vector<vector<T>>(n, vector<T>(m, v));
}
template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}
template<typename T>
void print_vector(vector<T> 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;
ll a;
};
/**
* 変数の意味は概ね[maspyさんの記事](https://maspypy.com/euler-tour-%E3%81%AE%E3%81%8A%E5%8B%89%E5%BC%B7#toc1)に準じています(ありがとうございます)
*/
class EulerTour{
public:
vector<vector<edge>> g;
int root;
int n;
vector<int> as;
vector<int> ord;
vector<int> in, out;
EulerTour(vector<vector<edge>> g, int root): g(g), root(root){
n = g.size();
in.resize(n);
out.resize(n);
build();
}
private:
void build(){
vector<bool> seen(n, false);
dfs(0, seen);
}
void dfs(int v, vector<bool> &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);
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; }
ll id(){ return -1; }
int mapping(ll l, int r) {
if (l == id()) return r;
return 0;
}
ll composition(ll l, ll r) {
if(l == id()) return r;
if(r == id()) return l;
return 0;
}
using Seg = atcoder::lazy_segtree<int, op, e, ll, mapping, composition, id>;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int n; cin >> n;
vector<vector<edge>> g(n);
for(int i = 0; i < n-1; i++){
int l, r; ll 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){
seg.apply(l-1, r, 0);
}else{
cout << seg.prod(l, r) << endl;
}
}
}
milanis48663220