#P15763. [JAG 2025 Summer Camp #1] Billion Tree

[JAG 2025 Summer Camp #1] Billion Tree

题目描述

This is an interactive problem.

The interaction consists of two phases.

Phase 1

You must first choose an integer NN (2N652 \leq N \leq 65). Then you must output the chosen NN and a tree TT on NN vertices satisfying the following conditions:

  • The vertices are numbered 1,2,,N1, 2, \ldots, N.
  • Each edge of TT has an integer weight between 00 and 10910^9, inclusive.

Phase 2

You are given an integer QQ, followed by QQ integers x1,x2,,xQx_1, x_2, \ldots, x_Q. For each ii (1iQ1 \leq i \leq Q), you must express xix_i as the sum of the weights of at most 5 paths in TT.

Formally, for each ii you must output:

  • an integer KK (1K51 \leq K \leq 5),
  • and KK pairs of vertices (u1,v1),(u2,v2),,(uK,vK)(u_1, v_1), (u_2, v_2), \ldots, (u_K, v_K),

such that

$$\begin{aligned} \sum_{j=1}^{K} w(u_j, v_j) = x_i, \end{aligned}$$

where w(u,v)w(u, v) denotes the weight of the path between vertices uu and vv in TT.

The weight of a path is defined as the sum of the weights of the edges contained in the path.

Interaction

The interaction proceeds as follows:

Phase 1

Choose an integer NN and a weighted tree TT, and output them in the following format:

$$\begin{aligned} & N \\ & a_1 \ b_1 \ c_1 \\ & \vdots \\ & a_{N-1} \ b_{N-1} \ c_{N-1} \end{aligned}$$

Each triple (ai,bi,ci)(a_i, b_i, c_i) represents an edge between vertices aia_i and bib_i with weight cic_i. The following conditions must hold:

  • 2N652 \leq N \leq 65
  • 1ai,biN(1iN1)1 \leq a_i, b_i \leq N \quad (1 \leq i \leq N - 1)
  • 0ci109(1iN1)0 \leq c_i \leq 10^9 \quad (1 \leq i \leq N - 1)

Phase 2

First, an integer QQ (1Q10 0001 \leq Q \leq 10\ 000) is given. Then, QQ integers x1,x2,,xQx_1, x_2, \ldots, x_Q (1xi1091 \leq x_i \leq 10^9) are given one by one. For each integer xix_i, you must output your answer in the following format:

$$\begin{aligned} & K \\ & u_1 \ v_1 \\ & \vdots \\ & u_K \ v_K \end{aligned}$$

Here KK (1K51 \leq K \leq 5) is the number of paths, and each pair (uj,vj)(u_j, v_j) represents a path between vertices uju_j and vjv_j.

Note that the value xix_i (i2i \geq 2) is provided only after the answer for xi1x_{i-1} has been printed.

Notes on Interactive Judging

The verdict will be indeterminate if there is malformed output during the interaction or your program quits prematurely. Terminate the program immediately after printing the answer, or the verdict will be indeterminate. As some environments require flushing the output buffers, make sure that your outputs are actually sent. Otherwise, your outputs will never reach the judge.




3
110


210




20
3
1 2 10
3 1 100


1
2 3

3
2 1
1 3
1 3

2
1 2
1 2