Maximize difference between pair of nodes in a given rooted tree such that one node is ancestor of another

#include using namespace std;  vector tree;vector visited;vector ancestorNum;  int maxDiff = INT_MIN;  void dfs(int src, int val, vector& W){          visited[src] = true;          for (auto neighbour : tree[src]) {                                  if (!visited[neighbour]            && (ancestorNum[neighbour]                > ancestorNum[src])) {                          maxDiff = max(                val – W[neighbour – 1],                maxDiff);                          dfs(neighbour, val, W);        }    }}  void bfs(int src, int N){            visited.assign(N, false);          queue q;              ancestorNum[src] = 0;          visited[src] = true;          q.push(src);          while (!q.empty()) {                  int cur = q.front();        q.pop();                  for (auto neighbour : tree[cur]) {                                      if (!visited[neighbour]) {                                                  visited[neighbour] = true;                                                  q.push(neighbour);                                                  ancestorNum[neighbour]                    = ancestorNum[cur] + 1;            }        }    }}  void maximumDiff(vector W,                 vector P, int N){    if (N == 1) {        cout