Minimize sum of node values by filling given empty Tree such that each node is GCD of its children

#include using namespace std;  class Node {public:    int val;    Node *left, *right;    Node(int val)    {        this->val = val;        left = NULL;        right = NULL;    }};  class Tree {public:    unordered_map depth;              int findDepth(Node* cur)    {        int mx = 0;        if (cur->left) {            mx = findDepth(cur->left);        }        if (cur->right) {            mx = max(mx, findDepth(cur->right));        }                          return depth[cur] = mx + 1;    }              int dfs(Node* cur, bool flag, int parValue)    {        if (parValue != -1) {            if (flag)                cur->val = parValue;            else                cur->val = parValue * 2;        }        int l = 0, r = 0;        if (cur->left && cur->right) {            if (depth[cur->left] > depth[cur->right]) {                l = dfs(cur->left, 1, cur->val);                r = dfs(cur->right, 0, cur->val);            }            else {                l = dfs(cur->left, 0, cur->val);                r = dfs(cur->right, 1, cur->val);            }        }        else if (cur->left) {            l = dfs(cur->left, 1, cur->val);        }        else if (cur->right) {            r = dfs(cur->right, 1, cur->val);        }          return l + r + cur->val;    }                      int minimumSum(Node* root)    {                findDepth(root);                          return dfs(root, 1, -1);    }};  int main(){          int X = 2;          Node* root = new Node(X);    root->left = new Node(-1);    root->right = new Node(-1);    root->left->left = new Node(-1);    root->left->right = new Node(-1);    root->left->right->left = new Node(-1);    root->left->right->right = new Node(-1);    root->left->right->right->left = new Node(-1);      Tree t;          cout