fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define main dummy_main
  5. int main(){
  6. return 0;
  7. }
  8. #undef main
  9. #define TreeNode TreeNodeDummy
  10. struct TreeNode{
  11. int val;
  12. TreeNode *left;
  13. TreeNode *right;
  14. TreeNode(int x) : val(x), left(NULL), right(NULL){
  15. }
  16. }
  17. ;
  18. #undef TreeNode
  19. int s;
  20. int arr[5100];
  21. int s1;
  22. int arr1[5100];
  23. int s2;
  24. int arr2[5100];
  25. void doit(TreeNode *x){
  26. if(x==NULL){
  27. return;
  28. }
  29. arr[s++] = x->val;
  30. doit(x->left);
  31. doit(x->right);
  32. }
  33. class Solution{
  34. public:
  35. bool twoSumBSTs(TreeNode* root1, TreeNode* root2, int target){
  36. int i;
  37. int j;
  38. set<int> ss;
  39. s = 0;
  40. doit(root1);
  41. s1 = s;
  42. for(i=(0);i<(s1);i++){
  43. arr1[i] = arr[i];
  44. }
  45. s = 0;
  46. doit(root2);
  47. s2 = s;
  48. for(i=(0);i<(s2);i++){
  49. arr2[i] = arr[i];
  50. }
  51. for(i=(0);i<(s1);i++){
  52. ss.insert(arr1[i]);
  53. }
  54. for(i=(0);i<(s2);i++){
  55. if(ss.count(target - arr2[i])){
  56. return true;
  57. }
  58. }
  59. return false;
  60. }
  61. }
  62. ;
  63. // cLay varsion 20191006-1
  64.  
  65. // --- original code ---
  66. // #define main dummy_main
  67. // {}
  68. // #undef main
  69. //
  70. // #define TreeNode TreeNodeDummy
  71. // struct TreeNode {
  72. // int val;
  73. // TreeNode *left;
  74. // TreeNode *right;
  75. // TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  76. // };
  77. // #undef TreeNode
  78. //
  79. // int s, arr[5100];
  80. // int s1, arr1[5100];
  81. // int s2, arr2[5100];
  82. //
  83. // void doit(TreeNode *x){
  84. // if(x==NULL) return;
  85. // arr[s++] = x->val;
  86. // doit(x->left);
  87. // doit(x->right);
  88. // }
  89. //
  90. // class Solution {
  91. // public:
  92. // bool twoSumBSTs(TreeNode* root1, TreeNode* root2, int target) {
  93. // int i, j;
  94. // set<int> ss;
  95. //
  96. // s = 0;
  97. // doit(root1);
  98. // s1 = s;
  99. // rep(i,s1) arr1[i] = arr[i];
  100. //
  101. // s = 0;
  102. // doit(root2);
  103. // s2 = s;
  104. // rep(i,s2) arr2[i] = arr[i];
  105. //
  106. // rep(i,s1) ss.insert(arr1[i]);
  107. // rep(i,s2) if(ss.count(target - arr2[i])) return true;
  108. // return false;
  109. // }
  110. // };
  111.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:25:11: error: variable or field ‘doit’ declared void
 void doit(TreeNode *x){
           ^~~~~~~~
prog.cpp:25:11: error: ‘TreeNode’ was not declared in this scope
prog.cpp:25:11: note: suggested alternative: ‘remove’
 void doit(TreeNode *x){
           ^~~~~~~~
           remove
prog.cpp:25:21: error: ‘x’ was not declared in this scope
 void doit(TreeNode *x){
                     ^
prog.cpp:35:19: error: ‘TreeNode’ has not been declared
   bool twoSumBSTs(TreeNode* root1, TreeNode* root2, int target){
                   ^~~~~~~~
prog.cpp:35:36: error: ‘TreeNode’ has not been declared
   bool twoSumBSTs(TreeNode* root1, TreeNode* root2, int target){
                                    ^~~~~~~~
prog.cpp: In member function ‘bool Solution::twoSumBSTs(int*, int*, int)’:
prog.cpp:40:5: error: ‘doit’ was not declared in this scope
     doit(root1);
     ^~~~
prog.cpp:40:5: note: suggested alternative: ‘div’
     doit(root1);
     ^~~~
     div
stdout
Standard output is empty