For this Question: Given a binary tree of N nodes, with root 1 and Q queries with nodes u and v. For each query find the sum of nodes on the shortest path from u to v, where node v is the ancestor of node u.First line contains the integer N and Q, denoting the number of nodes in the binary tree and the number of queries respectively.
Next N lines contains two integers denoting the left and right child of the i'th node respectively. 
If the node doesn't have a left or right child, it is denoted by '-1'
Next Q lines contain two integers u and v
1 <= N <= 10000
1 <= Q <= 100000
1 <= u, v <= NPrint Q lines denoting the sum of nodes on the shortest path from u to vSample Input 1:
6 3
2 4
5 3
-1 -1
-1 -1
6 -1
-1 -1
6 2
3 1
5 5
Sample output 1:
13
6
5

Explanation: Given binary tree 
                1
               /  \
             2     4
            / \
          5    3
         /
       6
Query 1: 6+5+2 = 13
Query 2: 3+2+1 = 6
Query 3: 5 , I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int l[N], r[N], p[N], s[N];

void dfs(int u, int p = 0){
	if(u == -1)	return;
	s[u] = s[p] + u;
	dfs(l[u], u);
	dfs(r[u], u);
}

signed main() {
	IOS;
		clock_t start = clock();
	int n, q;	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> l[i] >> r[i];
		p[l[i]] = p[r[i]] = i;
	}	
	dfs(1);
	while(q--){
		int u, v;
		cin >> u >> v;
		cout << s[u] - s[p[v]] << endl;
	}

	cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
	return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?