結果
| 問題 |
No.1790 Subtree Deletion
|
| コンテスト | |
| ユーザー |
shiroha_F14
|
| 提出日時 | 2021-12-10 13:53:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,011 bytes |
| コンパイル時間 | 1,835 ms |
| コンパイル使用メモリ | 179,528 KB |
| 実行使用メモリ | 15,392 KB |
| 最終ジャッジ日時 | 2024-09-15 14:05:45 |
| 合計ジャッジ時間 | 7,898 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 3 RE * 9 |
ソースコード
#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;
}
shiroha_F14