fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define MAX 1000001
  4. using namespace std;
  5.  
  6. vector < pair<int,int> > v;
  7. int level[MAX],ht;
  8.  
  9. string s[MAX];
  10.  
  11. int assign(int i,int h){
  12. ht = max(ht,h);
  13. if (v[i].first<0) level[h] = max(level[i],-v[i].first);
  14. else assign(v[i].first-1,h+1);
  15. if (v[i].second<0) level[h] = max(level[h],-v[i].second);
  16. else assign(v[i].second-1,h+1);
  17. return 0;
  18. }
  19.  
  20. int main(){
  21. int n;
  22. cin >> n;
  23. v.resize(n+1);
  24.  
  25. for (int i=0;i<n;i++){
  26. scanf("%d%d",&v[i].first,&v[i].second);
  27. }
  28.  
  29. assign(0,0);
  30.  
  31. for (int i=0;i<MAX;i++){
  32. int temp = level[i],c = 0;
  33. while(temp){
  34. s[i]+=(temp%2)+'0';
  35. temp/=2;
  36. c++;
  37. }
  38. for (int j=0;j<c/2;j++) swap(s[i][j],s[i][c-j-1]);
  39. }
  40.  
  41. double mx = level[ht];
  42. int v = ht;
  43.  
  44. double pw = 1;
  45. for (int i=ht;i>=0;i--){
  46. if (pw>mx) break;
  47. if (level[i]/pw>mx){
  48. mx = level[i]/pw;
  49. v = i;
  50. }
  51. pw*=2;
  52. }
  53.  
  54. cout << s[v];
  55. for (int i=0;i<=v;i++) cout << 0;
  56.  
  57. return 0;
  58. }
Runtime error #stdin #stdout 0.01s 50384KB
stdin
Standard input is empty
stdout
Standard output is empty