A Tree and Two Edges
시간 제한3초메모리 제한2048 MB
노드 n개와 간선 n+1개로 이루어진 연결 그래프가 주어질 때, 각 질의 쌍 사이의 단순 경로 개수를 구한다.
문제
Given a connected simple graph (with at most one edge between any pair of nodes) with nodes and edges (that's a tree with two extra edges), answer a list of queries: for two distinct nodes, how many simple paths are there between them? A simple path is a path that does not repeat nodes.
입력
The first line of input contains two integers () and (), where is the number of nodes and is the number of queries. The nodes are numbered from to .
Each of the next lines contains two integers and () indicating that there is an edge in the graph between nodes and . All edges are distinct.
Each of the next lines contains two integers and (). This is a query for the number of simple paths between nodes and .
출력
Output lines. On each line output a single integer, which is the number of simple paths between the query nodes. Output the answers to the queries in the order they appear in the input.