#P10953. 逃不掉的路

    ID: 11863 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>O2优化双连通分量最近公共祖先 LCA

逃不掉的路

Problem Description

In modern society, roads are essential.

There are nn towns and mm roads. Any two towns are connected by roads, and often by more than one.

However, some roads have been poorly maintained for years and are unpleasant to travel.

In theory, all roads lead to Rome. If one road is bad, you can just take a detour on other roads. But Xiao Lu found that no matter how you travel from town aa to town bb, there are always some unavoidable roads that you must pass through.

He wants you to compute: among all paths from aa to bb, how many roads are unavoidable?

Input Format

The first line contains nn and mm, separated by spaces.

The next mm lines each contain two integers xx and yy, separated by spaces, indicating that there is a bidirectional road of length 11 between towns xx and yy.

Line m+2m+2 contains qq.

The next qq lines each contain two integers aa and bb, separated by spaces, representing one query.

Output Format

For each query, output a positive integer indicating how many roads must be passed through when traveling from town aa to town bb.

Print one answer per line.

5 5
1 2
1 3
2 4
3 4
4 5
2
1 4
2 5
0
1

Hint

1n1051\le n \le 10^51m2×1051\le m \le 2\times 10^51q1051\le q \le 10^5
For all testdata, 1x,y,a,bn1 \le x,y,a,b \le n; for any road, the difference between the indices of its two endpoint towns does not exceed 10410^4;
Any two towns are connected by at least one path; the same road will not appear twice; a road’s endpoints will not be the same; the two towns in a query will not be the same.

Translated by ChatGPT 5