結果

問題 No.1790 Subtree Deletion
ユーザー KudeKude
提出日時 2021-12-19 03:47:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,585 bytes
コンパイル時間 2,600 ms
コンパイル使用メモリ 228,532 KB
実行使用メモリ 20,984 KB
最終ジャッジ日時 2023-10-13 18:36:22
合計ジャッジ時間 8,392 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,928 KB
testcase_01 AC 4 ms
5,760 KB
testcase_02 AC 3 ms
5,720 KB
testcase_03 AC 106 ms
12,320 KB
testcase_04 AC 104 ms
12,524 KB
testcase_05 AC 104 ms
12,348 KB
testcase_06 AC 108 ms
12,336 KB
testcase_07 AC 109 ms
12,432 KB
testcase_08 AC 17 ms
5,772 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

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 ull = unsigned long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

constexpr int MX = 100000;
vector<pair<int, ull>> g[MX];
int in_time[MX], out_time[MX];
ull a_par[MX];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  rep(i, n - 1) {
    int l, r;
    ull a;
    cin >> l >> r >> a;
    l--;
    r--;
    g[l].emplace_back(r, a);
    g[r].emplace_back(l, a);
  }
  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);
  int q;
  cin >> q;
  rep(_, q) {
    int t, x;
    cin >> t >> x;
    x--;
    if (t == 1) {
      int l = in_time[x], r = out_time[x];
      memset(&a_par[l], 0, sizeof(ull) * (r - l));
    } else {
      ull ans = 0;
      int l = in_time[x] + 1, r = out_time[x];
      assert(0 <= l && l <= r && r <= MX);
      for(int i = l; i < r; i++) ans ^= a_par[i];
      cout << ans << '\n';
    }
  }
}
0