After you helped Deni to make the perfect playing map for monopoly in 2021, she needs your help again! We recall that the playing map for monopoly consists of spaces (numbered from to ) and directed connections between them. Here . The directed connections fulfill the following conditions - there isn’t a connection from a space to itself and there aren’t different connections between the same pair of spaces. Also the connections have the property that every space is reachable from space .
Definition: Let us have a permutation of the numbers from to . We call the permutation an appropriate ordering of the spaces if the following condition holds - for every connection from space to space , has to be before in the permutation.
The problem for Deni is that she lost the perfect map for playing monopoly. Fortunately, her friend Bobi remembers the map but he decided to have some fun with her before letting her know the connections. Firstly, Bobi tells Deni that an appropriate ordering of the spaces is the sequence . After that Bobi will answer some questions from Deni to help her find out what are the connections between the spaces. Each question will be about how appropriate is some permutation of the numbers from to (for more details see section ”Implementation details”). Our heroine requests your assistance to come up and implement a strategy with the fewest questions possible.
Task
Write the program monopoly2 that determines the unknown connections with the fewest possible questions to Bobi. It must have the function find_connections which will be compiled with the jury’s program (for the role of Bobi).
Implementation details
Your function find_connections must have the following format:
std::vector <std::pair <int, int> > find_connections (int N);
It will be called once by the jury’s program with one parameter - the number of spaces. The function should return a list of ordered pairs describing the found connections between the spaces. The order of the ordered pairs in the list doesn’t matter.
The function for asking questions to Bobi has the following format:
std::vector <bool> check (std::vector <int> p);
The parameter is the permutation of the numbers from to in the question. The result is a boolean vector of size , where if and only if one of these holds:
- there is a connection from space to space with ;
- there is a space for which and you can walk along the connections from to .
Note that the unambiguity of the values follows from the properties of the connections.
If the sequence is not a valid permutation of the numbers from to , you will get Wrong answer for the test. The complexity of the function is . You can call this function at most times, otherwise you will get Wrong answer.
Your program monopoly2 must implement the function find_connections. It can also contain other code, functions, and global variables, but it must not contain the main function. Also, you should not read from the standard input or print to the standard output. Your program must include the header file monopoly2.h by instruction to the preprocessor:
#include "monopoly2.h"
Restrictions
| Subtask | Points | Required subtasks | Other constraints | |
|---|---|---|---|---|
| 0 | 0 | The map from the sample communication. | ||
| 1 | 5 | is the only appropriate ordering of the spaces. | ||
| 2 | 6 | |||
| 3 | 17 | can also be obtained by: starting with space , after that listing the spaces with direct connections to , after that listing the spaces with direct connections to the second added space, and so on. | ||
| 4 | 13 | |||
| 5 | 59 | If we start from space and follow the connections, we cannot use more than 25 connections. |
Scoring
Each test receives a score that is a fractional number between and inclusive. If a test has a positive score, it is considered successful for your solution. A test has a positive score if you successfully find the connections between the spaces.
If is the number of calls to the function check for a particular test, then the score of the test is calculated in the following way:
- For all subtasks: if , then the score is equal to .
- Subtasks , , and .
- If , then the score is equal to .
- Subtask .
- If , then the score is equal to .
- If , then the score is equal to .
- If , then the score is equal to .
- Subtask .
- If , then the score is equal to .
- If , then the score is equal to .
- If , then the score is equal to .
- Subtask .
- If , then the score is equal to .
- If , then the score is equal to .
- If , then the score is equal to .
- If , then the score is equal to ..
Sample communication
Let we have the following illustration of a map with spaces and connections.

| Actions of your program | Actions and answers of the jury |
|---|---|
find_connections(5) |
|
check({2, 3, 4, 5, 1}) |
return {1, 1, 1, 1, 0} |
check({1, 5, 2, 3, 4}) |
return {0, 1, 0, 0, 0} |
check({1, 4, 3, 2, 5}) |
return {0, 1, 1, 0, 0} |
return {{1, 2}, {2, 3}, {3, 4}, {2, 5}} |
Local testing
For local testing the following files are provided: monopoly2.h, Lgrader.cpp, sample file monopoly2.cpp for your program and file with the map from the sample communication. When the provided files are in the same folder, you can compile together your program monopoly2.cpp and Lgrader.cpp. This will make a program to check the correctness of your function.
The program will require from the standard input the following sequence of numbers:
- on the first line: one positive integer - the number of spaces ;
- on each of the following lines two positive integers which describe the directed connections.
If you don't follow the protocol for communication, you will get an appropriate error message. Otherwise, if the program is successful, you will get the message "Correctly found connections.".