#P10546. [THUPC 2024 决赛] 采矿

    ID: 12011 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2024交互题Special Judge随机化构造THUPC

[THUPC 2024 决赛] 采矿

Background

After carefully planning the workers’ moving routes and finishing all plans, you finally made money. You contracted a bigger mine pit and bought more advanced equipment.

However, after starting operation, you found that some mineral transport channels were installed in the wrong direction. Luckily, they can be reversed, and the central control system allows you to operate them easily.

But now the biggest problem is: you just took over this mine pit, and you do not even know what it looks like, let alone which switch corresponds to which transport channel.

Time is money. You want to figure out the whole structure of the mine pit and the mapping between all switches and channels as soon as possible.

Problem Description

This is an interactive problem.

Your mine pit has nn nodes, numbered 1n1\sim n. They are connected by n1n-1 transport channels, forming a tree.

All transport channels are directed. For a transport channel from node uu to node vv, all minerals produced at node uu or delivered to node uu can be transported to node vv at a faster speed. If a node has multiple outgoing transport channels, then these minerals will be evenly distributed among these channels.

The central control system contains n1n-1 switches and one monitor. The switches are numbered 1n11\sim n-1. Each switch can be set to position 00 or 11. The n1n-1 switches correspond one-to-one with the n1n-1 transport channels, but you do not know their correspondence. You only know that, suppose the transport channel corresponding to switch ii was installed as from uiu_i to viv_i, then when the switch is set to 00, its transport direction is the same as when it was installed; when the switch is set to 11, its transport direction becomes from viv_i to uiu_i. Your monitor can observe, for each node, how many different nodes its arriving minerals come from, that is, how many nodes (including itself) can transport minerals to this node through transport channels.

After you adjust the switch positions, you need to wait for a while until the monitor result becomes stable, and only then is your reading meaningful. Therefore, to avoid wasting too much time, you hope to determine all the information you want within 5050 readings.

Input Format

At the beginning, you need to input a positive integer nn. It is guaranteed that 2n100002\le n \le 10000.

After that, the input will generate readings based on your output. Each reading result is one line of nn positive integers, where the ii-th integer indicates how many different nodes the minerals arriving at node ii come from.

In each test case, the connection structure of the mine pit and the initial directions of all transport channels when they were installed are fixed, meaning they will not be dynamically changed into another scheme that is also consistent with all previous answers because of your output.

Output Format

When you need to adjust the switches and wait for a reading, output a line ? s, where s is a 01 string of length n1n-1, and the ii-th character indicates the position of switch ii. Then the interactive library will provide, on your standard input, the reading result after the monitor becomes stable. You may read at most 5050 times.

When you already know all channel information, output a line ! u1 v1 ... un-1 vn-1, where ui,viu_i,v_i indicate that the transport channel corresponding to switch ii was installed with direction from node uiu_i to node viv_i.

After outputting a line, you must flush the output buffer, otherwise the judging result may become TLE. The ways to flush the output buffer are:

  • C:fflush(stdout);

  • C++:fflush(stdout); or std::cout.flush(); or use std::endl for a newline

  • Java:System.out.flush();

  • Python:sys.stdout.flush()

5

1 4 1 2 3

1 1 2 3 4

? 0110

? 0000

! 1 4 2 3 2 4 4 5

Hint

The initial directions of the channels are shown in the figure above. The numbers on the channels represent the indices of the corresponding switches.

The sample is only used to explain the input/output format and the reading results, and does not mean that the answer can be derived from this reading.

The runtime and memory usage of the interactive library are not counted in the time and memory limits.

If you exceed the reading limit, the final answer is wrong, or the output format is wrong, the judging result will be WA.

Source and Acknowledgements

From the finals of THUPC2024 (Tsinghua University Student Programming Contest 2024 and Collegiate Invitational Contest). Thanks to THUSAA for providing this problem.

For testdata, statement, reference solution, editorial, etc., please refer to the official THUPC repository https://thusaac.com/public.

Translated by ChatGPT 5