编程介的小学生 2017-10-17 23:32 采纳率: 20.5%
浏览 827
已采纳

Bee Garden

Description

George’s father Ben is fond of bee breeding. He has got a bee garden near his country house and he likes to walk around the garden and gather honey from the hives.

Ben has n hives, located at various points of his garden. Some of them are connected to each other or Ben’s house by straight roads. Ben always walks along the roads, and he never moves from one road to another anywhere except at hives. Neither Ben’s house nor any hive is located on a road.

The roads are organized in such a way, that Ben has exactly one way to get from his house to any hive.

Each week Ben makes a roundtrip. He starts from his house and walks by the roads in such a way that he visits each hive at least once. George once came to see his father and noticed that his father takes the shortest path that allows him to visit each hive and return to his house.

He thought that his father is getting older, so Ben must be getting really tired with all that walking. He decided to build another straight road that would help his father to visit all the hives faster. That road must connect two hives or a hive and Ben’s house. Help George to build the road in such a way that his father needs to walk as short a path as possible to visit all the hives and return home.

Note that neither Ben’s house nor any hive must be located on the new road.

Input

The first line of the input file contains n — the number of the hives (1 ≤ n ≤ 200).

Let us consider Ben’s garden located on a Cartesian plane in such a way that his house occupied the point (0, 0). The following n lines contain two integer numbers each — the coordinates of the hives. The coordinates do not exceed 10 000 by their absolute values, no two hives coincide, no hive is located at (0, 0). Let the hives be numbered from 1 to n.

The following n lines describe roads — each road is described by the numbers of hives it connects, Ben’s house is denoted by 0.

Output

Output two numbers — the numbers of the hives to be connected by the road. Output 0 instead of hive’s number for Ben’s house.

If there is no straight road that shortens Ben’s roundtrip output “-1”.

Sample Input

3
1 0
1 1
0 1
0 2
1 2
1 3
Sample Output

0 3

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-11-02 01:00
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架