// @EXPECTED_RESULTS@: WRONG_ANSWER,TIME_LIMIT_EXCEEDED import java.util.* fun main() { val (n, m, t) = readln().split(" ").map { it.toInt() } val graph = System.`in`.bufferedReader().lineSequence().take(m) .flatMap { line -> val (a, b, l, v) = line.split(" ").map { it.toInt() } // add reverse connections too listOf(a to (b to (l to v)), (b to (a to (l to v)))) }.groupBy({ it.first }) { it.second } // Binary search var low = 0.0 var high = 1e11 while (high - low > 1e-6 && 1 - low / high > 1e-6) { val mid = (low + high) / 2 // dijkstra val distances = DoubleArray(n + 1) { Double.MAX_VALUE } distances[1] = 0.0 val queue = PriorityQueue>(Comparator.comparing { distances[it.first] }) queue.add(1 to 0.0) fun Pair.cost() = first / (second + mid) while (queue.isNotEmpty()) { val (location, cost) = queue.poll() // don't continue on more expensive paths if (cost > distances[location]) continue graph[location]!! .map { (b, v) -> b to (v.cost() + cost) } // only consider faster routes to b .filter { (b, cost) -> cost < distances[b] } // Update distances .onEach { (b, c) -> distances[b] = c } .toCollection(queue) } if (distances[n] > t) low = mid + 1e-7 else high = mid - 1e-7 } println(low) }