Under construction

Still being built. Things may change

Count

Time limit6sMemory limit2048 MB

Summary
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 (T,I,SV,SE,ι)(T, I, S_V, S_E, \iota) is given, where:

  • TT is a rooted tree with nn vertices, T=(V,E)T = (V, E), where VV is the vertex set and EE is the edge set. The vertices are numbered 1,2,…,n1, 2, \ldots, n, and the root is vertex 1.
  • II is a set whose elements are called information. There are two special elements: the unit element ϵ\epsilon and the illegal element ⊥\perp. 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 o∈I∖{ϵ,⊥}o \in I \setminus \{\epsilon, \perp\}, the vertex set SV(o)S_V(o) is a subset of VV with ∣SV(o)∣=2|S_V(o)| = 2.
  • For o∈I∖{⊥}o \in I \setminus \{\perp\}, the edge set SE(o)S_E(o) is a subset of EE. The edge set of the unit element is empty: SE(ϵ)=∅S_E(\epsilon) = \emptyset.
  • For every edge e=(u,v)∈Ee = (u, v) \in E, there is information ι(e)∈I\iota(e) \in I with SV(ι(e))={u,v}S_V(\iota(e)) = \{u, v\} and SE(ι(e))={e}S_E(\iota(e)) = \{e\}.

Information is combined by two operations, RR and CC. For all a,b∈Ia, b \in I, let r=R(a,b)r = R(a, b) and c=C(a,b)c = C(a, b), where r,c∈Ir, c \in I.

  1. If a=ϵa = \epsilon, then r=c=br = c = b. If b=ϵb = \epsilon, then r=c=ar = c = a.
  2. If a=⊥a = \perp or b=⊥b = \perp, then r=c=⊥r = c = \perp.
  3. Otherwise, if SE(a)∩SE(b)≠∅S_E(a) \cap S_E(b) \neq \emptyset or ∣SV(a)∩SV(b)∣≠1|S_V(a) \cap S_V(b)| \neq 1, then r=c=⊥r = c = \perp.
  4. Otherwise, SE(r)=SE(c)=SE(a)∪SE(b)S_E(r) = S_E(c) = S_E(a) \cup S_E(b), SV(r)=SV(a)S_V(r) = S_V(a), and SV(c)=SV(a)⊕SV(b)S_V(c) = S_V(a) \oplus S_V(b), where A⊕B=(A∪B)∖(A∩B)A \oplus B = (A \cup B) \setminus (A \cap B).

The distance between two vertices of TT is the number of edges on the unique simple path joining them.

You are given qq queries. Each query has a vertex uu and a non-negative integer dd. Let XX be the set of vertices whose distance to uu is at most dd, and let Y={(a,b)∈E∣a,b∈X}Y = \{(a, b) \in E \mid a, b \in X\} be the set of edges with both endpoints in XX.

It can be shown that, starting from ϵ\epsilon and all ι(e)\iota(e) (e∈Ee \in E), a finite number of calls to RR and CC produces information oo with o≠⊥o \neq \perp and SE(o)=YS_E(o) = Y. If d=0d = 0, the output must be the unit element ϵ\epsilon.

For each query, construct such an information oo, using at most MM calls to RR and CC in total.

Constraints

For all test cases, 1≤n≤2×1051 \leq n \leq 2 \times 10^5 and 1≤q≤1061 \leq q \leq 10^6. For each query, 1≤u≤n1 \leq u \leq n and 1≤d≤n−11 \leq d \leq n-1.

TestCasen=n=q=q=PropertyM=M=
111000100010410^4500500
222000200010410^4500500
3,43,410510^510610^6A55
5,65,66×1046 \times 10^46×1046\times 10^4B5050
776×1046 \times 10^46×1046 \times 10^4B55
8810510^510510^5B55
99750075005×1045 \times 10^4C500500
101010410^45×1045 \times 10^4500500
11111.5×1041.5 \times 10^45×1045 \times 10^4500500
12122×1042 \times 10^45×1045 \times 10^45050
13132.5×1042.5 \times 10^45×1045 \times 10^455
14143×1043 \times 10^410510^555
15156×1046 \times 10^410610^6D55
16166×1046 \times 10^410610^655
17178×1048 \times 10^410610^655
181810510^510610^655
19191.5×1051.5 \times 10^510610^655
20202×1052 \times 10^510610^611
  • Property A: For all i=1,2,…,n−1i = 1, 2, \ldots, n-1, the parent of i+1i+1 is ii.
  • Property B: For all queries, u=1u = 1.
  • Property C: For all queries, d≤100d \leq 100.
  • Property D: For all queries, d≥1000d \geq 1000.

Examples1

  1. Example 1

    Input
    2
    1 2
    1
    2 1
    
    Expected output
    1 2