QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 2048 MB 总分: 100 交互

#16475. 十亿树

统计

这是一个交互式问题。

交互过程分为两个阶段。

第一阶段

你必须首先选择一个整数 $N$ ($2 \le N \le 65$)。然后你必须输出所选的 $N$ 以及一棵包含 $N$ 个顶点的树 $T$,满足以下条件:

  • 顶点编号为 $1, 2, \dots, N$。
  • $T$ 的每条边都有一个介于 $0$ 和 $10^9$ 之间(含边界)的整数边权。

第二阶段

给你一个整数 $Q$,接着是 $Q$ 个整数 $x_1, x_2, \dots, x_Q$。对于每个 $i$ ($1 \le i \le Q$),你必须将 $x_i$ 表示为 $T$ 中至多 $5$ 条路径的权值之和。

具体来说,对于每个 $i$,你必须输出:

  • 一个整数 $K$ ($1 \le K \le 5$),
  • 以及 $K$ 对顶点 $(u_1, v_1), (u_2, v_2), \dots, (u_K, v_K)$,

使得:

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

其中 $w(u, v)$ 表示树 $T$ 中顶点 $u$ 和 $v$ 之间路径的权值。

路径的权值定义为该路径所包含的所有边的权值之和。

交互

交互按以下步骤进行:

第一阶段

选择一个整数 $N$ 和一棵带权树 $T$,并按以下格式输出它们:

N
a1 b1 c1
...
aN-1 bN-1 cN-1

每个三元组 $(a_i, b_i, c_i)$ 表示一条连接顶点 $a_i$ 和 $b_i$ 且权值为 $c_i$ 的边。以下条件必须满足:

  • $2 \le N \le 65$
  • $1 \le a_i, b_i \le N$ ($1 \le i \le N - 1$)
  • $0 \le c_i \le 10^9$ ($1 \le i \le N - 1$)

第二阶段

首先,给定一个整数 $Q$ ($1 \le Q \le 10\,000$)。然后,逐个给出 $Q$ 个整数 $x_1, x_2, \dots, x_Q$ ($1 \le x_i \le 10^9$)。对于每个整数 $x_i$,你必须按以下格式输出你的答案:

K
u1 v1
...
uK vK

这里 $K$ ($1 \le K \le 5$) 是路径的数量,每个数对 $(u_j, v_j)$ 表示顶点 $u_j$ 和 $v_j$ 之间的路径。

注意,只有在输出了 $x_{i-1}$ 的答案之后,才会提供数值 $x_i$ ($i \ge 2$)。

说明

如果在交互过程中出现格式错误的输出,或者你的程序提前退出,判题结果将是未确定的(indeterminate)。在输出所有答案后请立即终止程序,否则判题结果也将是未确定的。由于某些环境需要刷新输出缓冲区,请确保你的输出确实已被发送。否则,你的输出将永远无法到达评测机。

样例

输入样例 1

3
110
210
20

输出样例 1

3
1 2 10
3 1 100
1
2 3
3
2 1
1 3
1 3
2
1 2
1 2

样例解释

在样例交互中:

  • 你的程序首先输出 $N = 3$ 和一棵有 2 条边的树:边 $(1, 2)$ 权值为 $10$,边 $(3, 1)$ 权值为 $100$。
  • 评测机输入 $Q = 3$,然后输入第一个询问 $x_1 = 110$。
  • 你的程序输出 $K = 1$ 条路径:$(2, 3)$。其权值为 $w(2, 3) = 10 + 100 = 110$。
  • 评测机输入第二个询问 $x_2 = 210$。
  • 你的程序输出 $K = 3$ 条路径:$(2, 1)$,$(1, 3)$,$(1, 3)$。其权值之和为 $w(2, 1) + w(1, 3) + w(1, 3) = 10 + 100 + 100 = 210$。
  • 评测机输入第三个询问 $x_3 = 20$。
  • 你的程序输出 $K = 2$ 条路径:$(1, 2)$,$(1, 2)$。其权值之和为 $w(1, 2) + w(1, 2) = 10 + 10 = 20$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.