#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> >vps;
int cntdpth=1;
int ans=0;
int trg;
int slvmx(int cr=0,int dpth=1){
cntdpth=max(cntdpth,dpth);
int mx=-1;
if(vps[cr].first<0){
mx=max(mx,vps[cr].first*-1);
}else{
mx=max(mx,slvmx(vps[cr].first-1,dpth+1)*2);
}
if(vps[cr].second<0){
mx=max(mx,vps[cr].second*-1);
}else{
mx=max(mx,slvmx(vps[cr].second-1,dpth+1)*2);
}
return mx;
}
int main()
{
int n;
cin>>n;
vps=vector<pair<int,int> >(n);
for(int i=0;i<n;i++){
int x,y;
cin>>x>>y;
vps[i]={x,y};
}
trg=2*slvmx();
trg+=(trg%(1<<cntdpth)==0)?0:((1<<cntdpth)-(trg%cntdpth));
string binary = std::bitset<64>(trg).to_string();
binary.erase(0, binary.find_first_not_of('0'));
cout << binary;
return 0;
}
/***
3 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
11 |
Incorrect |
15 ms |
640 KB |
Output isn't correct |
12 |
Incorrect |
19 ms |
760 KB |
Output isn't correct |
13 |
Incorrect |
74 ms |
2296 KB |
Output isn't correct |
14 |
Incorrect |
148 ms |
4344 KB |
Output isn't correct |
15 |
Incorrect |
148 ms |
2804 KB |
Output isn't correct |
16 |
Incorrect |
520 ms |
12624 KB |
Output isn't correct |
17 |
Execution timed out |
1075 ms |
19192 KB |
Time limit exceeded |
18 |
Execution timed out |
1087 ms |
19192 KB |
Time limit exceeded |
19 |
Execution timed out |
1088 ms |
20984 KB |
Time limit exceeded |
20 |
Execution timed out |
1051 ms |
20472 KB |
Time limit exceeded |