#P2783. 有机化学之神偶尔会做作弊

    ID: 2428 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>图论强连通分量,缩点最近公共祖先,LCA

有机化学之神偶尔会做作弊

Description

You flip to that problem: given a hydrocarbon that contains only single bonds (an intuitive explanation for middle schoolers: a bunch of carbons connected by single lines, and every line is a single bond).

Then Ragnaros the Firelord purified all cycles with his flames (???). Every cyclic carbon structure is contracted into a single carbon, as shown in the figure.

环状碳变为一个碳

Next, for multiple specified pairs of carbons, compute how many carbons are between them in total, as illustrated (this illustration is unrelated to the one above).

求出有多少碳

But since this is during an exam, you can only tell your buddy the answer using sign language. You decide to represent the final answer in binary, as shown (don’t mind it; it’s not really related to the problem).

二进制手语

In short: you are given an undirected graph with nn vertices and mm edges. Contract every cycle in the graph into a single vertex. After this transformation, for each query asking about two vertices, find how many vertices lie between them.

Input Format

  • The first line contains two integers nn, mm, meaning there are nn vertices and mm bonds.
  • The next mm lines each contain two integers uu, vv, indicating there is a bond between carbon uu and carbon vv.
  • The next line contains an integer tottot, the number of queries.
  • The next tottot lines each contain two integers aa, bb, denoting the indices of the two queried carbons.

Output Format

Output tottot lines, each containing a binary number representing the answer.

3 2
1 2
2 3
2
1 2
2 3

10
10

Hint

The two queried carbons do not lie on a cycle.

Constraints

For 100%100\% of the testdata, 1<n1041 < n \le 10^4, 1<m5×1041 < m \le 5 \times 10^4.

Translated by ChatGPT 5