LCA Query On Tree

5

1 votes
Medium
Problem

Given a tree with N nodes rooted at node 1 and a node X.You have to count the number of pairs of nodes such that they have node as their lowest common ancestor.

Input:

The first line of the input file contains 2 integers N and node X.

Each of the next n-1 lines contains 2 integers u and v denoting that there is an edge between node u and v.

Output:

The output should contain a single integer, the answer to the problem.

Constraints:

1<=N<=100000

1<=X,u,v<=n

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?