CF1045C.Hyperspace Highways

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In an unspecified solar system, there are NN planets. A space government company has recently hired space contractors to build MM bidirectional Hyperspace™ highways, each connecting two different planets. The primary objective, which was to make sure that every planet can be reached from any other planet taking only Hyperspace™ highways, has been completely fulfilled. Unfortunately, lots of space contractors had friends and cousins in the Space Board of Directors of the company, so the company decided to do much more than just connecting all planets.

In order to make spending enormous amounts of space money for Hyperspace™ highways look neccessary, they decided to enforce a strict rule on the Hyperspace™ highway network: whenever there is a way to travel through some planets and return to the starting point without travelling through any planet twice, every pair of planets on the itinerary should be directly connected by a Hyperspace™ highway. In other words, the set of planets in every simple cycle induces a complete subgraph.

You are designing a Hyperspace™ navigational app, and the key technical problem you are facing is finding the minimal number of Hyperspace™ highways one needs to use to travel from planet AA to planet BB. As this problem is too easy for Bubble Cup, here is a harder task: your program needs to do it for QQ pairs of planets.

在某个未指明的太阳系中,共有 NN 颗行星。一家太空政府公司最近聘请了太空承包商,修建了 MM 条双向“超空间™”高速公路,每条公路连接两颗不同的行星。最初的主要目标——确保任意两颗行星之间均可仅通过“超空间™”高速公路相互抵达——已完全实现。然而,由于大量太空承包商在该公司“太空董事会”中拥有朋友和表亲等关系,公司决定开展远超单纯连通所有行星的额外工程。

为了使在“超空间™”高速公路上投入巨额太空资金显得确有必要,公司对“超空间™”高速公路网络施加了一条严格规则:只要存在一条不重复经过任何行星、且能从某颗行星出发并最终返回该行星的旅行路径(即一个简单环),那么该路径上所经所有行星两两之间都必须直接由一条“超空间™”高速公路相连。换言之,每个简单环所包含的行星集合,必须构成一个完全子图。

你正在设计一款“超空间™”导航应用程序,当前面临的关键技术问题是:找出从行星 AA 到行星 BB 所需经过的最少“超空间™”高速公路数量。由于该问题对 Bubble Cup 竞赛而言过于简单,现给出一个更难的任务:你的程序需对 QQ 对行星分别求解上述最小值。

输入格式

The first line contains three positive integers NN (1≤N≤100 0001\leq N\leq 100\,000), MM (1≤M≤500 0001\leq M\leq 500\,000) and QQ (1≤Q≤200 0001\leq Q\leq 200\,000), denoting the number of planets, the number of Hyperspace™ highways, and the number of queries, respectively.

Each of the following M lines contains a highway: highway ii is given by two integers uiu_i and viv_i (1≤ui<vi≤N1 \leq u_i \lt v_i \leq N), meaning the planets uiu_i and viv_i are connected by a Hyperspace™ highway. It is guaranteed that the network of planets and Hyperspace™ highways forms a simple connected graph.

Each of the following QQ lines contains a query: query jj is given by two integers aja_j and bjb_j (1≤aj<bj≤N)(1 \leq a_j \lt b_j \leq N ), meaning we are interested in the minimal number of Hyperspace™ highways one needs to take to travel from planet aja_j to planet bjb_j.

第一行包含三个正整数 NN(1≤N≤100 0001\leq N\leq 100\,000)、MM(1≤M≤500 0001\leq M\leq 500\,000)和 QQ(1≤Q≤200 0001\leq Q\leq 200\,000),分别表示行星的数量、超空间™高速公路的数量以及查询的数量。

接下来的 MM 行每行描述一条高速公路:第 ii 条高速公路由两个整数 uiu_i 和 viv_i(1≤ui<vi≤N1 \leq u_i \lt v_i \leq N)给出,表示行星 uiu_i 与行星 viv_i 之间存在一条超空间™高速公路。保证所有行星与超空间™高速公路构成一个简单连通图。

接下来的 QQ 行每行描述一个查询:第 jj 个查询由两个整数 aja_j 和 bjb_j(1≤aj<bj≤N1 \leq a_j \lt b_j \leq N)给出,表示我们希望求出从行星 aja_j 到行星 bjb_j 所需经过的最少超空间™高速公路数量。

输出格式

Output QQ lines: the jj-th line of output should contain the minimal number of Hyperspace™ highways one needs to take to travel from planet aja_j to planet bjb_j.

输出 QQ 行:第 jj 行应包含从星球 aja_j 到星球 bjb_j 所需经过的 Hyperspace™ 高速公路的最少数量。

输入输出样例

  • 输入#1

    5 7 2
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    1 5
    1 4
    2 5

    输出#1

    1
    2
  • 输入#2

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

    输出#2

    2
    2
    3
    3

说明/提示

The graph from the second sample:

第二个样例的图:

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

首页