CF1158E.Strange device

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

It is an interactive problem.

Vasya enjoys solving quizzes. He found a strange device and wants to know how it works.

This device encrypted with the tree (connected undirected graph without cycles) with nn vertices, numbered with integers from 11 to nn . To solve this quiz you should guess this tree.

Fortunately, this device can make one operation, using which you should guess the cipher. You can give the device an array d1,d2,,dnd_1, d_2, \ldots, d_n of non-negative integers. On the device, there are nn lamps, ii -th of them is connected with ii -th vertex of the tree. For all ii the light will turn on the ii -th lamp, if there exist such vertex of the tree with number jij \neq i that dist(i,j)djdist(i, j) \leq d_j . Let's define dist(i,j)dist(i, j) as the distance between vertices ii and jj in tree or number of edges on the simple path between vertices ii and jj .

Vasya wants to solve this quiz using 80\leq 80 operations with the device and guess the tree. Help him!

输入格式

输出格式

In the beginning, your program should read one integer nn — the number of vertices of the tree which encrypts the device ( 2n10002 \leq n \leq 1000 ).

After that, you can make several operations in the following format. To do operation print a symbol"?" (without quotes) and nn integers d1,d2,,dnd_1, d_2, \ldots, d_n , separated by spaces after it. Please note, that for all ii you can only use the numbers, satisfying the inequality 0di<n0 \leq d_i < n . After that, you should read a string ss with length nn , consisting of symbols "0" and "1" (without quotes). For all ii the symbol sis_i is equal to "0", if the lamp on the device, connected with ii -th vertex of the tree is switched off and "1" otherwise.

After several operations, you should print guessed tree. To do it print the only symbol "!" (without quotes). In the next n1n-1 lines print 22 integers aia_i , bib_i — indexes of the vertices connected by ii -th edge of the tree. This numbers should satisfy the conditions 1ai,bin1 \leq a_i, b_i \leq n and aibia_i \neq b_i . This edges should form a tree, which is equal to the hidden tree. After that, your program should terminate.

It is guaranteed, that in each test the tree is fixed before and won't change depending on your program's operations.

Your program can make from 00 to 8080 operations with the device and after that guess the tree equal with the hidden.

If your program will make more than 8080 operations it can get any verdict, because it will continue reading from closed input. If your program will make operation or print the answer in the incorrect format, it can get any verdict too. Be careful.

Don't forget to flush the output after printing questions and answers.

To flush the output, you can use:

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

Hacks:

The first line should contain one integer nn — the number of vertices in the tree ( 2n10002 \leq n \leq 1000 ). Next n1n-1 lines should contain 22 integers aia_i , bib_i — indexes of the vertices connected by ii -th edge of the tree ( 1ai,bin1 \leq a_i, b_i \leq n , aibia_i \neq b_i ). All edges should form a tree. Be careful, extra spaces or line breaks are not allowed.

输入输出样例

  • 输入#1

    5
    00000
    11011
    11100
    10010
    

    输出#1

    ? 0 0 0 0 0
    ? 1 1 2 0 2
    ? 0 0 0 1 0
    ? 0 1 0 0 1
    !
    4 2
    1 5
    3 4
    4 1
    

说明/提示

It is a picture of the tree which encrypt the device from the first test:

It is a table of pairwise distances between vertices in this tree:

- If you make operation where d=[0,0,0,0,0]d = [0, 0, 0, 0, 0] , no lamp will switch on, because dist(i,j)>0dist(i, j) > 0 for all iji \neq j .

  • If you make operation where d=[1,1,2,0,2]d = [1, 1, 2, 0, 2] , all lamps except the lamp connected with the 33 -rd vertex will switch on. For example, lamp connected with the 11 -st vertex will switch on, because dist(1,5)=12=d5dist(1, 5) = 1 \leq 2 = d_5 .
  • If you make operation where d=[0,0,0,1,0]d = [0, 0, 0, 1, 0] , all lamps except lamps connected with the 44 -th and 55 -th vertices will switch on.
  • If you make operation where d=[0,1,0,0,1]d = [0, 1, 0, 0, 1] , only lamps connected with the 11 -st and 44 -th vertices will switch on.
首页