#P5959. [POI 2018] Plan metra
[POI 2018] Plan metra
Problem Description
There is an unrooted tree with nodes. Each edge has a positive integer weight representing its length. The distance between two nodes is defined as the length of the shortest path between them in the tree.
You are given, for every node from to , its distance to node and its distance to node in the tree. Reconstruct the tree from this information.
Input Format
The first line contains a positive integer , representing the number of nodes.
The second line contains positive integers , representing the distance from each node to node .
The third line contains positive integers , representing the distance from each node to node .
Output Format
If there is no solution, output NIE.
Otherwise, output TAK on the first line. Then output lines, each containing three positive integers , indicating that there is a tree edge connecting nodes and with length .
If there are multiple solutions, output any one of them.
This problem uses a Special Judge.
7
6 6 2 2 1
5 3 5 1 4
TAK
1 5 2
5 7 1
5 2 4
7 3 3
1 4 2
1 6 1
Hint
For of the testdata, , , , .
Translated by ChatGPT 5