Under construction

Still being built. Things may change

Speedrun

Time limit10sMemory limit1024 MB

Summary
Marcel must visit every node of a hidden tree by reading short binary hints stored on the nodes while keeping failed goTo calls under a limit.
Level

Hard8 of 10

Topics
Tree, DFS, Bit manipulation
Solved
No attempts yet

Problem

Marcel started speedrunning in hopes of setting a new World Record (WR). Sadly, he cannot master the newly discovered strats, so he has to find a way to gain an unfair advantage.

The game he is trying to get good at is called Tree Souls III, and he is going for a WR in the full-tree% category.

As the name implies, the game takes place on a tree: a graph with NN vertices numbered from 11 to NN and N−1N - 1 edges, with no cycles.

The game works as follows. The character is placed on an arbitrary node in the tree. He can choose an integer xx and try to walk from his current node to node xx. If there is an edge between xx and his current node, he moves to xx. Otherwise nothing happens. A speedrun is valid if he visits each node at least once.

Here comes the cheating part. He does not know the edge-teleportation glitch, so he sets the seed for his world himself. That means he knows the shape of the tree before the run starts. Memorizing the tree would be too obvious, and he would be instantly banned from the speedrunning community. So he tampers with the code and puts hints in each node instead. A hint is a binary string of length ll, and ll is the same for every hint in every node. When he stands on a node, he can read the hint assigned to that node.

Constraints

  • 1≤N≤1 0001 ≤ N ≤ 1\,000
  • Let QQ be the number of calls to goTo that returned false. The constraints on ll and QQ that must be respected to earn score for each subtask are outlined below.

Examples1

  1. Example 1

    Input
    1
    
    Expected output
    1