#P9323. [EGOI 2022] Toy Design / 玩具设计

    ID: 10454 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2022交互题Special JudgeO2优化EGOI(欧洲/女生)

[EGOI 2022] Toy Design / 玩具设计

Background

Day 2 Problem C.

The statement is translated from EGOI2022 toydesign

CC BY-SA 3.0

Problem Description

This is an interactive problem with a grader.

You work at a company that designs toys. A toy that will be manufactured is as follows: there are nn pins, numbered from 11 to nn, sticking out of a box. Some pairs of pins are connected by wires inside the box. (In other words, the pins and wires form an undirected graph, where pins are nodes and wires are edges.) The wires cannot be seen from outside the box. The only way to obtain information about them is to use a detector on the pins: we choose two pins i,ji,j (iji\ne j), and the detector tells you whether these two pins are connected, either directly or indirectly. (So the detector tells you whether there is a path between these two pins in the graph.)

We call a wiring pattern a toy design.

You are using a dedicated software to query and build designs. The software works as follows: it starts from some design called “design 00”. It will not tell you what the wires inside the box look like. You need to repeatedly perform the following three-step operation:

  1. Choose a design aa and two pins i,ji,j (iji\ne j).
  2. The software tells you the detector result for these two pins. In other words, it tells you whether ii and jj are connected (directly or indirectly) in design aa.
  3. At the same time, if these two pins are not connected directly or indirectly in design aa, it creates a new design that contains all wires from design aa, and additionally adds one wire directly connecting ii and jj. The number of this design is the next available number. (So the first created design is design 11, then 22, and so on.) Note that this does not modify design aa; it only creates a new design that contains the additional wire.

Your goal is to use this operation to obtain as much information about design 00 as possible.

Note that it is not always possible to determine the exact wiring of design 00, because you cannot distinguish direct connections from indirect ones. For example, consider the following two designs with n=3n=3:

The detector would report that every pair of pins is connected in both designs, so we cannot distinguish them using the software above.

Your goal is to find any design that is equivalent to design 00. Two designs are equivalent if and only if, for every pair of pins, the detector returns the same result in both designs.

Output Format

Interaction

You need to implement a function:

void ToyDesign(int n, int max_ops);

Its purpose is to output a design that is equivalent to design 00. You can do this by calling the following two functions. The first function you can call is:

int Connected(int a, int i, int j);

Here 1i,jn1\le i,j\le n, iji\ne j, a0a\ge 0, and aa cannot exceed the number of designs currently available. If pins ii and jj are connected (directly or indirectly) in design aa, its return value is aa. Otherwise, its return value is the number of designs currently available plus one, i.e. the index of the new design that contains all wires of aa and one extra wire connecting ii and jj. The function Connected can be called at most max_ops times.

After your program has finished making the required Connected calls, it should describe a design equivalent to design 00. To describe a design, your program should call:

void DescribeDesign(std::vector<std::pair<int, int>> result);

The parameter result is a vector of integer pairs describing direct wire connections between pins. Each pair describes one wire and contains the numbers of the two pins it connects. Between any (unordered) pair of distinct pins, there must be at most one wire, and no wire may connect a pin to itself. Once you call this function, your program will be terminated.

Hint

Sample interaction

Contestant program Grader Explanation
ToyDesign(4, 20) There are 44 pins in the toy. Within 2020 calls to Connected, you must output any design equivalent to design 00.
Connected(0, 1, 2) returns 11. Pins 1,21,2 are not connected directly or indirectly in design 00. The new design is design 11.
Connected(1, 3, 2) returns 22. Pins 3,23,2 are not connected directly or indirectly in design 11. The new design is design 22.
Connected(0, 3, 4) returns 00. Pins 3,43,4 are connected directly or indirectly in design 00. No new design is created.
DescribeDesign({{3, 4}}) Describe a design with only one wire: connecting pins 3,43,4.

Constraints

For all testdata, 2n2002\le n\le 200.

  • Subtask 1 (1010 points): n200n\le 200, max_ops is 2000020000.
  • Subtask 2 (2020 points): n8n\le 8, max_ops is 2020.
  • Subtask 3 (3535 points): n200n\le 200, max_ops is 20002000.
  • Subtask 4 (3535 points): n200n\le 200, max_ops is 13501350.

Translated by ChatGPT 5