For this Question: You are given a binary tree rooted at 1. You have to find the mirror image of any node qi about node 1. If it doesn't exist then print -1. Consider the mirror to be a vertical plane at node 1.

Node 1 is considered to be a mirror image of itself.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 contains a single integer q[i]

Constraints:
1 <= N <= 10^3
1<= Q <= 10^3For each query print in a separate line the mirror image of the node if it exists, otherwise print -1.Sample Input 1:
7 4
2 4
5 3
-1 -1
-1 7
6 -1
-1 -1
-1 -1
2
5
3
1

Sample output 1:
4
7
-1
1

Explanation: Given binary tree 
                1
               /  \
             2     4
            / \      \
          5    3     7
         /
       6
Query 1: mirror image of node 2 is node 4
Query 2: mirror image of node 5 is node 7
Query 3: mirror image of node 3 is the left child of node 4, but since there is no left child, print -1
Query 4: mentioned in statement, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
 
#define int 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 = 1e3 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

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

void solve(){
	int n, q;
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> l[i] >> r[i];
		if(l[i] != -1)	p[l[i]] = i;
		if(r[i] != -1)	p[r[i]] = i;
	}
	while(q--){
		vector<int> v;
		int x;	cin >> x;
		while(x != 1){
			if(l[p[x]] == x)
				v.push_back(1);
			else
				v.push_back(0);
			x = p[x];
		}
		reverse(v.begin(), v.end());
		for(auto i: v){
			if(x == -1)	break;
			if(i == 0){
				if(l[x] == -1){
					x = l[x];
					break;
				}
				x = l[x];
			}
			else{
				if(r[x] == -1){
					x = r[x];
					break;
				}
				x = r[x];
			}
		}
		cout << x << endl;;
	}
}

void testcases(){
	int tt = 1; 
	//cin >> tt;
	while(tt--){
		solve();
	}
}

signed main() {
	IOS;
		clock_t start = clock();

	testcases();

	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?