CF1819E.Roads in E City

普及/提高-

通过率:0%

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 100m100 \cdot m requests.

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt ( 1t10001 \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 ( 2n20002 \le n \le 2\,000 , n1m2000n - 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 ( 1ai,bin1 \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 20002\,000 .

输出格式

Once you have read the description of the test case, you can make queries. Queries can be of three types:

  1. "- xx " ( 1xm1 \le x \le m ). In this case the road with the number xx is blocked if it has not already been blocked.
  2. "+ xx " ( 1xm1 \le x \le m ). In this case the road with the number xx is unblocked. Note that road xx must be blocked beforehand. All roads are initially unblocked.
  3. "? yy " ( 1yn1 \le y \le n ). In this case the jury program chooses some city ss . If you can get from town ss to town yy by unblocked repaired roads, the jury program will output 11 , otherwise the jury program will output 00 . Note that city ss will be selected before getting information about city yy , but your previous requests may be taken into account when selecting city ss .

In total, you can make no more than 100m100 \cdot m queries for each set of input data.

After you have found all repaired roads, output "! c1, c2, c3, , cmc_1,\ c_2,\ c_3,\ \ldots,\ c_m ", where cic_i is 11 if road ii is repaired, and 00 if road is not repaired. This output will not count in the total number of queries. The jury program will output 11 if your answer is correct, and 00 if the answer is not correct. If you received 00 , your program must terminate immediately to receive a Wrong Answer verdict. Otherwise you can get any verdict, because the program will continue reading from the closed stream. If you read 11 , move on to the next test case, or terminate the program if there is none.

Note that you do not have to unblock all roads before outputting the answer. It is guaranteed that all repaired roads are fixed initially and will not be changed by the jury program depending on queries.

After outputting a query or the answer do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see the documentation for other languages.

HacksYou can't do hacks on this problem.

输入输出样例

  • 输入#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.

首页