from heapq import heappop, heappush from math import inf, isinf import sys def printe(*args, end="\n", **kwargs): print(*args, end=end, file=sys.stderr, **kwargs) def main(): N, M, X = map(int, input().split()) graph = [{} for _ in range(N)] for _ in range(M): u, v, C, T = map(int, input().split()) graph[u - 1][v - 1] = (C + T * X, T) graph[v - 1][u - 1] = (C + T * X, T) distance = [(inf, inf)] * N distance[0] = (0, 0) queue = [(0, 0, 0)] while queue: c_total, c_t, c_n = heappop(queue) if distance[c_n][0] < c_total: continue for n_n, (n_total, n_t) in graph[c_n].items(): if distance[n_n][0] > c_total + n_total: distance[n_n] = (c_total + n_total, c_t + n_t) heappush(queue, (c_total + n_total, c_t + n_t, n_n)) if isinf(distance[N - 1][0]): print(-1) else: print(distance[N - 1][1] + (distance[N - 1] [0] - distance[N - 1][1] * X + X - 1) // X) if __name__ == "__main__": main()