Under construction

Still being built. Things may change

Particle Accelerator

Time limit5sMemory limit2048 MB

Summary
The accelerator is a tree of N rooms, and the task makes Q calls to generate with distinct room values v, but the statement never says what generate must return.
Level

Medium5 of 10

Topics
Tree, DFS
Solved
No attempts yet

Problem

The KOI research institute runs experiments with a particle accelerator. The accelerator has NN rooms and N−1N-1 two-way passages that connect them. Any two distinct rooms can reach each other using only passages, so the accelerator forms a tree.

Rooms are numbered with distinct integers from 00 to N−1N-1, and passages are numbered with distinct integers from 00 to N−2N-2. For every 0≤i≤N−20 \le i \le N-2, passage ii connects room A[i]A[i] and room B[i]B[i].

Constraints

  • 2≤Q≤N≤200 0002 \le Q \le N \le 200\,000
  • The accelerator forms a tree.
  • For all ii, 0≤A[i],B[i]≤N−10 \le A[i], B[i] \le N-1 and A[i]≠B[i]A[i] \neq B[i] (0≤i≤N−20 \le i \le N - 2).
  • For every call to the generate function, 0≤v≤N−10 \le v \le N-1, and each vv is a different value.

Examples1

  1. Example 1

    Input
    2 2
    0 1
    0
    1
    
    Expected output
    0
    1