Logo
(追記) (追記ここまで)

28145번 - A Tree and Two Edges 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB78393048.387%

문제

Given a connected simple graph (with at most one edge between any pair of nodes) with $n$ nodes and $n+1$ 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 $n$ (4ドル \le n \le 5 \times 10^4$) and $q$ (1ドル \le q \le 5 \times 10^4$), where $n$ is the number of nodes and $q$ is the number of queries. The nodes are numbered from 1ドル$ to $n$.

Each of the next $n+1$ lines contains two integers $a$ and $b$ (1ドル \le a < b \le n$) indicating that there is an edge in the graph between nodes $a$ and $b$. All edges are distinct.

Each of the next $q$ lines contains two integers $u$ and $v$ (1ドル \le u < v \le n$). This is a query for the number of simple paths between nodes $u$ and $v$.

출력

Output $q$ 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.

제한

예제 입력 1

4 6
1 2
1 3
1 4
2 3
2 4
1 2
1 3
1 4
2 3
2 4
3 4

예제 출력 1

3
3
3
3
3
4

예제 입력 2

6 4
1 2
1 3
1 6
2 3
3 4
3 5
4 5
1 2
1 3
1 4
1 6

예제 출력 2

2
2
4
1

힌트

출처

ICPC > Regionals > North America > North America Championship > North America Championship 2023 B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /