# https://yukicoder.me/problems/no/2739 import heapq MAX_INT = 10 ** 18 def main(): N, M, X = map(int, input().split()) next_nodes = [[] for _ in range(N)] for _ in range(M): u, v, C, T = map(int, input().split()) next_nodes[u - 1].append((v - 1, X * T + C)) next_nodes[v - 1].append((u - 1, X * T + C)) fix = [MAX_INT ] * N seen = [MAX_INT] * N seen[0] = 0 queue = [] heapq.heappush(queue, (0, 0)) while len(queue) > 0: cost, v = heapq.heappop(queue) if fix[v] < MAX_INT: continue fix[v] = cost for w, c in next_nodes[v]: if fix[w] < MAX_INT: continue new_cost = c + cost if seen[w] > new_cost: seen[w] = new_cost heapq.heappush(queue, (new_cost, w)) if fix[N - 1] == MAX_INT: print(-1) else: x = fix[N - 1] answer = x // X + (1 if x % X > 0 else 0) print(answer) if __name__ == "__main__": main()