#P10931. 闇の連鎖

闇の連鎖

Problem Description

The legendary Dark Chain is called Dark by people.

Dark is the product of the darkness in the human heart, and heroes from all times and places have tried to defeat it.

After research, you find that Dark has the structure of an undirected graph. The graph has NN nodes and two types of edges: one type is called main edges, and the other type is called additional edges.

Dark has N1N - 1 main edges, and between any two nodes in Dark there exists a path consisting only of main edges.

In addition, Dark has MM additional edges.

Your task is to cut Dark into two disconnected parts.

At the beginning, all additional edges of Dark are invincible, and you can only choose one main edge to cut.

Once you cut a main edge, Dark will enter defense mode: main edges become invincible, and additional edges can be cut.

However, your ability only allows you to cut one more additional edge of Dark.

Now you want to know how many different plans can defeat Dark in total.

Note that even if after you cut a main edge in the first step you have already split Dark into two parts, you still need to cut one additional edge to count as defeating Dark.

Input Format

The first line contains two integers NN and MM.

Then N1N - 1 lines follow, each line contains two integers AA and BB, indicating that there is a main edge between AA and BB.

Then MM lines follow in the same format to give the additional edges.

Output Format

Output one integer representing the answer.

4 1
1 2
2 3
1 4
3 4
3

Hint

Constraints: 1N1000001\le N \le 100000, 1M2000001\le M \le 200000. The testdata guarantees that the answer does not exceed 23112^{31}-1.

Translated by ChatGPT 5