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 ListNode dummy_ListNode
  10. #define TreeNode dummy_TreeNode
  11. struct ListNode{
  12. int val;
  13. ListNode *next;
  14. ListNode(int x) : val(x), next(NULL){
  15. }
  16. }
  17. ;
  18. struct TreeNode{
  19. int val;
  20. TreeNode *left;
  21. TreeNode *right;
  22. TreeNode(int x) : val(x), left(NULL), right(NULL){
  23. }
  24. }
  25. ;
  26. #undef ListNode
  27. #undef TreeNode
  28. bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
  29. int i;
  30. vector<ListNode*> nx;
  31. for(i=(0);i<(head.size());i++){
  32. if(head[i] == NULL){
  33. return true;
  34. }
  35. }
  36. if(root==NULL){
  37. return false;
  38. }
  39. nx.push_back(top);
  40. for(i=(0);i<(head.size());i++){
  41. if(head[i]->val == root->val){
  42. nx.push_back(head[i]->next);
  43. }
  44. }
  45. return solve(top, nx, root->left) || solve(top, nx, root->right);
  46. }
  47. class Solution{
  48. public:
  49. bool isSubPath(ListNode* head, TreeNode* root){
  50. vector<ListNode*> hoge;
  51. hoge.push_back(head);
  52. return solve(head, hoge, root);
  53. }
  54. }
  55. ;
  56. // cLay varsion 20200308-1
  57.  
  58. // --- original code ---
  59. // #define main dummy_main
  60. // {}
  61. // #undef main
  62. //
  63. // #define ListNode dummy_ListNode
  64. // #define TreeNode dummy_TreeNode
  65. // struct ListNode {
  66. // int val;
  67. // ListNode *next;
  68. // ListNode(int x) : val(x), next(NULL) {}
  69. // };
  70. // struct TreeNode {
  71. // int val;
  72. // TreeNode *left;
  73. // TreeNode *right;
  74. // TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  75. // };
  76. // #undef ListNode
  77. // #undef TreeNode
  78. //
  79. // bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
  80. // vector<ListNode*> nx;
  81. // rep(i,head.size()) if(head[i] == NULL) return true;
  82. // if(root==NULL) return false;
  83. //
  84. // nx.push_back(top);
  85. // rep(i,head.size()) if(head[i]->val == root->val) nx.push_back(head[i]->next);
  86. //
  87. // return solve(top, nx, root->left) || solve(top, nx, root->right);
  88. // }
  89. //
  90. // class Solution {
  91. // public:
  92. // bool isSubPath(ListNode* head, TreeNode* root) {
  93. // vector<ListNode*> hoge;
  94. // hoge.push_back(head);
  95. // return solve(head, hoge, root);
  96. // }
  97. // };
  98.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:28:12: error: ‘ListNode’ was not declared in this scope
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
            ^~~~~~~~
prog.cpp:28:12: note: suggested alternative: ‘fesetmode’
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
            ^~~~~~~~
            fesetmode
prog.cpp:28:22: error: ‘top’ was not declared in this scope
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
                      ^~~
prog.cpp:28:34: error: ‘ListNode’ was not declared in this scope
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
                                  ^~~~~~~~
prog.cpp:28:34: note: suggested alternative: ‘fesetmode’
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
                                  ^~~~~~~~
                                  fesetmode
prog.cpp:28:43: error: template argument 1 is invalid
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
                                           ^
prog.cpp:28:43: error: template argument 2 is invalid
prog.cpp:28:51: error: ‘TreeNode’ was not declared in this scope
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
                                                   ^~~~~~~~
prog.cpp:28:51: note: suggested alternative: ‘remove’
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
                                                   ^~~~~~~~
                                                   remove
prog.cpp:28:61: error: ‘root’ was not declared in this scope
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
                                                             ^~~~
prog.cpp:28:61: note: suggested alternative: ‘rint’
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
                                                             ^~~~
                                                             rint
prog.cpp:28:65: error: expression list treated as compound expression in initializer [-fpermissive]
 bool solve(ListNode* top, vector<ListNode*> head, TreeNode *root){
                                                                 ^
prog.cpp:49:18: error: ‘ListNode’ has not been declared
   bool isSubPath(ListNode* head, TreeNode* root){
                  ^~~~~~~~
prog.cpp:49:34: error: ‘TreeNode’ has not been declared
   bool isSubPath(ListNode* head, TreeNode* root){
                                  ^~~~~~~~
prog.cpp: In member function ‘bool Solution::isSubPath(int*, int*)’:
prog.cpp:50:12: error: ‘ListNode’ was not declared in this scope
     vector<ListNode*> hoge;
            ^~~~~~~~
prog.cpp:50:12: note: suggested alternative: ‘fesetmode’
     vector<ListNode*> hoge;
            ^~~~~~~~
            fesetmode
prog.cpp:50:21: error: template argument 1 is invalid
     vector<ListNode*> hoge;
                     ^
prog.cpp:50:21: error: template argument 2 is invalid
prog.cpp:51:10: error: request for member ‘push_back’ in ‘hoge’, which is of non-class type ‘int’
     hoge.push_back(head);
          ^~~~~~~~~
prog.cpp:52:34: error: ‘solve’ cannot be used as a function
     return solve(head, hoge, root);
                                  ^
stdout
Standard output is empty