QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 128 MB Total points: 100

#4740. 地铁设计

Statistics

Byteasar 前往 Byteburg 旅行,并决定乘坐地铁出行。在火车站(与地铁站位于同一地点)下车后,他立即前往最近的自动售票机。价目表显示,火车站与机场之间的换乘是免费的,而对于任何其他路线,票价等于终点站之间的距离。为了方便旅客,价目表列出了从火车站和机场到所有其他车站的票价。

Byteasar 还发现,该地铁系统有 $n$ 个车站,由 $n-1$ 条正长度的隧道组成的经济网络连接,这些隧道连接了每一对车站(尽管大多数时候是间接连接的)。了解这些信息后,Byteasar 希望恢复该网络的结构,或者断定他所掌握的信息是不一致的。

输入格式

标准输入的第一行包含一个正整数 $n$,表示 Byteburg 的地铁站数量。车站编号从 $1$ 到 $n$,其中 $1$ 号站为火车站,$n$ 号站为机场。

第二行包含一个由 $n-2$ 个整数 $d_2, d_3, \dots, d_{n-1}$ 组成的序列,取值范围为 $[1, 1\,000\,000]$,各数之间用空格分隔;序列中的第 $i$ 个数给出了从火车站到 $i$ 号站的票价,这等于该路线的长度。

第三行包含一个类似的序列 $l_2, l_3, \dots, l_{n-1}$,指定了从机场出发到各站的票价。

输出格式

如果不存在与 Byteasar 的信息一致的网络,则输出一行单词 NIE(波兰语中的“不”)。

否则,输出的第一行应包含单词 TAK(波兰语中的“是”),接下来的 $n-1$ 行应描述车站之间的(直接)隧道:每行包含三个整数 $a, b$ 和 $c$,用空格分隔,表示有一条长度为 $c$ 的隧道连接 $a$ 号站和 $b$ 号站。如果存在多个正确答案,程序可以任意选择其中一个。

样例

输入格式 1

7
6 6 2 2 1
5 3 5 1 4

输出格式 1

TAK
1 5 2
5 7 1
5 2 4
7 3 3
1 4 2
1 6 1

说明

下图展示了一个与 Byteasar 的信息一致的网络(标注了隧道长度)。

样例测试

1ocen: $n = 1000, d_i = 1000 - i, l_i = i - 1$; 2ocen: $n = 1000, d_i = l_i = i - 1$; 3ocen: 随机测试 $n = 500\,000$,答案为 NIE。

评分

测试集由以下子任务组成。每个子任务内可能包含多个测试点。

子任务 数据范围 分值
1 $n \le 10, l_i, d_i \le 200$ 11
2 $n \le 3000, l_i, d_i \le 5000$ 22
3 $n \le 3000$ 16
4 $n \le 100\,000$ 33
5 $n \le 500\,000$ 18

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.