Buggy python submission (verdict: Runtime Error):
import heapq

n,m,s=map(int,input().split())
limit=7
S=min(s,limit)
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[[float("inf") for _ in range(limit+1)] for _ in range(n+1)]
queue=[]

for i in range(m):
    u,v,a,b=map(int,input().split())
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

for k in range(s+1):
    time[1][k]=0

heapq.heappush(queue,(0,1,s))
while len(queue)!=0:
    t,v,c=heapq.heappop(queue)
    for nv,na,nb in path[v]:
        if na>c:
            continue
        elif time[nv][c-na]<=t+nb:
            continue
        else:
            time[nv][c-na]=t+nb
            heapq.heappush(queue,(t+nb,nv,c-na))

    nc=min(c+coin[v][0],limit)
    nt=t+coin[v][1]
    if time[v][nc]<=nt:
        continue
    else:
        time[v][nc]=nt
        heapq.heappush(queue,(nt,v,nc))
    
for i in range(2,n+1):
    print(min(time[i]))

Fixed submission:
import heapq

n,m,s=map(int,input().split())
limit=2500
s=min(s,limit)
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[[float("inf") for _ in range(limit+1)] for _ in range(n+1)]
queue=[]

for i in range(m):
    u,v,a,b=map(int,input().split())
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

time[1][s]=0
heapq.heappush(queue,(0,1,s))

while len(queue)!=0:
    t,v,c=heapq.heappop(queue)
    for nv,na,nb in path[v]:
        if na>c:
            continue
        elif time[nv][c-na]<=t+nb:
            continue
        else:
            time[nv][c-na]=t+nb
            heapq.heappush(queue,(t+nb,nv,c-na))

    nc=min(c+coin[v][0],limit)
    nt=t+coin[v][1]
    if time[v][nc]<=nt:
        continue
    else:
        time[v][nc]=nt
        heapq.heappush(queue,(nt,v,nc))
    
for i in range(2,n+1):
    print(min(time[i]))

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

n,m,s=map(int,input().split())
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[float("inf") for _ in range(n+1)]
time[0]=0
queue=[]
A=0
for i in range(m):
    u,v,a,b=map(int,input().split())
    A=max(a,A)
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

heapq.heappush(queue,(0,s,1,1))
while len(queue)!=0:
    t,c,v,d=heapq.heappop(queue)
    if time[v]>t:
        time[v]=t
    for nv,na,nb in path[v]:
        if na>c:
            continue
        else:
            heapq.heappush(queue,(t+nb,c-na,nv,d+1))
    if c > (n-d)*A:
        continue
    else:
        heapq.heappush(queue,(t+coin[v][1],c+coin[v][0],v,d))
    
print(*time[2:],sep="\n")

Fixed submission:
import heapq

n,m,s=map(int,input().split())
limit=2500
s=min(s,limit)
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[[float("inf") for _ in range(limit+1)] for _ in range(n+1)]
queue=[]

for i in range(m):
    u,v,a,b=map(int,input().split())
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

time[1][s]=0
heapq.heappush(queue,(0,1,s))

while len(queue)!=0:
    t,v,c=heapq.heappop(queue)
    for nv,na,nb in path[v]:
        if na>c:
            continue
        elif time[nv][c-na]<=t+nb:
            continue
        else:
            time[nv][c-na]=t+nb
            heapq.heappush(queue,(t+nb,nv,c-na))

    nc=min(c+coin[v][0],limit)
    nt=t+coin[v][1]
    if time[v][nc]<=nt:
        continue
    else:
        time[v][nc]=nt
        heapq.heappush(queue,(nt,v,nc))
    
for i in range(2,n+1):
    print(min(time[i]))

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

n,m,s=map(int,input().split())
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[float("inf") for _ in range(n+1)]
time[0]=0
queue=[]
A=0
for i in range(m):
    u,v,a,b=map(int,input().split())
    A=max(a,A)
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

heapq.heappush(queue,(0,s,1,1))
while len(queue)!=0:
    t,c,v,d=heapq.heappop(queue)
    if time[v]>t:
        time[v]=t
    for nv,na,nb in path[v]:
        if na>c:
            continue
        else:
            heapq.heappush(queue,(t+nb,c-na,nv,d+1))
    if c > (n-d)*A:
        continue
    else:
        heapq.heappush(queue,(t+coin[v][1],c+coin[v][0],v,d))
    
print(*time[2:],sep="\n")

Fixed submission:
import heapq

n,m,s=map(int,input().split())
limit=2500
s=min(s,limit)
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[[float("inf") for _ in range(limit+1)] for _ in range(n+1)]
queue=[]

for i in range(m):
    u,v,a,b=map(int,input().split())
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

time[1][s]=0
heapq.heappush(queue,(0,1,s))

while len(queue)!=0:
    t,v,c=heapq.heappop(queue)
    for nv,na,nb in path[v]:
        if na>c:
            continue
        elif time[nv][c-na]<=t+nb:
            continue
        else:
            time[nv][c-na]=t+nb
            heapq.heappush(queue,(t+nb,nv,c-na))

    nc=min(c+coin[v][0],limit)
    nt=t+coin[v][1]
    if time[v][nc]<=nt:
        continue
    else:
        time[v][nc]=nt
        heapq.heappush(queue,(nt,v,nc))
    
for i in range(2,n+1):
    print(min(time[i]))

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

n,m,s=map(int,input().split())
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[float("inf") for _ in range(n+1)]
time[0]=0
queue=[]
for i in range(m):
    u,v,a,b=map(int,input().split())
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

heapq.heappush(queue,(0,s,1))
while len(queue)!=0:
    t,c,v=heapq.heappop(queue)
    if time[v]>t:
        time[v]=t
    for nv,na,nb in path[v]:
        if na>c:
            continue
        else:
            heapq.heappush(queue,(t+nb,c-na,nv))
    if c > n*50:
        continue
    else:
        heapq.heappush(queue,(t+coin[v][1],c+coin[v][0],v))
    
print(*time[2:],sep="\n")

Fixed submission:
import heapq

n,m,s=map(int,input().split())
limit=2500
s=min(s,limit)
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[[float("inf") for _ in range(limit+1)] for _ in range(n+1)]
queue=[]

for i in range(m):
    u,v,a,b=map(int,input().split())
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

time[1][s]=0
heapq.heappush(queue,(0,1,s))

while len(queue)!=0:
    t,v,c=heapq.heappop(queue)
    for nv,na,nb in path[v]:
        if na>c:
            continue
        elif time[nv][c-na]<=t+nb:
            continue
        else:
            time[nv][c-na]=t+nb
            heapq.heappush(queue,(t+nb,nv,c-na))

    nc=min(c+coin[v][0],limit)
    nt=t+coin[v][1]
    if time[v][nc]<=nt:
        continue
    else:
        time[v][nc]=nt
        heapq.heappush(queue,(nt,v,nc))
    
for i in range(2,n+1):
    print(min(time[i]))

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

n,m,s=map(int,input().split())
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[float("inf") for _ in range(n+1)]
time[0]=0
queue=[]
for i in range(m):
    u,v,a,b=map(int,input().split())
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

heapq.heappush(queue,(0,s,1))
while len(queue)!=0:
    t,c,v=heapq.heappop(queue)
    if max(time)<t:
        continue

    if time[v]>t:
        time[v]=t

    for nv,na,nb in path[v]:
        if na>c:
            continue
        else:
            heapq.heappush(queue,(t+nb,c-na,nv))
    heapq.heappush(queue,(t+coin[v][1],c+coin[v][0],v))
    
print(*time[2:],sep="\n")


Fixed submission:
import heapq

n,m,s=map(int,input().split())
limit=2500
s=min(s,limit)
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[[float("inf") for _ in range(limit+1)] for _ in range(n+1)]
queue=[]

for i in range(m):
    u,v,a,b=map(int,input().split())
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

time[1][s]=0
heapq.heappush(queue,(0,1,s))

while len(queue)!=0:
    t,v,c=heapq.heappop(queue)
    for nv,na,nb in path[v]:
        if na>c:
            continue
        elif time[nv][c-na]<=t+nb:
            continue
        else:
            time[nv][c-na]=t+nb
            heapq.heappush(queue,(t+nb,nv,c-na))

    nc=min(c+coin[v][0],limit)
    nt=t+coin[v][1]
    if time[v][nc]<=nt:
        continue
    else:
        time[v][nc]=nt
        heapq.heappush(queue,(nt,v,nc))
    
for i in range(2,n+1):
    print(min(time[i]))

Buggy python submission (verdict: Runtime Error):
n,m,s=map(int,input().split())
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[float("inf") for _ in range(n+1)]
time[0]=0
queue=[]
for i in range(m):
    u,v,a,b=map(int,input().split())
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

heapq.heappush(queue,(0,s,1))
while len(queue)!=0:
    t,c,v=heapq.heappop(queue)
    if max(time)<t:
        continue

    if time[v]>t:
        time[v]=t

    for nv,na,nb in path[v]:
        if na>c:
            continue
        else:
            heapq.heappush(queue,(t+nb,c-na,nv))
    heapq.heappush(queue,(t+coin[v][1],c+coin[v][0],v))
    
print(*time[2:],sep="\n")

Fixed submission:
import heapq

n,m,s=map(int,input().split())
limit=2500
s=min(s,limit)
path=[[] for _ in range(n+1)]
coin=[(0,0)]
time=[[float("inf") for _ in range(limit+1)] for _ in range(n+1)]
queue=[]

for i in range(m):
    u,v,a,b=map(int,input().split())
    path[u].append((v,a,b))
    path[v].append((u,a,b))

for i in range(n):
    c,d=map(int,input().split())
    coin.append((c,d))

time[1][s]=0
heapq.heappush(queue,(0,1,s))

while len(queue)!=0:
    t,v,c=heapq.heappop(queue)
    for nv,na,nb in path[v]:
        if na>c:
            continue
        elif time[nv][c-na]<=t+nb:
            continue
        else:
            time[nv][c-na]=t+nb
            heapq.heappush(queue,(t+nb,nv,c-na))

    nc=min(c+coin[v][0],limit)
    nt=t+coin[v][1]
    if time[v][nc]<=nt:
        continue
    else:
        time[v][nc]=nt
        heapq.heappush(queue,(nt,v,nc))
    
for i in range(2,n+1):
    print(min(time[i]))