Count
Time limit6sMemory limit2048 MB
Given a rooted tree and queries (u, d), build the edge set induced by vertices within distance d of u using at most M calls to R and C.
- Level
Hard9 of 10
- Topics
- Tree, Divide and conquer, Dynamic programming
- Solved
- No attempts yet
Problem
This is an interactive problem.
A quintuple is given, where:
- is a rooted tree with vertices, , where is the vertex set and is the edge set. The vertices are numbered , and the root is vertex 1.
- is a set whose elements are called information. There are two special elements: the unit element and the illegal element . General information has two attributes, a vertex set and an edge set. The unit element has only an edge set attribute. The illegal element has neither.
- For general information , the vertex set is a subset of with .
- For , the edge set is a subset of . The edge set of the unit element is empty: .
- For every edge , there is information with and .
Information is combined by two operations, and . For all , let and , where .
- If , then . If , then .
- If or , then .
- Otherwise, if or , then .
- Otherwise, , , and , where .
The distance between two vertices of is the number of edges on the unique simple path joining them.
You are given queries. Each query has a vertex and a non-negative integer . Let be the set of vertices whose distance to is at most , and let be the set of edges with both endpoints in .
It can be shown that, starting from and all (), a finite number of calls to and produces information with and . If , the output must be the unit element .
For each query, construct such an information , using at most calls to and in total.
Constraints
For all test cases, and . For each query, and .
- Property A: For all , the parent of is .
- Property B: For all queries, .
- Property C: For all queries, .
- Property D: For all queries, .