from heapq import * INF = 10**18 def dijkstra(g, s, n): dist = [INF]*n hq = [(0, s)] dist[s] = 0 while hq: d, v = heappop(hq) if dist[v]!=d: continue for to, c in g[v]: if dist[v] + c < dist[to]: dist[to] = dist[v] + c heappush(hq, (dist[to], to)) return dist from math import ceil n, m, x = list(map(int, input().split())) g = [[] for _ in range(n)] for i in range(m): u,v,c,t = list(map(int, input().split())) u -= 1 v -= 1 g[u].append((v,t+c/x)) g[v].append((u,t+c/x)) dist = dijkstra(g, 0, n) if dist[-1] == INF: print(-1) else: print(ceil(dist[-1]))