#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pair<int,int>>
#define vll vector<pair<long long,long long>>
#define pb push_back
#define ll long long
#define ld long double
#define nl '\n'
#define boost ios::sync_with_stdio(false)
#define mp make_pair
#define se second
#define fi first
#define fore(i, y) for(int i = 0; i < y; i++)
#define forr(i,x,y) for(int i = x;i<=y;i++)
#define forn(i,y,x) for(int i = y; i >= x; i--)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define clr(v,k) memset(v,k,sizeof(v))
#define rall(v) v.rbegin() , v.rend()
#define pii pair<int,int>
#define pll pair<ll , ll>
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 1;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return a * (b / gcd(a , b));} // least common multiple (PPCM)
// HERE IS THE SOLUTION
const int N = 2000;
vector<vii> adj(N + 1);
int k;
set<int> v;
bool ins = 0;
bool quit = 0;
int path = 0 , best = 0;
void dfs(int i , int par)
{
if(quit)return;
if(i == k)
{
ins = 1;
}
if(ins)
v.insert(i);
for(auto u : adj[i])
{
if(u.fi == par)continue;
dfs(u.fi , i);
}
if(i == k)
quit = 1;
}
void dfs1(int i , int par)
{
for(auto u : adj[i])
{
if(u.fi == par)continue;
path^=u.se;
if(v.count(u.fi))
best = max(best , path);
dfs1(u.fi , i);
path^=u.se;
}
}
int query(int a , int b)
{
v.clear();
quit = 0 , ins = 0;
k = b;
dfs(0 , -1);
path = 0 , best = 0;
dfs1(a , -1);
return best;
}
int main()
{
cin.tie(0);
cout.tie(0);
boost;
// freopen("inp.txt" , "r" , stdin);
int q;
cin>>q;
int cnt = 0;
while(q--)
{
string s;
cin>>s;
int x , y;
cin>>x>>y;
x--;
if(s == "Add")
{
adj[x].pb({cnt + 1 , y});
adj[cnt + 1].pb({x , y});
cnt++;
}
else
{
y--;
cout<<query(x , y)<<nl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
16 ms |
412 KB |
Output is correct |
14 |
Correct |
31 ms |
428 KB |
Output is correct |
15 |
Correct |
31 ms |
424 KB |
Output is correct |
16 |
Correct |
22 ms |
532 KB |
Output is correct |
17 |
Correct |
8 ms |
404 KB |
Output is correct |
18 |
Correct |
11 ms |
340 KB |
Output is correct |
19 |
Correct |
10 ms |
396 KB |
Output is correct |
20 |
Correct |
8 ms |
424 KB |
Output is correct |
21 |
Correct |
9 ms |
404 KB |
Output is correct |
22 |
Correct |
14 ms |
424 KB |
Output is correct |
23 |
Correct |
16 ms |
380 KB |
Output is correct |
24 |
Correct |
10 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
893 ms |
1184 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
16 ms |
412 KB |
Output is correct |
14 |
Correct |
31 ms |
428 KB |
Output is correct |
15 |
Correct |
31 ms |
424 KB |
Output is correct |
16 |
Correct |
22 ms |
532 KB |
Output is correct |
17 |
Correct |
8 ms |
404 KB |
Output is correct |
18 |
Correct |
11 ms |
340 KB |
Output is correct |
19 |
Correct |
10 ms |
396 KB |
Output is correct |
20 |
Correct |
8 ms |
424 KB |
Output is correct |
21 |
Correct |
9 ms |
404 KB |
Output is correct |
22 |
Correct |
14 ms |
424 KB |
Output is correct |
23 |
Correct |
16 ms |
380 KB |
Output is correct |
24 |
Correct |
10 ms |
468 KB |
Output is correct |
25 |
Runtime error |
893 ms |
1184 KB |
Execution killed with signal 11 |
26 |
Halted |
0 ms |
0 KB |
- |