monopoly2

Time limit: 0.1s Memory limit: 256MB Input: Output:

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 NN spaces (numbered from 11 to NN) and MM directed connections between them. Here M=N1M=N-1. 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 11.

Definition: Let us have a permutation of the numbers from 11 to NN. We call the permutation an appropriate ordering of the spaces if the following condition holds - for every connection from space ii to space jj, ii has to be before jj 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 1,2,...,N1, 2, ..., N. 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 11 to NN (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 pp is the permutation of the numbers from 11 to NN in the question. The result is a boolean vector bb of size NN, where bi=1 (0i<N)b_i = 1 \ (0 \leq i < N) if and only if one of these holds:

  • there is a connection from space pjp_j to space pip_i with i<ji < j;
  • there is a space pjp_j for which bj=1b_j=1 and you can walk along the connections from pjp_j to pip_i.

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 11 to NN, you will get Wrong answer for the test. The complexity of the function is O(N)O(N). You can call this function at most 108N\frac{10^8}{N} 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

  • 1N1 0001 \leq N \leq 1 \ 000
  • M=N1M = N - 1
Subtask Points Required subtasks NN Other constraints
0 0 - - The map from the sample communication.
1 5 - 1 000\leq 1 \ 000 1,2,...,N1,2,...,N is the only appropriate ordering of the spaces.
2 6 00 6\leq 6 -
3 17 11 1 000\leq 1 \ 000 1,2,...,N1,2,...,N can also be obtained by: starting with space 11, after that listing the spaces with direct connections to 11, after that listing the spaces with direct connections to the second added space, and so on.
4 13 0,20,2 300\leq 300 -
5 59 040-4 1 000\leq 1 \ 000 If we start from space 11 and follow the connections, we cannot use more than 25 connections.

Scoring

Each test receives a score that is a fractional number between 00 and 11 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 cntcnt 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 cnt>108Ncnt > \frac{10^8}{N}, then the score is equal to 00.
  • Subtasks 00, 11, and 22.
    • If cnt108Ncnt \leq \frac{10^8}{N}, then the score is equal to 11.
  • Subtask 33.
    • If cnt10 000cnt \leq 10 \ 000, then the score is equal to 11.
    • If 10 000<cnt15 00010 \ 000 < cnt \leq 15 \ 000, then the score is equal to min(1 000cnt9 000,1)min(\frac{1 \ 000}{cnt - 9 \ 000}, 1).
    • If 15 000<cnt108N15 \ 000 < cnt \leq \frac{10^8}{N}, then the score is equal to 0.10.1.
  • Subtask 44.
    • If cnt50 000cnt \leq 50 \ 000, then the score is equal to 11.
    • If 50 000<cnt200 00050 \ 000 < cnt \leq 200 \ 000, then the score is equal to min(25 000cnt25 000,1)min(\frac{25 \ 000}{cnt - 25 \ 000}, 1).
    • If 200 000<cnt108N200 \ 000 < cnt \leq \frac{10^8}{N}, then the score is equal to 0.10.1.
  • Subtask 55.
    • If cnt170cnt \leq 170, then the score is equal to 11.
    • If 170<cnt1 000170 < cnt \leq 1 \ 000, then the score is equal to min((170+3000cnt+3000)3000cnt,1)min((\frac{170+3000}{cnt+3000})^{\frac{3000}{cnt}},1).
    • If 1 000<cnt20 0001 \ 000 < cnt \leq 20 \ 000, then the score is equal to min(170cnt0.4,0.5)min(\frac{170}{cnt}^{0.4},0.5).
    • If 20 000<cnt108N20 \ 000 < cnt \leq \frac{10^8}{N}, then the score is equal to 0.10.1..

Sample communication

Let we have the following illustration of a map with 55 spaces and 44 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 NN;
  • on each of the following N1N-1 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.".

Log in or sign up to be able to send submissions!