#GD0000228. Tấm bản đồ bị thất lạc (Lost Map)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tấm bản đồ bị thất lạc (Lost Map)
Lost Map
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
There are villages connected by exactly undirected roads, forming a tree. Every road has a positive integer length. You lost the road map but retained the distance table: is the total length along the unique route from village to village .
Recover the original direct road connections. The roads may be printed in any order and with either endpoint first.
Input
- The first line contains integer .
- The next lines each contain integers. Entry is the distance between villages . For , , while . The matrix is guaranteed to be a tree-distance matrix of positive edge lengths.
Output
Print lines, each containing for one original direct road. Print every road exactly once.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ma trận là metric đường đi trên một cây cạnh dương.
- Subtask 2 (30 points): ; ; ; ; ma trận là metric đường đi trên một cây cạnh dương.
- Subtask 3 (50 points): ; ; ; ; ma trận là metric đường đi trên một cây cạnh dương.
Examples
Input
4
0 1 1 2
1 0 2 3
1 2 0 3
2 3 3 0
Output
1 2
1 3
1 4
Explanation
Villages and each have distance from village , giving direct roads and . Village is at distance from village but from villages and , so the direct road is of length . Thus the three roads are .