Asteroid Rangers

Time limit1sMemory limit128 MB

Summary
Given n moving points, count how many times the minimum spanning tree over all future times changes, plus the initial build.
Level

Hard9 of 10

Topics
Minimum spanning tree, Geometry, Implementation, Greedy
Solved
No attempts yet

Problem

The year is 2112 and humankind has spread across the solar system. The Space Ranger Corps have built bases on asteroids throughout the system, and your job at the Asteroid Communications Ministry is to keep every base able to communicate with every other base as cheaply as possible.

You will not connect every pair of bases directly, because that would be far too expensive. Instead you build the smallest number of communication links so that any base can reach any other base, possibly relayed through intermediate bases. The cost of a link is proportional to the distance between the two bases it connects, so the cheapest network is a minimum spanning tree over the bases.

The catch is that asteroids move. Two bases that are close now may drift apart later, so the cheapest network can change over time. Whenever a cheaper network becomes available you switch to it, and because switching costs time and money you want to know how many times the network has to be built or rebuilt.

Assumptions: each asteroid is a single point; every asteroid moves in a straight line at constant velocity; no two asteroids ever occupy the same point at the same time. The cheapest network at time t=0t = 0 is unique, and whenever a network becomes cheapest at some time t≥0t \ge 0 it is the unique cheapest network throughout the interval t<s<t+10−6t < s < t + 10^{-6}.

You set up the cheapest network at time t=0t = 0 and rebuild it every time a strictly cheaper network becomes available. Report how many times the network is set up or rebuilt over all time t≥0t \ge 0: this is 11 for the initial network plus 11 for each moment at which the cheapest network changes. A network that was used before and later becomes cheapest again is counted every time it is rebuilt, so equal networks appearing at different times are not merged.

Input

The input contains one or more test cases and is read until end of file.

Each test case begins with a line containing an integer nn (2≤n≤502 \le n \le 50), the number of asteroid bases. Each of the next nn lines contains six integers xx, yy, zz, vxv_x, vyv_y, vzv_z: the first three give the base's position at time 00 (−150≤x,y,z≤150-150 \le x, y, z \le 150) and the last three give its velocity in space units per time unit (−100≤vx,vy,vz≤100-100 \le v_x, v_y, v_z \le 100).

Output

For each test case, print a single line Case X: k, where XX is the test case number (starting from 11) and kk is the number of times the communication network has to be built or rebuilt over all time t≥0t \ge 0.

Examples6

  1. Example 1

    Input
    3
    0 0 0 0 0 0
    5 0 0 0 0 0
    10 1 0 -1 0 0
    4
    0 0 0 1 0 0
    0 1 0 0 -1 0
    1 1 1 3 1 1
    -1 -1 2 1 -1 -1
    
    Expected output
    Case 1: 3
    Case 2: 3
    
  2. Example 2

    Input
    2
    0 0 0 0 0 0
    1 0 0 0 0 0
    
    Expected output
    Case 1: 1
    
  3. Example 3

    Input
    3
    0 0 0 0 0 0
    10 0 0 0 0 0
    0 10 0 0 0 0
    
    Expected output
    Case 1: 1
    
  4. Example 4

    Input
    3
    0 0 0 0 0 0
    5 0 0 0 0 0
    10 1 0 -1 0 0
    
    Expected output
    Case 1: 3
    
  5. Example 5

    Input
    2
    0 0 0 0 0 0
    3 0 0 0 0 0
    3
    0 0 0 0 0 0
    10 0 0 0 0 0
    0 10 0 0 0 0
    
    Expected output
    Case 1: 1
    Case 2: 1
    
  6. Example 6

    Input
    4
    0 0 0 1 0 0
    0 1 0 0 -1 0
    1 1 1 3 1 1
    -1 -1 2 1 -1 -1
    
    Expected output
    Case 1: 3