Under construction

Still being built. Things may change

Vault Heist 2

Time limit2sMemory limit1024 MB

Summary
Jeonghu builds a tree of at most 100 vertices, each with at most 3 edges, that encodes a number up to 10^18 so Yeongu can recover it after one edge is cut.
Level

Hard9 of 10

Topics
Tree, Math, Implementation
Solved
No attempts yet

Problem

This is a two-step problem. In each test case, the program runs exactly twice. See the grading section for details.

Yeongu and Jeonghu are safecrackers who make money by robbing bank vaults. Today they plan to rob TT bank vaults. To rob one vault, Jeonghu first breaks into the bank system and finds the vault's password, an integer no greater than 101810^{18}. He then sends it to Yeongu through TTS (Tree Transmission System). If Yeongu recovers the correct password for every bank and opens every vault safely, both of them celebrate with a bonus party. Otherwise, the bank's security system arrests them.

Before the operation, the two met in secret and agreed on the following.

  • Before Yeongu enters a bank, he and Jeonghu agree on a rule for passing the password. They both know the password is an integer no greater than 101810^{18}.
  • Yeongu enters the bank, and Jeonghu breaks into the bank system to find the password. Following the agreed rule, Jeonghu builds a tree to send through TTS. The tree must satisfy the conditions below. Then he sends the number of vertices and the edge list to TTS.
    • The tree has between 11 and 100100 vertices. If the tree has NN vertices, its vertices are the positive integers from 11 to NN.
    • No vertex has four or more incident edges.
  • TTS has a critical bug: when it transmits a tree, at most one edge can be removed. The tree then splits into one or more connected components. TTS picks one of the largest components arbitrarily and discards the rest. If the remaining component has N′N' vertices, TTS renumbers its vertices 1,2,⋯N′1, 2, \cdots N'.
  • TTS sends N′N' and the edge list to Yeongu. TTS chooses the order of the edges arbitrarily.
  • Using the information from TTS and the rule agreed on earlier, Yeongu recovers the password. If it matches the password Jeonghu found, Yeongu opens the vault safely.

Play the roles of Yeongu and Jeonghu, open the vaults safely, and enjoy the bonus party.

Constraints

  • 1≤T≤10001 \le T \le 1000
  • Every number in the input is an integer.

Examples2

  1. Example 1

    Input
    0
    2
    2023
    1226
    
    Expected output
    7
    1 2
    2 3
    1 4
    4 5
    5 6
    5 7
    3
    1 2
    2 3
    
  2. Example 2

    Input
    1
    2
    5
    1 2
    1 3
    5 3
    3 4
    3
    3 2
    1 2
    
    Expected output
    2023
    1226