結果

問題 No.1790 Subtree Deletion
ユーザー shiroha_F14shiroha_F14
提出日時 2021-12-10 13:53:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,011 bytes
コンパイル時間 3,330 ms
コンパイル使用メモリ 177,148 KB
実行使用メモリ 15,208 KB
最終ジャッジ日時 2023-10-13 18:16:31
合計ジャッジ時間 8,898 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 WA -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 WA -
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(200000, false);
vector<int> parent(200000, -1);
vector<vector<pair<int, ll>>> g(200000);

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;
  
  for(int i = 0; i < n - 1; i++){
    int l, r; cin >> l >> r;
    ll a; cin >> a;
    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;
  for(int i = 0; i < q; i++){
    int t, x, y; cin >> t >> x >> y;
    if(t == 1){
      x--, y--;
      f[parent[x]] ^= f[x];
      f[y] ^= f[x];
      parent[x] = y;
    }else{
      anslist.push(f[x - 1]);
    }
  }

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

  return 0;
}
0