This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
#define trav(a, b) for(auto a : b)
#define v vector
#define vl vector<ll>
#define mk make_pair
#define f first
#define s second
using namespace std;
vector<pair<int, int>> adj[2000];
int vis[2000];
int crr;
void ff(int x, int pr, bool flag){
if(x == crr)flag = true;
if(flag){
vis[x] = 1;
}
trav(e, adj[x]){
if(e.f != pr)ff(e.f, x, flag);
}
}
int ans = 0;
void dfs(int x, int pr, int level){
if(vis[x])
ans = max(ans, level);
trav(e, adj[x]){
if(e.f != pr){
dfs(e.f, x, level ^ e.s);
}
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int q;
cin >> q;
string x;
int a, b, size = 1;
while(q --){
cin >> x >> a >> b;
if(x == "Add"){
adj[a - 1].push_back(mk(size, b));
adj[size].push_back(mk(a - 1, b));
size ++;
} else {
crr = b - 1;
for(int i = 0;i < size;i ++)vis[i] = 0;
ff(0, -1, false);
ans = 0;
dfs(a - 1, -1, 0);
cout << ans << '\n';
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |