#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{
ll l, r;
}nd;
vector<node>g;
ll dfs(int x){
int changel=0,changer=0;
if(g[x].l>0)g[x].l = dfs(g[x].l),changel++;
else g[x].l*=-1LL;
if(g[x].r>0)g[x].r = dfs(g[x].r),changer++;
else g[x].r*=-1LL;
ll dif = abs(g[x].l - g[x].r);
return g[x].r + g[x].l + dif;
}
int main(){_
int n;cin>>n;
g.resize(n+1);
for(int i=1;i<=n;i++){
ll l,r;cin>>g[i].l>>g[i].r;
}
ll ans = dfs(1);
vector<int>resp;
while(ans){
resp.pb(ans&1);
ans>>=1;
}
reverse(all(resp));
for(auto x:resp)cout<<x;
cout<<endl;
}
Compilation message
poklon.cpp: In function 'int main()':
poklon.cpp:38:12: warning: unused variable 'l' [-Wunused-variable]
38 | ll l,r;cin>>g[i].l>>g[i].r;
| ^
poklon.cpp:38:14: warning: unused variable 'r' [-Wunused-variable]
38 | ll l,r;cin>>g[i].l>>g[i].r;
| ^
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
460 KB |
Output isn't correct |
13 |
Incorrect |
10 ms |
1484 KB |
Output isn't correct |
14 |
Incorrect |
18 ms |
2636 KB |
Output isn't correct |
15 |
Incorrect |
19 ms |
1868 KB |
Output isn't correct |
16 |
Incorrect |
67 ms |
7428 KB |
Output isn't correct |
17 |
Incorrect |
153 ms |
16680 KB |
Output isn't correct |
18 |
Incorrect |
156 ms |
17452 KB |
Output isn't correct |
19 |
Incorrect |
190 ms |
18652 KB |
Output isn't correct |
20 |
Incorrect |
184 ms |
31576 KB |
Output isn't correct |