#include <bits/stdc++.h>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
struct node{
pair<ll,ll> l,r;
}nd;
vector<node>g;
pair<ll,ll> dfs(int x){
if(g[x].l.first>0)g[x].l = dfs(g[x].l.first);
else g[x].l.first*=-1LL;
if(g[x].r.first>0)g[x].r = dfs(g[x].r.first);
else g[x].r.first*=-1LL;
if(g[x].l.first<g[x].r.first)swap(g[x].l,g[x].r);
ll msb = 0,tmp = g[x].r.first;
if(tmp)while(tmp<g[x].l.first)tmp<<=1LL,msb++;
else return {g[x].l.first,g[x].l.second+1LL};
if(g[x].r.second-g[x].l.second>=msb)return {g[x].r.first,g[x].r.second+1LL};
else return {g[x].l.first,g[x].l.second+1LL};
}
int main(){_
int n;cin>>n;
g.resize(n+1);
for(int i=1;i<=n;i++){
ll l,r;cin>>g[i].l.first>>g[i].r.first;
}
auto [ans,zero] = dfs(1);
vector<int>resp;
while(ans){
resp.pb(ans&1LL);
ans>>=1LL;
}
reverse(all(resp));
for(auto x:resp)cout<<x;
for(int i=0;i<zero;i++)cout<<'0';
cout<<endl;
}
Compilation message
poklon.cpp: In function 'int main()':
poklon.cpp:41:12: warning: unused variable 'l' [-Wunused-variable]
41 | ll l,r;cin>>g[i].l.first>>g[i].r.first;
| ^
poklon.cpp:41:14: warning: unused variable 'r' [-Wunused-variable]
41 | ll l,r;cin>>g[i].l.first>>g[i].r.first;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
3 ms |
664 KB |
Output is correct |
13 |
Correct |
11 ms |
2272 KB |
Output is correct |
14 |
Correct |
22 ms |
4188 KB |
Output is correct |
15 |
Correct |
20 ms |
3404 KB |
Output is correct |
16 |
Correct |
73 ms |
12924 KB |
Output is correct |
17 |
Correct |
172 ms |
29252 KB |
Output is correct |
18 |
Correct |
170 ms |
30240 KB |
Output is correct |
19 |
Correct |
214 ms |
34428 KB |
Output is correct |
20 |
Correct |
224 ms |
48188 KB |
Output is correct |