harsh-dart / HactoberFest2024

5 stars 17 forks source link

Distance between any two nodes of the tree #12

Closed blunterdecosta123 closed 7 hours ago

blunterdecosta123 commented 1 day ago

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!!

Cyphershadow24ar commented 1 day ago

Can you assign me this issue under Hacktoberfest 2024.