F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Starloop System

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1179    Accepted Submission(s): 410


Problem Description
At the end of the 200013th year of the Galaxy era, the war between Carbon-based lives and Silicon civilization finally comes to its end with the Civil Union born from the ruins. The shadow fades away, and the new-born Union is opening a new page.

Although the war ended, the affect of the war is far from over. Now the council is busy fixing the transportation system. Before the war, all the stars were connected with artificial wormholes which were destroyed during the war. At the same time, natural wormholes are breaking down with the growing traffic. A new traffic system is on the schedule.

As two civilizations combine, the technology integrates. Scientists find a new traffic system called the Starloop System.

This system is made up of several starloops. People build a starway to connect two stars. A startloop is a closed path with no repetitions of stars or starways allowed, other than the repetition of the starting and ending star. And a starloop contains at least two starts and two starways. A startloop's cost is the sum of the length of all the starways in it. Length of a starway connecting two stars is floor(x), which x is the euclidean distance between two stars. You can build more than one starway between any two stars, but one starway can only belongs to one starloop.



As the picture above shows, there are two starloops. One is blue and the other one is brown.

As a starloop is set up, each star on the starloop will get a unit of star-energy. So the two blue stars can get one unit of star-energy, and at the same time the black two stars can get two units because they both belong to two starloops. When a star earns a certain number of energy units, the transporter on that star will be activated. One can easily travel between any two stars whose transporter is activated.

Now the council wants to know the minimal cost to build a starloop system on all the stars . In other words, every star's transporter should be activated
 

Input
There are multiple test cases.
For each test case:
There is a line with one integer n which is the number of stars.

The following n lines each describes a star by four integers xi, yi, zi and wi, defined as the spatial coordinate and the number of energy units the star needs to activate the transporter. Please NOTE that getting more than wi energy units will put the star in a dangerous situation, so it is not allowed.
The input ends with n = 0.

1<=n<=100
|xi|,|yi|,|zi|<=200
wi<=50


 

Output
For each test case, output one line that contains an integer equals to the minimal cost you can get. If there is no solution, just output -1;
 

Sample Input
3 0 0 2 1 0 2 0 1 2 0 0 1 3 0 0 2 2 0 2 0 1 2 0 0 1 3 0 0 2 3 0 2 0 1 2 0 0 1 0
 

Sample Output
6 8 -1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-20 00:44:37, Gzip enabled