結果

問題 No.1790 Subtree Deletion
ユーザー shiroha_F14shiroha_F14
提出日時 2021-12-10 14:01:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,310 bytes
コンパイル時間 2,208 ms
コンパイル使用メモリ 178,760 KB
実行使用メモリ 5,948 KB
最終ジャッジ日時 2023-10-13 18:16:21
合計ジャッジ時間 7,039 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

vector<bool> visited(50000, false);
vector<int> parent(50000, -1);
vector<vector<pair<int, ll>>> g(50000);

void dfs(int p, vector<ll>& f){
  if(visited[p]) return;
  visited[p] = true;

  for(auto v : g[p]){
    if(visited[v.first]) continue;
    parent[v.first] = p;
    dfs(v.first, f);
    f[p] ^= f[v.first];
    f[p] ^= v.second;
  }
}

int main(){
  int n; cin >> n;
  assert(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(a <= 1000000000000000000);
    g[l - 1].push_back({r - 1, a});
    g[r - 1].push_back({l - 1, a});
  }

  vector<ll> f(n, 0);

  dfs(0, f);
  
  queue<ll> anslist;

  int q; cin >> q;
  assert(q <= 50000);
  for(int i = 0; i < q; i++){
    int t, x, y; cin >> t >> x >> y;
    assert(t == 1 || t == 2);
    if(t == 1){
      assert(2 <= x && x <= n);
      assert(1 <= y && y <= n);
      assert(x != y);
      x--, y--;
      f[parent[x]] ^= f[x];
      f[y] ^= f[x];
      parent[x] = y;
    }else{
      assert(1 <= x && x <= n);
      assert(y == 0);
      anslist.push(f[x - 1]);
    }
  }

  while(!anslist.empty()){
    cout << anslist.front() << endl;
    anslist.pop();
  }

  return 0;
}
0