/*
ID: antwand1
TASK: barn1
LANG: C++
*/
#include <bits/stdc++.h>
#define ll long long
#define du long double
#define F first
#define S second
using namespace std;
const int N=1e6+100;
vector<pair<int,int>> g[N];
int sz=1,mx=0;
bool ok[N];
void dfs(int u,int p,int we)
{
if(ok[u])mx=max(mx,we);
for(auto x:g[u]){
if(x.F!=p){
dfs(x.F,u,we^x.S);
}
}
}
void dfs2(int u,int p,int tar)
{
// cout<<u<<" "<<tar<<endl;
if(tar==u)tar=0;
if(tar==0)ok[u]=1;
for(auto x:g[u]){
if(x.F!=p){
dfs2(x.F,u,tar);
}
}
}
main()
{
//freopen("barn1.in","r",stdin);freopen("barn1.out","w",stdout);
int n;
cin>>n;
while(n--){
string s;
cin>>s;
if(s=="Add"){
sz++;
int a,b;
cin>>a>>b;
g[sz].push_back({a,b});
g[a].push_back({sz,b});
}
else{
for(int i=1;i<=sz;i++){
// cout<<i<<" :";
// for(auto x:g[i])cout<<x.F<<" ";cout<<endl;
}
int a,b;
cin>>a>>b;
for(int i=1;i<=sz;i++)ok[i]=0;
dfs2(1,1,b);
// for(int i=1;i<=sz;i++)cout<<ok[i]<<" ";cout<<endl;
mx=0;
dfs(a,a,0);
cout<<mx<<endl;
}
}
}
Compilation message
klasika.cpp:37:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main()
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
15 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23788 KB |
Output is correct |
8 |
Correct |
15 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
15 ms |
23788 KB |
Output is correct |
11 |
Correct |
15 ms |
23788 KB |
Output is correct |
12 |
Correct |
15 ms |
23788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
15 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23788 KB |
Output is correct |
8 |
Correct |
15 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
15 ms |
23788 KB |
Output is correct |
11 |
Correct |
15 ms |
23788 KB |
Output is correct |
12 |
Correct |
15 ms |
23788 KB |
Output is correct |
13 |
Correct |
26 ms |
23916 KB |
Output is correct |
14 |
Correct |
28 ms |
23916 KB |
Output is correct |
15 |
Correct |
26 ms |
23916 KB |
Output is correct |
16 |
Correct |
23 ms |
24044 KB |
Output is correct |
17 |
Correct |
27 ms |
24044 KB |
Output is correct |
18 |
Correct |
31 ms |
23916 KB |
Output is correct |
19 |
Correct |
30 ms |
23916 KB |
Output is correct |
20 |
Correct |
27 ms |
23916 KB |
Output is correct |
21 |
Correct |
27 ms |
23916 KB |
Output is correct |
22 |
Correct |
33 ms |
23916 KB |
Output is correct |
23 |
Correct |
31 ms |
23916 KB |
Output is correct |
24 |
Correct |
27 ms |
23916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5074 ms |
26484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
15 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23788 KB |
Output is correct |
8 |
Correct |
15 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
15 ms |
23788 KB |
Output is correct |
11 |
Correct |
15 ms |
23788 KB |
Output is correct |
12 |
Correct |
15 ms |
23788 KB |
Output is correct |
13 |
Correct |
26 ms |
23916 KB |
Output is correct |
14 |
Correct |
28 ms |
23916 KB |
Output is correct |
15 |
Correct |
26 ms |
23916 KB |
Output is correct |
16 |
Correct |
23 ms |
24044 KB |
Output is correct |
17 |
Correct |
27 ms |
24044 KB |
Output is correct |
18 |
Correct |
31 ms |
23916 KB |
Output is correct |
19 |
Correct |
30 ms |
23916 KB |
Output is correct |
20 |
Correct |
27 ms |
23916 KB |
Output is correct |
21 |
Correct |
27 ms |
23916 KB |
Output is correct |
22 |
Correct |
33 ms |
23916 KB |
Output is correct |
23 |
Correct |
31 ms |
23916 KB |
Output is correct |
24 |
Correct |
27 ms |
23916 KB |
Output is correct |
25 |
Execution timed out |
5074 ms |
26484 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |