Language: C++

#include<iostream>
#include<map>
#include<set>
using namespace std;
typedef struct node{
    int id;
    node *left, *right;
    node(int id):id(id),left(NULL),right(NULL){}
} Node;
class Solution{
private:
       map<int,Node*> hashMapping;
       set<Node*> rootCandidates;
       Node* createNode(int ID){
              if(ID!=-1){
               if(hashMapping.find(ID) == hashMapping.end()){
                    hashMapping[ID] = new Node(ID);
              } 
              return hashMapping[ID];
           }else{
              return NULL; 
           }
       }
       void preorder(Node* root){
         if(root==NULL){
             return;
         }else{
             cout<<" "<<root->id;
             preorder(root->left);
             preorder(root->right);
         }
       }
       void inorder(Node* root){
          if(root==NULL){
             return;
          }else{
             inorder(root->left);
             cout<<" "<<root->id;
             inorder(root->right);
          }
       }
       void postorder(Node* root){
          if(root==NULL){
             return;
          }else{
             postorder(root->left);
             postorder(root->right);
             cout<<" "<<root->id;
         }
       }
public:
     node* buildTree(){
           hashMapping.clear();
           rootCandidates.clear();
           int num,rootID=-1;
           cin>>num;
           while(num--){
                 int ID,leftID,rightID;
                 cin>>ID>>leftID>>rightID;
                 rootCandidates.insert(ID);
                 rootCandidates.erase(leftID);
                 rootCandidates.erase(rightID);
                 createNode(ID)->left = createNode(leftID); 
                 createNode(ID)->right = createNode(rightID); 
           }
           return hashMapping[*rootCandidates.begin()];
     }
void printPreOrder(node *root){
         cout<<"Preorder"<<endl;
         preorder(root);
         cout<<endl;
     }
void printInOrder(node *root){
         cout<<"Inorder"<<endl;
         inorder(root);
         cout<<endl;
     }
void printPostOrder(node *root){
         cout<<"Postorder"<<endl;
         postorder(root);
         cout<<endl;
    }
} sln;
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
    node *root = sln.buildTree(); 
    sln.printPreOrder(root);
    sln.printInOrder(root);
    sln.printPostOrder(root);
    return 0;
}

Compiler output:
a.cc: In member function 'node* Solution::buildTree()':
a.cc:60:39: error: no matching function for call to 'std::set<node*>::insert(int&)'
   60 |                  rootCandidates.insert(ID);
      |                  ~~~~~~~~~~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/14/set:63,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_set.h:511:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = node*; _Compare = std::less<node*>; _Alloc = std::allocator<node*>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<node*>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<node*>, node*>::rebind<node*>; typename _Alloc::value_type = node*; value_type = node*]' (near match)
  511 |       insert(const value_type& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:511:7: note:   conversion of argument 1 would be ill-formed:
a.cc:60:40: error: invalid conversion from 'int' to 'std::set<node*>::value_type' {aka 'node*'} [-fpermissive]
   60 |                  rootCandidates.insert(ID);
      |                                        ^~
      |                                        |
      |                                        int
/usr/include/c++/14/bits/stl_set.h:520:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(value_type&&) [with _Key = node*; _Compare = std::less<node*>; _Alloc = std::allocator<node*>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<node*>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<node*>, node*>::rebind<node*>; typename _Alloc::value_type = node*; value_type = node*]' (near match)
  520 |       insert(value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:520:7: note:   conversion of argument 1 would be ill-formed:
a.cc:60:40: error: invalid conversion from 'int' to 'std::set<node*>::value_type' {aka 'node*'} [-fpermissive]
   60 |                  rootCandidates.insert(ID);
      |                                        ^~
      |                                        |
      |                                        int
/usr/include/c++/14/bits/stl_set.h:568:9: note: candidate: 'template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _Key = node*; _Compare = std::less<node*>; _Alloc = std::allocator<node*>]'
  568 |         insert(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/14/bits/stl_set.h:568:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:548:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(const_iterator, const value_type&) [with _Key = node*; _Compare = std::less<node*>; _Alloc = std::allocator<node*>; iterator = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::const_iterator; const_iterator = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::const_iterator; value_type = node*]'
  548 |       insert(const_iterator __position, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:548:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:553:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(const_iterator, value_type&&) [with _Key = node*; _Compare = std::less<node*>; _Alloc = std::allocator<node*>; iterator = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::const_iterator; const_iterator = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::const_iterator; value_type = node*]'
  553 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:553:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:580:7: note: candidate: 'void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = node*; _Compare = std::less<node*>; _Alloc = std::allocator<node*>]'
  580 |       insert(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:580:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<node*>'
  580 |       insert(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:600:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::insert_return_type std::set<_Key, _Compare, _Alloc>::insert(node_type&&) [with _Key = node*; _Compare = std::less<node*>; _Alloc = std::allocator<node*>; insert_return_type = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::insert_return_type; node_type = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::node_type]'
  600 |       insert(node_type&& __nh)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:600:26: note:   no known conversion for argument 1 from 'int' to 'std::set<node*>::node_type&&' {aka 'std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::node_type&&'}
  600 |       insert(node_type&& __nh)
      |              ~~~~~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_set.h:605:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(const_iterator, node_type&&) [with _Key = node*; _Compare = std::less<node*>; _Alloc = std::allocator<node*>; iterator = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::const_iterator; const_iterator = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::const_iterator; node_type = std::_Rb_tree<node*, node*, std::_Identity<node*>, std::less<node*>, std::allocator<node*> >::node_type]'
  605 |       insert(const_iterator __hint, node_type&& __nh)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:605:7: note:   candidate expects 2 arguments, 1 provided
a.cc:61:39: error: invalid conversion from 'int' to 'std::set<node*>::key_type' {aka 'node*'} [-fpermissive]
   61 |                  rootCandidates.erase(leftID);
      |                                       ^~~~~~
      |                                       |
      |                                       int
/usr/include/c++/14/bits/stl_set.h:686:29: note:   initializing argument 1 of 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = node*; _Compare = std::less<node*>; _Alloc = std::allocator<node*>; size_type = long unsigned int; key_type = node*]'
  686 |       erase(const key_type& __x)
      |             ~~~~~~~~~~~~~~~~^~~
a.cc:62:39: error: invalid conversion from 'int' to 'std::set<node*>::key_type' {aka 'node*'} [-fpermissive]
   62 |                  rootCandidates.erase(rightID);
      |                                       ^~~~~~~
      |                                       |
      |                                       int
/usr/include/c++/14/bits/stl_set.h:686:29: note:   initializing argument 1 of 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = node*; _Compare = std::less<node*>; _Alloc = std::allocator<node*>; size_type = long unsigned int; key_type = node*]'
  686 |       erase(const key_type& __x)
      |             ~~~~~~~~~~~~~~~~^~~
a.cc:66:30: error: ambiguous overload for 'operator[]' (operand types are 'std::map<int, node*>' and 'node* const')
   66 |            return hashMapping[*rootCandidates.begin()];
      |                              ^
In file included from /usr/include/c++/14/map:63,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = node*; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, node*> >; mapped_type = node*; key_type = int]' (near match)
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:7: note:   conversion of argument 1 would be ill-formed:
a.cc:66:31: error: invalid conversion from 'node*' to 'std::map<int, node*>::key_type' {aka 'int'} [-fpermissive]
   66 |            return hashMapping[*rootCandidates.begin()];
      |                               ^~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               node*
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = int; _Tp = node*; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, node*> >; mapped_type = node*; key_type = int]' (near match)
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:7: note:   conversion of argument 1 would be ill-formed:
a.cc:66:31: error: invalid conversion from