QOJ.ac

QOJ

Limite de temps : 0.5 s Limite de mémoire : 1024 MB Points totaux : 100 Interactif

#5015. Tree

Statistiques

Background

Little G created an easy problem, but Little F strengthened it on a whim...

Description

This is an interactive problem.

There is a tree with $n$ ($n \le 1\,000$) nodes, where all edge weights are $1$, but you do not know which pairs of nodes are connected by edges.

However, you can query the sum of distances from a node to a set of nodes to find the hidden edges.

Specifically, you can use $ask(u, V)$, where $V$ is a set (with distinct elements), which returns $\sum_{x \in V} dist(u, x)$, where $dist(x, y)$ is the length of the shortest path between nodes $x$ and $y$ in the tree. You need to report all found edges using $answer(u, v)$.

The number of queries must not exceed $A$, and the sum of $|V|$ across all queries must not exceed $B$.

Implementation Details

This problem only supports C++11 or higher.

You must include the following header at the beginning of your code:

#include "tree.h"

You do not need to implement the main function; you only need to implement the following function:

void solver(int n, int A, int B)

This function will be called once at the beginning of each test case.

You may call the following function at most $A$ times, such that the sum of the sizes of $v$ does not exceed $B$, and elements within $v$ must be distinct in a single call:

int ask(int u, vector <int> v)

This returns the sum of distances from node $u$ to all nodes in $v$.

After determining the answer, you must call the following function exactly $n-1$ times:

void answer(int u, int v)

This indicates that there is a tree edge between $u$ and $v$.

The tree is fixed before the interaction begins; the interactor is not adaptive.

Input

The first line contains three integers $n, A, B$.

The next $n-1$ lines each contain two integers $u, v$, representing a tree edge.

Output

If the input format or query format is incorrect, the system will output Invalid and provide the reason for the error.

If the number of queries exceeds $A$, it will output Too many queries.

If the sum of the sizes of the queried sets $v$ exceeds $B$, it will output The sum is too large.

If the reported edges are incorrect, it will output Different tree.

If the answer is correct, it will output Correct cnt=x sum=y, where $x$ is the total number of queries and $y$ is the total sum of the sizes of $v$.

Examples

Input 1

3 114 514
1 2
2 3

Output 1

Correct cnt=2 sum=3

Note 1

tree.cpp : ask(1,{2,3})
grader.cpp : 3
tree.cpp : ask(1,{2})
grader.cpp : 1
tree.cpp : answer(1,2)
tree.cpp : answer(2,3)
grader.cpp : Correct cnt=2 sum=3

Constraints

Subtask 1 (3 points): $n \le 1\,000, A = 5 \times 10^5, B = 5 \times 10^5$.

Subtask 2 (17 points): $n \le 100, A = 3 \times 10^3, B = 3 \times 10^4$.

Subtask 3 (20 points): $n \le 1\,000, A = 5 \times 10^4, B = 3 \times 10^6$.

Subtask 4 (60 points): $n \le 1\,000, A = 8\,500, B = 3 \times 10^5$.

The time and memory used by the interactor are negligible and can be ignored.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.