CF1819E.Roads in E City

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem.

As is well known, the city "E" has never had its roads repaired in its a thousand and a half years old history. And only recently the city administration repaired some of them.

It is known that in total in the city "E" there are nn intersections and mm roads, which can be used in both directions, numbered with integers from 11 to mm. The ii-th road connects intersections with numbers aia_i and bib_i.

Among all mm roads, some subset of the roads has been repaired, but you do not know which one. The only information you could get from the city's road services is that you can get from any intersection to any other intersection by driving only on the roads that have been repaired.

You are a young entrepreneur, and decided to organize a delivery service of fresh raw meat in the city "E" (in this city such meat is called "steaks", it is very popular among the locals). You have already recruited a staff of couriers, but the couriers are willing to travel only on repaired roads. Now you have to find out which roads have already been repaired.

The city administration has given you the city for a period of time, so you can make different queries of one of three types:

  1. Block the road with the number xx. In this case, movement on the road for couriers will be forbidden. Initially all roads are unblocked.
  2. Unblock the road with the number xx. In this case, couriers will be able to move on the road xx if it is repaired.
  3. Try to deliver the order to the intersection with the number yy. In this case, one of your couriers will start moving from intersection with number ss you don't know and deliver the order to intersection with number yy if there is a path on unblocked repaired roads from intersection ss to intersection yy. It is guaranteed that intersection ss will be chosen beforehand.

Unfortunately, the city is placed at your complete disposal for a short period of time, so you can make no more than 100⋅m100 \cdot m requests.

这是一个交互式问题。

众所周知,城市“E”在其一千五百年的历史中从未修缮过道路。直到最近,市政府才修缮了其中一部分道路。

已知城市“E”中共有 nn 个路口和 mm 条双向通行的道路,这些道路按整数编号为 11 至 mm。第 ii 条道路连接编号为 aia_i 和 bib_i 的两个路口。

在全部 mm 条道路中,有一部分子集已被修缮,但你并不知道具体是哪些。你唯一能从市政道路部门获取的信息是:仅通过已修缮的道路,即可从任意一个路口到达其余任意一个路口(即所有已修缮道路构成的子图是连通的)。

你是一位年轻的创业者,决定在城市“E”开办一项新鲜生肉配送服务(该城将此类生肉称为“牛排”,在当地居民中极为流行)。你已招募了一批快递员,但他们只愿意在已修缮的道路上行驶。现在,你需要确定哪些道路已被修缮。

市政府已将该城市短期交由你使用,因此你可以发出以下三种类型的查询请求:

  1. 封锁编号为 xx 的道路。此时,快递员将禁止在该道路上通行。初始状态下,所有道路均处于未封锁状态。
  2. 解除编号为 xx 的道路的封锁。此时,若该道路已被修缮,则快递员可再次在该道路上通行。
  3. 尝试向编号为 yy 的路口配送订单。此时,你的某位快递员将从一个你未知的编号为 ss 的路口出发;若存在一条由未封锁且已修缮的道路构成的路径,从路口 ss 到达路口 yy,则该快递员将成功完成配送。保证路口 ss 是预先选定的。

不幸的是,城市仅在极短时间内供你完全支配,因此你最多只能发出 100⋅m100 \cdot m 次查询请求。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1 0001 \le t \le 1\,000) — the number of test cases. The description of test cases follows.

The first line contains two integers nn and mm (2≤n≤2 0002 \le n \le 2\,000, n−1≤m≤2 000n - 1 \le m \le 2\,000) —the number of intersections and roads in the city "E".

Each of the following mm lines describes one road. The ii-th of these lines contains two integers aia_i and bib_i (1≤ai,bi≤n1 \le a_i, b_i \le n) — the ends of the ii-th road. It is guaranteed that no road connects the city to itself, while it is possible that there are several roads between a pair of different intersections.

It is guaranteed that the sum of nn and the sum of mm over all test cases does not exceed 2 0002\,000.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1 0001 \le t \le 1\,000),表示测试用例的数量。随后是各测试用例的描述。

第一行包含两个整数 nn 和 mm(2≤n≤2 0002 \le n \le 2\,000,n−1≤m≤2 000n - 1 \le m \le 2\,000),分别表示城市“E”中的交叉路口数量和道路数量。

接下来的 mm 行每行描述一条道路。其中第 ii 行包含两个整数 aia_i 和 bib_i(1≤ai,bi≤n1 \le a_i, b_i \le n),表示第 ii 条道路连接的两个端点。保证不存在连接同一交叉路口(即自环)的道路,但允许在两个不同交叉路口之间存在多条道路。

保证所有测试用例中 nn 的总和与 mm 的总和均不超过 2 0002\,000。

输入输出样例

  • 输入#1

    2
    2 2
    1 2
    2 1
    
    
    1
    
    0
    
    
    
    1
    
    1
    3 3
    1 2
    2 3
    3 1
    
    
    1
    
    1
    
    
    1
    
    0
    
    
    1
    
    1
    
    1
    
    1

    输出#1

    - 1
    ? 1
    
    ? 2
    
    - 2
    + 1
    ? 1
    
    ! 1 0
    
    
    
    
    
    - 1
    ? 2
    
    ? 1
    
    - 2
    ? 3
    
    ? 3
    
    + 1
    ? 3
    
    ? 2
    
    ? 1
    
    ! 1 1 1

说明/提示

In the first test case, road 11 was repaired, while road 22 was not. For the first delivery request, intersection 11 was selected as ss, and the path from intersection 11 to 11 exists. For the second delivery request, intersection 11 was selected as ss. Since the only repaired road was blocked, there was no path between intersections 11 and 22. For the third delivery request, intersection 22 was selected as ss, the path between intersections 22 and 11 exists along road 11, which is repaired and unblocked.

In the second test case, intersections 11, 33, 11, 22, 22, 33, 11 were selected as starting intersections for delivery requests.

在第一个测试用例中,道路 11 被修复,而道路 22 未被修复。对于第一个配送请求,交点 11 被选为起点 ss,从交点 11 到 11 的路径存在。对于第二个配送请求,交点 11 被选为起点 ss;由于唯一被修复的道路被阻塞,交点 11 与交点 22 之间不存在路径。对于第三个配送请求,交点 22 被选为起点 ss,交点 22 与交点 11 之间的路径沿道路 11 存在,该道路已被修复且未被阻塞。

在第二个测试用例中,配送请求的起点交点依次为 11、33、11、22、22、33、11。

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

首页