CF1763F.Edge Queries

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an undirected, connected graph of nn nodes and mm edges. All nodes uu of the graph satisfy the following:

  • Let SuS_u be the set of vertices in the longest simple cycle starting and ending at uu.
  • Let CuC_u be the union of the sets of vertices in any simple cycle starting and ending at uu.
  • Su=CuS_u = C_u.

You need to answer qq queries.

For each query, you will be given node aa and node bb. Out of all the edges that belong to any simple path from aa to bb, count the number of edges such that if you remove that edge, aa and bb are reachable from each other.

给你一个包含 nn 个节点和 mm 条边的无向连通图。图中所有节点 uu 均满足以下条件:

  • 设 SuS_u 为从 uu 出发并回到 uu 的最长简单环所包含的顶点集合;
  • 设 CuC_u 为所有从 uu 出发并回到 uu 的简单环的顶点集合的并集;
  • Su=CuS_u = C_u。

你需要回答 qq 个查询。

对于每个查询,给定节点 aa 和节点 bb。在所有属于 aa 到 bb 的任意简单路径的边中,统计满足如下条件的边的数量:若删除该边,aa 和 bb 仍彼此可达。

输入格式

The first line contains two integers nn and mm (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5, 1≤m≤min⁡1 \le m \le \min(2⋅1052 \cdot 10^5, (n⋅(n−1))/2(n \cdot (n-1))/2)) — the total number of nodes and edges in the graph, respectively.

The next mm lines contain two integers uu and vv (1≤1 \le uu, vv ≤n\le n, u≠vu \neq v) — describing an edge, implying that nodes uu and vv are connected to each other.

It is guaranteed that there is at most one edge between any pair of vertices in the graph and the given graph is connected.

The next line contains a single integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of queries.

Then qq lines follow, each representing a query. Each query contains two integers aa and bb (1≤1 \le aa, bb ≤n\le n).

第一行包含两个整数 nn 和 mm(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,1≤m≤min⁡(2⋅105, (n⋅(n−1))/2)1 \le m \le \min(2 \cdot 10^5,\ (n \cdot (n-1))/2)),分别表示图中节点和边的总数。

接下来的 mm 行每行包含两个整数 uu 和 vv(1≤u, v≤n1 \le u,\ v \le n,u≠vu \neq v),描述一条边,表示节点 uu 与 vv 相互连通。

保证图中任意一对顶点之间至多存在一条边,且给定的图是连通的。

下一行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5),表示查询的数量。

随后是 qq 行,每行代表一个查询。每个查询包含两个整数 aa 和 bb(1≤a, b≤n1 \le a,\ b \le n)。

输出格式

For each query, output a single integer — answer to the query.

对于每个查询,输出一个整数——该查询的答案。

输入输出样例

  • 输入#1

    10 11
    1 2
    2 3
    3 4
    4 5
    5 3
    2 7
    7 9
    9 10
    10 6
    6 7
    1 8
    5
    1 4
    5 10
    3 5
    2 8
    7 10

    输出#1

    3
    7
    3
    0
    4
  • 输入#2

    13 15
    1 2
    2 3
    3 4
    4 1
    2 4
    3 5
    5 6
    6 7
    6 8
    7 9
    9 10
    8 7
    10 11
    10 12
    10 13
    6
    9 11
    1 5
    1 8
    5 2
    5 12
    12 13

    输出#2

    0
    5
    8
    5
    3
    0

说明/提示

The graph in the first sample is :

The first query is (1,4)(1, 4). There are 55 total edges that belong to any simple path from 11 to 44. Edges (3,4),(4,5),(5,3)(3, 4), (4, 5), (5, 3) will be counted in the answer to the query.

The fourth query is (2,8)(2, 8). There is only one simple path from 22 to 88, thus none of the edges will be counted in the answer to the query.

The fifth query is (7,10)(7, 10). There are 44 total edges that belong to any simple path from 77 to 1010, all of them will be counted in the answer to the query.

第一个样例中的图如下所示:

第一个查询为 (1,4)(1, 4)。在任意一条从 11 到 44 的简单路径中,共有 55 条边;其中边 (3,4)(3, 4)、(4,5)(4, 5)、(5,3)(5, 3) 将被计入该查询的答案。

第四个查询为 (2,8)(2, 8)。从 22 到 88 仅存在唯一一条简单路径,因此该查询的答案中不计入任何边。

第五个查询为 (7,10)(7, 10)。在任意一条从 77 到 1010 的简单路径中,共有 44 条边;这 44 条边均将被计入该查询的答案。

输入解题思路,AI测评打分。不知道怎么写?

首页