結果

問題 No.1790 Subtree Deletion
ユーザー KudeKude
提出日時 2021-12-19 03:37:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,632 bytes
コンパイル時間 3,729 ms
コンパイル使用メモリ 235,700 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2023-10-13 18:36:05
合計ジャッジ時間 6,672 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

ll op(ll x, ll y) { return x ^ y; }
ll e() { return 0; }
bool compositoin(bool f, bool g) { return f && g; }
bool id() { return true; }
ll mapping(bool f, ll x) { return f * x; }

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<pair<int, ll>>> g(n);
  rep(i, n - 1) {
    int l, r;
    ll a;
    cin >> l >> r >> a;
    l--;
    r--;
    g[l].emplace_back(r, a);
    g[r].emplace_back(l, a);
  }
  VI in_time(n), out_time(n);
  VL a_par(n);
  int time = 0;
  auto dfs = [&](auto self, int u, int p) -> void {
    in_time[u] = time;
    time++;
    for(auto [v, a] : g[u]) {
      if (v != p) {
        a_par[time] = a;
        self(self, v, u);
      }
    }
    out_time[u] = time;
  };
  dfs(dfs, 0, -1);
  lazy_segtree<ll, op, e, bool, mapping, compositoin, id> seg(a_par);
  int q;
  cin >> q;
  rep(_, q) {
    int t, x;
    cin >> t >> x;
    x--;
    if (t == 1) {
      seg.apply(in_time[x], out_time[x], false);
    } else {
      int ans = seg.prod(in_time[x] + 1, out_time[x]);
      cout << ans << '\n';
    }
  }
}
0