Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import sys

input = sys.stdin.readline

inf = 10**13

N,M,S = map(int,input().split())

data = [[] for _ in range(N)]

sumA = 0

for i in range(M):
    U,V,A,B = map(int,input().split())
    sumA += A
    U -= 1
    V -= 1
    data[U].append((B,V,A))###(距離, 行き先, 費用)
    data[V].append((B,U,A))###(距離, 行き先, 費用)

P = sumA

C = [0]*N
D = [0]*N

for i in range(N):
    C[i],D[i] = map(int,input().split())

dist = [[inf]*(P+1) for _ in range(N)]
#visit = [[0]*(P+1) for _ in range(N)]
###heapにぶち込んだことがあるかないか

q = [(0,0,min(S,P))]###(仮の最短距離, 頂点番号, 所持金)
heapq.heapify(q)

while q:
    v = heapq.heappop(q)
    if v[0] >= dist[v[1]][v[2]]:
        continue
    dist[v[1]][v[2]] = v[0]

    if v[2] + C[v[1]] <= P:
        heapq.heappush(q,(v[0]+D[v[1]],v[1],v[2]+C[v[1]]))

    for x in data[v[1]]:
        if x[2] > v[2]:
            continue
        heapq.heappush(q,(v[0]+x[0],x[1],v[2]-x[2]))
    
    ###
    #print(P)
    #print(q)
    #print(v)
    ###

for i in range(1,N):
    print(min(dist[i]))
        



Fixed submission:
import heapq
import sys

input = sys.stdin.readline

inf = 10**13

N,M,S = map(int,input().split())

data = [[] for _ in range(N)]

sumA = 0

for i in range(M):
    U,V,A,B = map(int,input().split())
    sumA += A
    U -= 1
    V -= 1
    data[U].append((B,V,A))###(距離, 行き先, 費用)
    data[V].append((B,U,A))###(距離, 行き先, 費用)

P = sumA

C = [0]*N
D = [0]*N

for i in range(N):
    C[i],D[i] = map(int,input().split())

dist = [[inf]*(P+1) for _ in range(N)]
#visit = [[0]*(P+1) for _ in range(N)]
###heapにぶち込んだことがあるかないか

q = [(0,0,min(S,P))]###(仮の最短距離, 頂点番号, 所持金)
heapq.heapify(q)

while q:
    v = heapq.heappop(q)
    if v[0] >= dist[v[1]][v[2]]:
        continue
    dist[v[1]][v[2]] = v[0]

    if v[2] + C[v[1]] <= P:
        if dist[v[1]][v[2]+C[v[1]]] == inf:
            heapq.heappush(q,(v[0]+D[v[1]],v[1],v[2]+C[v[1]]))

    for x in data[v[1]]:
        if x[2] > v[2]:
            continue
        if dist[x[1]][v[2]-x[2]] == inf:
            heapq.heappush(q,(v[0]+x[0],x[1],v[2]-x[2]))
    
    ###
    #print(P)
    #print(q)
    #print(v)
    ###

for i in range(1,N):
    print(min(dist[i]))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import sys

input = sys.stdin.readline

inf = 10**12

N,M,S = map(int,input().split())

data = [[] for _ in range(N)]

sumA = 0

for i in range(M):
    U,V,A,B = map(int,input().split())
    sumA += A
    U -= 1
    V -= 1
    data[U].append((B,V,A))###(距離, 行き先, 費用)
    data[V].append((B,U,A))###(距離, 行き先, 費用)

P = sumA

C = [0]*N
D = [0]*N

for i in range(N):
    C[i],D[i] = map(int,input().split())

dist = [[inf]*(P+1) for _ in range(N)]
#visit = [[0]*(P+1) for _ in range(N)]
###heapにぶち込んだことがあるかないか

q = [(0,0,min(S,P))]###(仮の最短距離, 頂点番号, 所持金)
heapq.heapify(q)

while q:
    v = heapq.heappop(q)
    if v[0] > dist[v[1]][v[2]]:
        continue
    dist[v[1]][v[2]] = v[0]

    if v[2] + C[v[1]] <= P:
        heapq.heappush(q,(v[0]+D[v[1]],v[1],v[2]+C[v[1]]))

    for x in data[v[1]]:
        if x[2] > v[2]:
            continue
        heapq.heappush(q,(v[0]+x[0],x[1],v[2]-x[2]))
    
    ###
    #print(P)
    #print(q)
    #print(v)
    ###

for i in range(1,N):
    print(min(dist[i]))
        



Fixed submission:
import heapq
import sys

input = sys.stdin.readline

inf = 10**13

N,M,S = map(int,input().split())

data = [[] for _ in range(N)]

sumA = 0

for i in range(M):
    U,V,A,B = map(int,input().split())
    sumA += A
    U -= 1
    V -= 1
    data[U].append((B,V,A))###(距離, 行き先, 費用)
    data[V].append((B,U,A))###(距離, 行き先, 費用)

P = sumA

C = [0]*N
D = [0]*N

for i in range(N):
    C[i],D[i] = map(int,input().split())

dist = [[inf]*(P+1) for _ in range(N)]
#visit = [[0]*(P+1) for _ in range(N)]
###heapにぶち込んだことがあるかないか

q = [(0,0,min(S,P))]###(仮の最短距離, 頂点番号, 所持金)
heapq.heapify(q)

while q:
    v = heapq.heappop(q)
    if v[0] >= dist[v[1]][v[2]]:
        continue
    dist[v[1]][v[2]] = v[0]

    if v[2] + C[v[1]] <= P:
        if dist[v[1]][v[2]+C[v[1]]] == inf:
            heapq.heappush(q,(v[0]+D[v[1]],v[1],v[2]+C[v[1]]))

    for x in data[v[1]]:
        if x[2] > v[2]:
            continue
        if dist[x[1]][v[2]-x[2]] == inf:
            heapq.heappush(q,(v[0]+x[0],x[1],v[2]-x[2]))
    
    ###
    #print(P)
    #print(q)
    #print(v)
    ###

for i in range(1,N):
    print(min(dist[i]))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

inf = 10**12

N,M,S = map(int,input().split())

data = [[] for _ in range(N)]

maxA = 0

for i in range(M):
    U,V,A,B = map(int,input().split())
    maxA = max(maxA,A)
    U -= 1
    V -= 1
    data[U].append((B,V,A))###(距離, 行き先, 費用)
    data[V].append((B,U,A))###(距離, 行き先, 費用)

P = maxA * (N-1)

C = [0]*N
D = [0]*N

for i in range(N):
    C[i],D[i] = map(int,input().split())

dist = [[inf]*(P+1) for _ in range(N)]
#visit = [[0]*(P+1) for _ in range(N)]
###heapにぶち込んだことがあるかないか

q = [(0,0,min(S,P))]###(仮の最短距離, 頂点番号, 所持金)
heapq.heapify(q)

while q:
    v = heapq.heappop(q)
    if v[0] > dist[v[1]][v[2]]:
        continue
    dist[v[1]][v[2]] = v[0]

    if v[2] + C[v[1]] <= P:
        heapq.heappush(q,(v[0]+D[v[1]],v[1],v[2]+C[v[1]]))

    for x in data[v[1]]:
        if x[2] > v[2]:
            continue
        heapq.heappush(q,(v[0]+x[0],x[1],v[2]-x[2]))
    
    ###
    #print(P)
    #print(q)
    #print(v)
    ###

for i in range(1,N):
    print(min(dist[i]))
        



Fixed submission:
import heapq
import sys

input = sys.stdin.readline

inf = 10**13

N,M,S = map(int,input().split())

data = [[] for _ in range(N)]

sumA = 0

for i in range(M):
    U,V,A,B = map(int,input().split())
    sumA += A
    U -= 1
    V -= 1
    data[U].append((B,V,A))###(距離, 行き先, 費用)
    data[V].append((B,U,A))###(距離, 行き先, 費用)

P = sumA

C = [0]*N
D = [0]*N

for i in range(N):
    C[i],D[i] = map(int,input().split())

dist = [[inf]*(P+1) for _ in range(N)]
#visit = [[0]*(P+1) for _ in range(N)]
###heapにぶち込んだことがあるかないか

q = [(0,0,min(S,P))]###(仮の最短距離, 頂点番号, 所持金)
heapq.heapify(q)

while q:
    v = heapq.heappop(q)
    if v[0] >= dist[v[1]][v[2]]:
        continue
    dist[v[1]][v[2]] = v[0]

    if v[2] + C[v[1]] <= P:
        if dist[v[1]][v[2]+C[v[1]]] == inf:
            heapq.heappush(q,(v[0]+D[v[1]],v[1],v[2]+C[v[1]]))

    for x in data[v[1]]:
        if x[2] > v[2]:
            continue
        if dist[x[1]][v[2]-x[2]] == inf:
            heapq.heappush(q,(v[0]+x[0],x[1],v[2]-x[2]))
    
    ###
    #print(P)
    #print(q)
    #print(v)
    ###

for i in range(1,N):
    print(min(dist[i]))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

inf = 10**12

N,M,S = map(int,input().split())

data = [[] for _ in range(N)]

maxA = 0

for i in range(M):
    U,V,A,B = map(int,input().split())
    maxA = max(maxA,A)
    U -= 1
    V -= 1
    data[U].append((B,V,A))###(距離, 行き先, 費用)
    data[V].append((B,U,A))###(距離, 行き先, 費用)

P = maxA * (N-1)

C = [0]*N
D = [0]*N

for i in range(N):
    C[i],D[i] = map(int,input().split())

dist = [[inf]*(P+1) for _ in range(N)]
#visit = [[0]*(P+1) for _ in range(N)]
###heapにぶち込んだことがあるかないか

q = [(0,0,min(S,P))]###(仮の最短距離, 頂点番号, 所持金)
heapq.heapify(q)

while q:
    v = heapq.heappop(q)
    if v[0] > dist[v[1]][v[2]]:
        continue
    dist[v[1]][v[2]] = v[0]

    if v[2] + C[v[1]] <= P:
        heapq.heappush(q,(v[0]+D[v[1]],v[1],v[2]+C[v[1]]))

    for x in data[v[1]]:
        if x[2] > v[2]:
            continue
        heapq.heappush(q,(v[0]+x[0],x[1],v[2]-x[2]))
    
    ###
    #print(P)
    #print(q)
    #print(v)
    ###

for i in range(1,N):
    print(min(dist[i]))
        



Fixed submission:
import heapq
import sys

input = sys.stdin.readline

inf = 10**13

N,M,S = map(int,input().split())

data = [[] for _ in range(N)]

sumA = 0

for i in range(M):
    U,V,A,B = map(int,input().split())
    sumA += A
    U -= 1
    V -= 1
    data[U].append((B,V,A))###(距離, 行き先, 費用)
    data[V].append((B,U,A))###(距離, 行き先, 費用)

P = sumA

C = [0]*N
D = [0]*N

for i in range(N):
    C[i],D[i] = map(int,input().split())

dist = [[inf]*(P+1) for _ in range(N)]
#visit = [[0]*(P+1) for _ in range(N)]
###heapにぶち込んだことがあるかないか

q = [(0,0,min(S,P))]###(仮の最短距離, 頂点番号, 所持金)
heapq.heapify(q)

while q:
    v = heapq.heappop(q)
    if v[0] >= dist[v[1]][v[2]]:
        continue
    dist[v[1]][v[2]] = v[0]

    if v[2] + C[v[1]] <= P:
        if dist[v[1]][v[2]+C[v[1]]] == inf:
            heapq.heappush(q,(v[0]+D[v[1]],v[1],v[2]+C[v[1]]))

    for x in data[v[1]]:
        if x[2] > v[2]:
            continue
        if dist[x[1]][v[2]-x[2]] == inf:
            heapq.heappush(q,(v[0]+x[0],x[1],v[2]-x[2]))
    
    ###
    #print(P)
    #print(q)
    #print(v)
    ###

for i in range(1,N):
    print(min(dist[i]))