Problem Description
You are given a tree consisting of n nodes. Your task is to process q queries to determine the distance between pairs of nodes in the tree.
Input Format
The first line contains two integers n and q:
n: the number of nodes in the tree (1 ≤ n ≤ 200,000)
q: the number of queries (1 ≤ q ≤ 200,000)
The next n-1 lines describe the edges of the tree. Each line contains two integers a and b, indicating there is an edge between nodes a and b.
The final q lines describe the queries. Each line contains two integers a and b, asking for the distance between nodes a and b.
Output Format
Print q integers, each representing the answer to the corresponding query.
Constraints
1 ≤ a, b ≤ n
The input tree is connected and contains no cycles.
Kindly assign me this issue under hacktoberfest 2024!!
Problem Description You are given a tree consisting of n nodes. Your task is to process q queries to determine the distance between pairs of nodes in the tree.
Input Format The first line contains two integers n and q:
n: the number of nodes in the tree (1 ≤ n ≤ 200,000) q: the number of queries (1 ≤ q ≤ 200,000) The next n-1 lines describe the edges of the tree. Each line contains two integers a and b, indicating there is an edge between nodes a and b.
The final q lines describe the queries. Each line contains two integers a and b, asking for the distance between nodes a and b.
Output Format Print q integers, each representing the answer to the corresponding query.
Constraints 1 ≤ a, b ≤ n The input tree is connected and contains no cycles.
Kindly assign me this issue under hacktoberfest 2024!!