АВТ
Язык:

Дистанционный практикум по программированию

Задачи Online статус Соревнования
Новости Справка СДО
 
Здравствуйте, Гость! Войдите с паролем или зарегистрируйтесь.

1585. Road to Home

Ограничение времени: 1 сек.
Ограничение памяти:262144 КБайт
Баллы:100
Статистика Послать на проверку Задачу добавил debug

The favourite fairy-tale country of the H&H employees is Berland. Berland consists of N towns. Some of the towns are connected with the portals. All towns are numbered with numbers from 1 to N. The town with number i has portals to Mi closest towns (portals are unidirectional). If two or more towns are on the equal distance then towns with the smaller numbers are chosen. In Berland the distance between two points (x1, y1) and (x2, y2) is equal to min(|x1 - x2|, |y1 - y2|) + 1. For each transfer through the portal between two towns due should be paid. The due is equal to the square root of distance between the towns. The amount of due is rounded to the nearest integer using standard rules.

At the face of the war threat some of the towns are united to the United Union (UU). All towns from the UU are called union towns, and other towns are called non-union. To draw the citizens at the union side the following decision was made: the due of transfer from non-union city to the union one is decreased and the due for some other transfers is increased. So if X is a union town and Z is a non-union, the due for the transfer from Z to X is decreased by Dx and for the transfer from X to Z is increased by Dx. If W is also a union town and Y is a non-union, then the due for the transfer from X to W and back is increased by Dx + Dw and the due for the transfer between cities Z and Y is not changed.

Professor Perlov is visiting his grandchild in the town number N. And now he would like to get back to the town number 1. But he is unsure about the optimal route.

Your task is to help the professor to find the cheapest route from town N to town 1. Note, that it is even possible for the professor to earn some money — in this case you should find the route with maximum earning.

Входные данные

First line of the input file contains integer number N (1 ≤ N ≤ 10000). The following N lines contains the description of towns. Each description consists of 4 integer numbers: xi, yi, Mi, Di, where (xi, yi) are the town coordinates, Mi — number of portals in the town, Di — the due change or -1, if this is a non-union city. All coordinates are not more then 1000 by absolute value. You can assume that the sum of all Mi is not more then 1500000 and - 1 ≤ Di ≤ 25.

Выходные данные

Write to the output the optimal route for the professor — the sequence of the numbers of towns he should visit. You can assume that at least one route exists. If there are several solution, output any of them. If the professor can earn infinite amount of money, output only one number "-1".

Пример

Входные данные
5
0 0 1 10
1 1 3 10
1 0 4 -1
1 -2 4 10
4 5 3 -1
Выходные данные
5 3 1


Статистика Послать на проверку Обсуждение задачи Автор/источник:
Задачи с соревнований и сборов / Сборы в Перми 2009 / 07.07.09 Большой контест /
1584. C - Interesting Places 1585. 1586. E - Ant and Apples 1587. F - Square 1588. G - Pair
 
время генерации 0.703 сек.
© Copyright ВоГУ, АВТ, Носов Д.А., Андрианов И.А.