Buggy python submission (verdict: Time Limit Exceeded):
import heapq
def main():
    N, M, S = map(int, input().split())
    money_max = 50*N
    S = min(S, money_max-1)
    dp = [[float("inf")]*(money_max) for _ in range(N)]
    dp[0][S] = 0
    G = [[] for _ in range(N)]
    exchange = [None]*N
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        u, v = u-1, v-1
        G[u].append([v, a, b])
        G[v].append([u, a, b])
    for i in range(N):
        c, d = map(int, input().split())
        exchange[i] = [c, d]
    q = []
    heapq.heapify(q)
    heapq.heappush(q, [0, 0])
    time_min = [float("inf")]*N
    time_min[0] = 0
    while 0 < len(q):
        pre_time, p = heapq.heappop(q)
        if time_min[p] < pre_time:
            continue
        for i in range(money_max - exchange[p][0]):
            if dp[p][i] < float("inf"):
                dp[p][i+exchange[p][0]] = min(dp[p][i+exchange[p][0]], dp[p][i] + exchange[p][1])
        for to, money, time in G[p]:
            f = False
            for i in range(money, money_max):
                if dp[p][i] < float("inf") and dp[to][i-money] > dp[p][i] + time:
                    dp[to][i-money] = dp[p][i] + time
                    if dp[to][i-money] < time_min[to]:
                        time_min[to] = dp[to][i-money]
                    f = True
            if f:
                heapq.heappush(q, [time_min[to], to])
    for i in range(1, N):
        print(time_min[i])

if __name__ == "__main__":
    main()

Fixed submission:
import heapq
def main():
    N, M, S = map(int, input().split())
    money_max = 50*N
    S = min(S, money_max)
    dp = [[float("inf")]*(money_max+1) for _ in range(N)]
    dp[0][S] = 0
    G = [[] for _ in range(N)]
    exchange = [None]*N
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        u, v = u-1, v-1
        G[u].append([v, a, b])
        G[v].append([u, a, b])
    for i in range(N):
        c, d = map(int, input().split())
        exchange[i] = [c, d]
    q = []
    heapq.heapify(q)
    heapq.heappush(q, [0, 0, S])
    while 0 < len(q):
        pre_time, idx, s = heapq.heappop(q)
        if dp[idx][s] < pre_time:
            continue
        ex = min(s + exchange[idx][0], money_max)
        if dp[idx][s] + exchange[idx][1] < dp[idx][ex]:
            dp[idx][ex] = dp[idx][s] + exchange[idx][1]
            heapq.heappush(q, [dp[idx][ex], idx, ex])
        for to, money, time in G[idx]:
            if money <= s:
                if dp[idx][s] + time < dp[to][s-money]:
                    dp[to][s-money] = dp[idx][s] + time
                    heapq.heappush(q, [dp[to][s-money], to, s-money])
    for i in range(1, N):
        print(min(dp[i]))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
def main():
    N, M, S = map(int, input().split())
    money_max = 50*N
    S = min(S, money_max-1)
    dp = [[float("inf")]*(money_max) for _ in range(N)]
    dp[0][S] = 0
    G = [[] for _ in range(N)]
    exchange = [None]*N
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        u, v = u-1, v-1
        G[u].append([v, a, b])
        G[v].append([u, a, b])
    for i in range(N):
        c, d = map(int, input().split())
        exchange[i] = [c, d]
    q = []
    heapq.heapify(q)
    heapq.heappush(q, [0, 0])
    time_min = [float("inf")]*N
    time_min[0] = 0
    while 0 < len(q):
        pre_time, p = heapq.heappop(q)
        if time_min[p] < pre_time:
            continue
        for i in range(money_max - exchange[p][0]):
            if dp[p][i] < float("inf"):
                dp[p][i+exchange[p][0]] = min(dp[p][i+exchange[p][0]], dp[p][i] + exchange[p][1])
        for to, money, time in G[p]:
            f = False
            for i in range(money, money_max):
                if dp[p][i] < float("inf") and dp[to][i-money] > dp[p][i] + time:
                    f = True
                    break
            if f:
                for i in range(money, money_max):
                    if dp[p][i] < float("inf") and dp[to][i-money] > dp[p][i] + time:
                        dp[to][i-money] = dp[p][i] + time
                        if dp[to][i-money] < time_min[to]:
                            time_min[to] = dp[to][i-money]
                heapq.heappush(q, [time_min[to], to])
    for i in range(1, N):
        print(time_min[i])

if __name__ == "__main__":
    main()

Fixed submission:
import heapq
def main():
    N, M, S = map(int, input().split())
    money_max = 50*N
    S = min(S, money_max)
    dp = [[float("inf")]*(money_max+1) for _ in range(N)]
    dp[0][S] = 0
    G = [[] for _ in range(N)]
    exchange = [None]*N
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        u, v = u-1, v-1
        G[u].append([v, a, b])
        G[v].append([u, a, b])
    for i in range(N):
        c, d = map(int, input().split())
        exchange[i] = [c, d]
    q = []
    heapq.heapify(q)
    heapq.heappush(q, [0, 0, S])
    while 0 < len(q):
        pre_time, idx, s = heapq.heappop(q)
        if dp[idx][s] < pre_time:
            continue
        ex = min(s + exchange[idx][0], money_max)
        if dp[idx][s] + exchange[idx][1] < dp[idx][ex]:
            dp[idx][ex] = dp[idx][s] + exchange[idx][1]
            heapq.heappush(q, [dp[idx][ex], idx, ex])
        for to, money, time in G[idx]:
            if money <= s:
                if dp[idx][s] + time < dp[to][s-money]:
                    dp[to][s-money] = dp[idx][s] + time
                    heapq.heappush(q, [dp[to][s-money], to, s-money])
    for i in range(1, N):
        print(min(dp[i]))

if __name__ == "__main__":
    main()