← Home
```go
package main

import (
	"fmt"
	"math"
)

// Vector struct represents a 3D vector or point
type Vector struct {
	X, Y, Z float64
}

// Add returns the sum of two vectors
func (a Vector) Add(b Vector) Vector {
	return Vector{a.X + b.X, a.Y + b.Y, a.Z + b.Z}
}

// Sub returns the difference of two vectors
func (a Vector) Sub(b Vector) Vector {
	return Vector{a.X - b.X, a.Y - b.Y, a.Z - b.Z}
}

// Dot returns the dot product of two vectors
func (a Vector) Dot(b Vector) float64 {
	return a.X*b.X + a.Y*b.Y + a.Z*b.Z
}

// Scale returns the vector multiplied by a scalar
func (a Vector) Scale(s float64) Vector {
	return Vector{a.X * s, a.Y * s, a.Z * s}
}

// Len2 returns the squared length of the vector
func (a Vector) Len2() float64 {
	return a.Dot(a)
}

// solveQuad returns non-negative real roots of at^2 + bt + c = 0
func solveQuad(a, b, c float64) []float64 {
	// Handle the case where a is close to 0 (linear equation)
	if math.Abs(a) < 1e-9 {
		if math.Abs(b) < 1e-9 {
			return []float64{}
		}
		t := -c / b
		if t >= 0 {
			return []float64{t}
		}
		return []float64{}
	}

	delta := b*b - 4*a*c
	if delta < 0 {
		// Allow for small floating point errors
		if delta > -1e-9 {
			delta = 0
		} else {
			return []float64{}
		}
	}

	sqrtDelta := math.Sqrt(delta)
	t1 := (-b - sqrtDelta) / (2 * a)
	t2 := (-b + sqrtDelta) / (2 * a)

	var res []float64
	// We are looking for t >= 0. Since the Death Star and mines are initially disjoint,
	// collision happens at t > 0.
	if t1 >= 0 {
		res = append(res, t1)
	}
	if t2 >= 0 {
		res = append(res, t2)
	}
	return res
}

func main() {
	var Ax, Ay, Az, vx, vy, vz, R float64
	// Read Death Star parameters
	fmt.Scan(&Ax, &Ay, &Az, &vx, &vy, &vz, &R)
	A := Vector{Ax, Ay, Az}
	V := Vector{vx, vy, vz}

	var n int
	fmt.Scan(&n)

	minTime := 1e18 // Start with a large number
	found := false

	for i := 0; i < n; i++ {
		var Oix, Oiy, Oiz, ri float64
		var mi int
		fmt.Scan(&Oix, &Oiy, &Oiz, &ri, &mi)
		O := Vector{Oix, Oiy, Oiz}

		// 1. Check collision with the Mine Body
		// The mine body is a sphere centered at O with radius ri.
		// Collision occurs if distance between DS center and O is <= R + ri.
		// Let S be the initial position of DS relative to Mine: S = A - O
		S := A.Sub(O)
		radSum := R + ri

		// Equation: |S + Vt|^2 = radSum^2
		// |V|^2 t^2 + 2(S.V)t + |S|^2 - radSum^2 = 0
		a := V.Len2()
		b := 2 * S.Dot(V)
		c := S.Len2() - radSum*radSum

		roots := solveQuad(a, b, c)
		for _, t := range roots {
			if t < minTime {
				minTime = t
				found = true
			}
		}

		// 2. Check collision with each Spike
		for j := 0; j < mi; j++ {
			var px, py, pz float64
			fmt.Scan(&px, &py, &pz)
			P := Vector{px, py, pz} // Vector from O to spike tip
			pLen2 := P.Len2()

			// The spike is a segment from O to O+P.
			// The collision volume for the spike is a capsule of radius R around this segment.
			// This capsule is the union of:
			// - A sphere of radius R at O (covered by Mine Body check since R < R+ri)
			// - A sphere of radius R at O+P (Spike Tip)
			// - A cylinder of radius R around the segment

			// a. Spike Tip Collision
			// Sphere at O+P with radius R
			// DS Center relative to Tip: (A + Vt) - (O + P) = (S - P) + Vt
			S_tip := S.Sub(P)
			c_tip := S_tip.Len2() - R*R
			b_tip := 2 * S_tip.Dot(V)
			// a is same as before (|V|^2)

			rootsTip := solveQuad(a, b_tip, c_tip)
			for _, t := range rootsTip {
				if t < minTime {
					minTime = t
					found = true
				}
			}

			// b. Spike Cylinder Collision
			// Infinite cylinder of radius R around line passing through O with direction P.
			// We project the motion onto the plane perpendicular to P.
			
			sDotP := S.Dot(P)
			vDotP := V.Dot(P)

			// Calculate perpendicular components
			S_par := P.Scale(sDotP / pLen2)
			S_perp := S.Sub(S_par)

			V_par := P.Scale(vDotP / pLen2)
			V_perp := V.Sub(V_par)

			// Equation for cylinder collision: |S_perp + V_perp t|^2 = R^2
			a_cyl := V_perp.Len2()
			b_cyl := 2 * S_perp.Dot(V_perp)
			c_cyl := S_perp.Len2() - R*R

			rootsCyl := solveQuad(a_cyl, b_cyl, c_cyl)
			for _, t := range rootsCyl {
				// We must check if the collision happens within the segment bounds [0, 1].
				// The projection of the center onto the line is given by alpha * P.
				// alpha(t) = ((S + Vt) . P) / |P|^2
				alpha := (sDotP + vDotP*t) / pLen2
				if alpha >= 0 && alpha <= 1 {
					if t < minTime {
						minTime = t
						found = true
					}
				}
			}
		}
	}

	if !found {
		fmt.Println("-1")
	} else {
		fmt.Printf("%.9f\n", minTime)
	}
}
```