Minimum distance between two given nodes in an N-ary tree

#include using namespace std;  struct Node {    int val;    vector child;};  Node* newNode(int key){    Node* temp = new Node;    temp->val = key;    return temp;}  bool flag;  void findPath(Node* root, int key,              vector& arr){    if (!root)        return;    arr.push_back(root->val);        if (root->val == key) {        flag = 1;        return;    }        for (int i = 0; i < root->child.size(); i++) {          findPath(root->child[i], key, arr);                  if (flag == 1)            return;    }      arr.pop_back();    return;}  void findMinDist(Node* root, int A, int B){    if (root == NULL)        return;    int val = root->val;          vector arr1, arr2;          flag = false;          findPath(root, A, arr1);          flag = false;          findPath(root, B, arr2);          int j;              for (int i = 1; i < min(arr1.size(), arr2.size()); i++) {        if (arr1[i] != arr2[i]) {            val = arr1[i - 1];            j = i - 1;            break;        }    }    int d1 = 0, d2 = 0;              for (int i = j; i < arr1.size(); i++)        if (arr1[i] == A)            break;        else            d1 += 1;              for (int i = j; i < arr2.size(); i++)        if (arr2[i] == B)            break;        else            d2 += 1;        val = d1 + d2;    cout child).push_back(newNode(3));    (root->child[0]->child).push_back(newNode(4));    (root->child[0]->child).push_back(newNode(5));    (root->child[1]->child).push_back(newNode(6));    (root->child[1])->child.push_back(newNode(7));    (root->child[1]->child).push_back(newNode(8));    int A = 4, B = 3;          findMinDist(root, A, B);      return 0;}