#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
klasika.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
70740 KB |
Output is correct |
2 |
Correct |
33 ms |
70848 KB |
Output is correct |
3 |
Correct |
32 ms |
70992 KB |
Output is correct |
4 |
Correct |
33 ms |
71240 KB |
Output is correct |
5 |
Correct |
31 ms |
70752 KB |
Output is correct |
6 |
Correct |
32 ms |
70720 KB |
Output is correct |
7 |
Correct |
34 ms |
70696 KB |
Output is correct |
8 |
Correct |
37 ms |
70724 KB |
Output is correct |
9 |
Correct |
35 ms |
70740 KB |
Output is correct |
10 |
Correct |
31 ms |
70748 KB |
Output is correct |
11 |
Correct |
32 ms |
70740 KB |
Output is correct |
12 |
Correct |
31 ms |
70868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
70740 KB |
Output is correct |
2 |
Correct |
33 ms |
70848 KB |
Output is correct |
3 |
Correct |
32 ms |
70992 KB |
Output is correct |
4 |
Correct |
33 ms |
71240 KB |
Output is correct |
5 |
Correct |
31 ms |
70752 KB |
Output is correct |
6 |
Correct |
32 ms |
70720 KB |
Output is correct |
7 |
Correct |
34 ms |
70696 KB |
Output is correct |
8 |
Correct |
37 ms |
70724 KB |
Output is correct |
9 |
Correct |
35 ms |
70740 KB |
Output is correct |
10 |
Correct |
31 ms |
70748 KB |
Output is correct |
11 |
Correct |
32 ms |
70740 KB |
Output is correct |
12 |
Correct |
31 ms |
70868 KB |
Output is correct |
13 |
Correct |
67 ms |
74912 KB |
Output is correct |
14 |
Correct |
145 ms |
86808 KB |
Output is correct |
15 |
Correct |
188 ms |
106952 KB |
Output is correct |
16 |
Correct |
255 ms |
131548 KB |
Output is correct |
17 |
Correct |
40 ms |
70900 KB |
Output is correct |
18 |
Correct |
43 ms |
71036 KB |
Output is correct |
19 |
Correct |
54 ms |
71264 KB |
Output is correct |
20 |
Correct |
43 ms |
71492 KB |
Output is correct |
21 |
Correct |
42 ms |
71408 KB |
Output is correct |
22 |
Correct |
58 ms |
73428 KB |
Output is correct |
23 |
Correct |
71 ms |
76908 KB |
Output is correct |
24 |
Correct |
93 ms |
81624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5061 ms |
438548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
70740 KB |
Output is correct |
2 |
Correct |
33 ms |
70848 KB |
Output is correct |
3 |
Correct |
32 ms |
70992 KB |
Output is correct |
4 |
Correct |
33 ms |
71240 KB |
Output is correct |
5 |
Correct |
31 ms |
70752 KB |
Output is correct |
6 |
Correct |
32 ms |
70720 KB |
Output is correct |
7 |
Correct |
34 ms |
70696 KB |
Output is correct |
8 |
Correct |
37 ms |
70724 KB |
Output is correct |
9 |
Correct |
35 ms |
70740 KB |
Output is correct |
10 |
Correct |
31 ms |
70748 KB |
Output is correct |
11 |
Correct |
32 ms |
70740 KB |
Output is correct |
12 |
Correct |
31 ms |
70868 KB |
Output is correct |
13 |
Correct |
67 ms |
74912 KB |
Output is correct |
14 |
Correct |
145 ms |
86808 KB |
Output is correct |
15 |
Correct |
188 ms |
106952 KB |
Output is correct |
16 |
Correct |
255 ms |
131548 KB |
Output is correct |
17 |
Correct |
40 ms |
70900 KB |
Output is correct |
18 |
Correct |
43 ms |
71036 KB |
Output is correct |
19 |
Correct |
54 ms |
71264 KB |
Output is correct |
20 |
Correct |
43 ms |
71492 KB |
Output is correct |
21 |
Correct |
42 ms |
71408 KB |
Output is correct |
22 |
Correct |
58 ms |
73428 KB |
Output is correct |
23 |
Correct |
71 ms |
76908 KB |
Output is correct |
24 |
Correct |
93 ms |
81624 KB |
Output is correct |
25 |
Execution timed out |
5061 ms |
438548 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |