Huskar, Tuskar, and Balls
Difficulty: Hard

Huskar and Tuskar are playing a game with balls. There is a tree with $N$ nodes numbered from $1$ to $N$ respectively (root is $1$). There is a ball on each node. If a node has only one child, the ball on this node will drop onto the child node. But if a node has more than one child, Huskar and Tuskar can't decide the way that the ball will follow. So they start deleting edges one by one (Huskar goes first) until every ball has exactly one way to go. Every ball must be able to reach a leaf node. (A leaf node is a node which has no children.)

In this game each player has a node. When a ball drops onto a player's node, this player gets one point and the ball is removed from the tree. 

Both of them are *just* trying to maximize their own points. They are not jealous friends. So if one cannot affect his own points, he would like to help increase his friend's points.

You are given a graph, and you need to determine Huskar and Tuskar's points when they delete edges optimally for themselves.

Input Format:
Line 1 : Two integers : $N$ and $Q$, the number of the nodes in the tree and the number of queries.  
Lines $2...N$ : line $i$, one integer : the parent of node $i$.  
Lines $N+1...N+Q$ : line $(N+i)$ , two integers : Huskar's node and Tuskar's node.  


**Constraints**  
$2 \le N \le 2 \times 10^5$  
$1 \le Q \le 2 \times 10^5$  
Huskar and Tuskar can't be on same node.  

Output Format:
You must print $Q$ lines. In each line, two integers for each query : Huskar's points and Tuskar's points.

Sample Input:
	6 1
	4
	1
	1
	3
	3
	3 6

Sample Output:
	2 1

Python 3 starter code:


Reference solution (C++):
	#include <bits/stdc++.h>

	using namespace std;

	const int MAXN = 500010;
	const int LogN = 21;
	
	int dad[MAXN][LogN];
	
	int N,Q;
	
	stack<int> st;
	
	vector<int> v[MAXN];
	
	int wh[MAXN];
	int depth[MAXN];
	
	void iterative( int k ){ 
	
		st.push(k);
		
		while ( !st.empty() ){
			
			k = st.top();
			st.pop();
			
			if ( wh[k] < v[k].size() ){
				st.push(k);
				st.push( v[k][ wh[k] ] );
				
				depth[ v[k][wh[k]] ] = depth[k]+1;
				
				wh[k]++; 
			}
		}
		
	}
	
	int LCA( int a , int b ){
		
		if ( depth[a] > depth[b] ){
			for ( int i=LogN-1 ; i>=0 ; i-- )
				if ( depth[dad[a][i]] >= depth[b] )
					a=dad[a][i];
		}
		else if ( depth[b] > depth[a] ){
			for ( int i=LogN-1 ; i>=0 ; i-- )
				if ( depth[dad[b][i]] >= depth[a] )
					b=dad[b][i];
		}
		
		if ( a==b )	return a;
		
		for ( int i=LogN-1 ; i>=0 ; i-- )
			if ( dad[a][i]!=dad[b][i] ){
				a=dad[a][i];
				b=dad[b][i];
			}
			
		return dad[a][0];
	}		
		
	int main(){
	
		scanf(" %d %d",&N,&Q);
		
		for ( int i=2 ; i<=N ; i++ ){
			scanf(" %d",&dad[i][0]);
			v[ dad[i][0] ].push_back(i);
		}
		
		depth[1] = 1;
		
		iterative(1);
		
		for ( int i=1 ; i<LogN ; i++ )
			for ( int j=1 ; j<=N ; j++ )
				dad[j][i] = dad[dad[j][i-1]][i-1];
			
		int a,b,lca;
			
		for ( int i=1 ; i<=Q ; i++ ){
			
			scanf(" %d %d",&a,&b);
			lca = LCA(a,b);
			printf("%d %d\n",depth[a],depth[b]-depth[lca]);
			
		} 
	
		return 0;
		
	}