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>
#define int long long
#define F first
#define S second
#define T int t; cin >> t; while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 1e6 + 5;
const int M = 1e3 + 3;
const int inf = 1e18;
const int mod = 1e9 + 7;
int q, ans;
vector<pair<int, int>> adj[N];
set<int> st[N];
void dfs(int node, int from, int with, int b) {
if (st[node].find(b) != st[node].end())
ans = max(ans, with);
for(auto x: adj[node]) {
if (x.F != from)
dfs(x.F, node, with ^ x.S, b);
}
}
main() {
IOS
cin >> q;
int cnt = 1;
st[1].insert(1);
while(q--) {
string s;
int a, b;
cin >> s >> a >> b;
if (s[0] == 'A') {
adj[a].push_back({++cnt, b});
adj[cnt].push_back({a, b});
for(auto x: st[a]) st[cnt].insert(x);
st[cnt].insert(cnt);
}
else {
ans = 0;
dfs(a, 0, 0, b);
cout << ans << '\n';
}
}
}
Compilation message (stderr)
klasika.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main() {
| ^~~~
# | 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... |