#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e3 + 5;
int newnode = 2;
vector < pair < int , int > > graph[N],child[N];
vector < int > possible;
int find_x(int node , int past , int x){
if(node == x)return 0;
int ret = -1;
for(auto itr : graph[node]){
if(itr.first == past)continue;
int cand = find_x(itr.first , node , x);
if(cand != -1)ret = cand ^ itr.second;
}
return ret;
}
void vectorize(int node , int zor){
//cout << "vectorize : " << node << " " << zor << " / ";for(auto itr : child[node])cout << itr.first << "-" << itr.second << " ";cout << endl;
possible.push_back(zor);
for(auto itr : child[node]){
vectorize(itr.first,zor ^ itr.second);
}
}
void add(int x , int y){
graph[x].push_back({newnode,y});
graph[newnode].push_back({x,y});
child[x].push_back({newnode,y});
newnode++;
}
int query(int a , int b){
int n1 = find_x(a,0,b);
possible.clear();
vectorize(b,0);
//cout << "n1 : " << n1 << endl;
//cout << "possible : ";for(auto itr : possible)cout << itr << " ";cout << endl;
int ans = 0;
for(auto itr : possible){
ans = max(ans , n1 ^ itr);
}
return ans;
}
void solve(){
int q;cin >> q;
while(q--){
string typ;cin >> typ;
int q1,q2;cin >> q1 >> q2;
if(typ == "Add"){
add(q1,q2);
}
else{
cout << query(q1,q2) << endl;
}
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
5 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
648 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
600 KB |
Output is correct |
17 |
Correct |
5 ms |
856 KB |
Output is correct |
18 |
Correct |
6 ms |
604 KB |
Output is correct |
19 |
Correct |
6 ms |
604 KB |
Output is correct |
20 |
Correct |
5 ms |
604 KB |
Output is correct |
21 |
Correct |
5 ms |
348 KB |
Output is correct |
22 |
Correct |
6 ms |
604 KB |
Output is correct |
23 |
Correct |
6 ms |
604 KB |
Output is correct |
24 |
Correct |
5 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
115 ms |
1400 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
5 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
648 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
600 KB |
Output is correct |
17 |
Correct |
5 ms |
856 KB |
Output is correct |
18 |
Correct |
6 ms |
604 KB |
Output is correct |
19 |
Correct |
6 ms |
604 KB |
Output is correct |
20 |
Correct |
5 ms |
604 KB |
Output is correct |
21 |
Correct |
5 ms |
348 KB |
Output is correct |
22 |
Correct |
6 ms |
604 KB |
Output is correct |
23 |
Correct |
6 ms |
604 KB |
Output is correct |
24 |
Correct |
5 ms |
604 KB |
Output is correct |
25 |
Runtime error |
115 ms |
1400 KB |
Execution killed with signal 11 |
26 |
Halted |
0 ms |
0 KB |
- |