Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

N, M, Start, Goal = map(int, input().split())
Start -= 1
Goal -= 1
adj_list = [[] for _ in range(N)]
for i in range(M):
  u, v, yen, sunuke = map(int, input().split())
  u -= 1
  v -= 1
  adj_list[u].append([u, v, yen, sunuke])
  adj_list[v].append([v, u, yen, sunuke])

def dijkstra(start, changed):
  res = [ -1 for _ in range(N) ]
  q = [[0, start]]
  visited = {}

  while len(q)>0:
    money, city = heappop(q)
    if res[city]>=0:
      continue
    res[city] = money

    for from_city, to_city, yen, sunuke  in adj_list[city]:
      cost = sunuke if changed else yen
      heappush(q, [money+cost, to_city])
        

  return res


min_yen_path = dijkstra(Start, False)
min_sunuke_path = dijkstra(Goal, True)

res = []
max_sunuke = 0
for i in reversed(range(N)):
  s = 10**15-min_yen_path[i]-min_sunuke_path[i]
  max_sunuke = max([s, max_sunuke]) 
  res.append(max_sunuke)
  
for i in reversed(res):
  print(i)


Fixed submission:
from heapq import heappush, heappop

N, M, Start, Goal = map(int, input().split())
Start -= 1
Goal -= 1
adj_list = [[] for _ in range(N)]
for i in range(M):
  u, v, yen, sunuke = map(int, input().split())
  u -= 1
  v -= 1
  adj_list[u].append([u, v, yen, sunuke])
  adj_list[v].append([v, u, yen, sunuke])

def dijkstra(start, changed):
  res = [ -1 for _ in range(N) ]
  q = [[0, start]]
  visited = {}

  while len(q)>0:
    money, city = heappop(q)
    if res[city]>=0:
      continue
    res[city] = money

    for from_city, to_city, yen, sunuke  in adj_list[city]:
      if res[to_city]<0:
        cost = sunuke if changed else yen
        heappush(q, [money+[yen, sunuke][changed], to_city])
        

  return res


min_yen_path = dijkstra(Start, 0)
min_sunuke_path = dijkstra(Goal, 1)

res = []
max_sunuke = 0
for i in reversed(range(N)):
  s = 10**15-min_yen_path[i]-min_sunuke_path[i]
  max_sunuke = max([s, max_sunuke]) 
  res.append(max_sunuke)
  
for i in reversed(res):
  print(i)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

N, M, Start, Goal = map(int, input().split())
Start -= 1
Goal -= 1
adj_list = [[] for _ in range(N)]
for i in range(M):
  u, v, yen, sunuke = map(int, input().split())
  u -= 1
  v -= 1
  adj_list[u].append([u, v, yen, sunuke])
  adj_list[v].append([v, u, yen, sunuke])

def dijkstra(start, changed):
  res = {}
  q = [[0, start]]
  visited = {}

  while len(q)>0:
    money, city = heappop(q)
    if city in res:
      continue
    res[city] = money

    for from_city, to_city, yen, sunuke  in adj_list[city]:
      if changed:
        heappush(q, [money+sunuke, to_city])
      else:
        heappush(q, [money+yen, to_city])
        

  return res


min_yen_path = dijkstra(Start, False)
min_sunuke_path = dijkstra(Goal, True)

res = []
max_sunuke = 0
for i in reversed(range(N)):
  s = 10**15-min_yen_path[i]-min_sunuke_path[i]
  max_sunuke = max([s, max_sunuke]) 
  res.append(max_sunuke)
  
for i in reversed(res):
  print(i)


Fixed submission:
from heapq import heappush, heappop

N, M, Start, Goal = map(int, input().split())
Start -= 1
Goal -= 1
adj_list = [[] for _ in range(N)]
for i in range(M):
  u, v, yen, sunuke = map(int, input().split())
  u -= 1
  v -= 1
  adj_list[u].append([u, v, yen, sunuke])
  adj_list[v].append([v, u, yen, sunuke])

def dijkstra(start, changed):
  res = [ -1 for _ in range(N) ]
  q = [[0, start]]
  visited = {}

  while len(q)>0:
    money, city = heappop(q)
    if res[city]>=0:
      continue
    res[city] = money

    for from_city, to_city, yen, sunuke  in adj_list[city]:
      if res[to_city]<0:
        cost = sunuke if changed else yen
        heappush(q, [money+[yen, sunuke][changed], to_city])
        

  return res


min_yen_path = dijkstra(Start, 0)
min_sunuke_path = dijkstra(Goal, 1)

res = []
max_sunuke = 0
for i in reversed(range(N)):
  s = 10**15-min_yen_path[i]-min_sunuke_path[i]
  max_sunuke = max([s, max_sunuke]) 
  res.append(max_sunuke)
  
for i in reversed(res):
  print(i)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappush, heappop

class Rail:
  def __init__(self, f, t, y, s, c=0):
    self.from_city = f
    self.to_city = t
    self.yen = y
    self.sunuke = s
    self.cost = c

  def __lt__(self, other):
    return self.cost < other.cost

  def __str__(self):
    return str(self.cost)


N, M, Start, Goal = map(int, input().split())
Start -= 1
Goal -= 1
adj_list = [[] for _ in range(N)]
for i in range(M):
  u, v, yen, sunuke = map(int, input().split())
  u -= 1
  v -= 1
  adj_list[u].append(Rail(u, v, yen, sunuke))
  adj_list[v].append(Rail(v, u, yen, sunuke))

def dijkstra(start, changed):
  res = {}
  r = Rail(start, start, 0, 0)
  q = [r]
  heapify(q)
  visited = {}

  while len(q)>0:
    r = heappop(q)
    now_city = r.to_city
    if visited.get(now_city, False):
      continue
    visited[now_city] = True
    res[now_city] = r.cost

    #print([now_city+1, r.cost])

    for rr in adj_list[now_city]:
      if changed:
        rr.cost = r.cost + rr.sunuke
      else:
        rr.cost = r.cost + rr.yen
        
      heappush(q, rr)

  return res


min_yen_path = dijkstra(Start, False)
min_sunuke_path = dijkstra(Goal, True)

res = []
max_sunuke = 0
for i in reversed(range(N)):
  s = 10**15-min_yen_path[i]-min_sunuke_path[i]
  max_sunuke = max([s, max_sunuke]) 
  res.append(max_sunuke)
  
for i in reversed(res):
  print(i)


Fixed submission:
from heapq import heappush, heappop

N, M, Start, Goal = map(int, input().split())
Start -= 1
Goal -= 1
adj_list = [[] for _ in range(N)]
for i in range(M):
  u, v, yen, sunuke = map(int, input().split())
  u -= 1
  v -= 1
  adj_list[u].append([u, v, yen, sunuke])
  adj_list[v].append([v, u, yen, sunuke])

def dijkstra(start, changed):
  res = [ -1 for _ in range(N) ]
  q = [[0, start]]
  visited = {}

  while len(q)>0:
    money, city = heappop(q)
    if res[city]>=0:
      continue
    res[city] = money

    for from_city, to_city, yen, sunuke  in adj_list[city]:
      if res[to_city]<0:
        cost = sunuke if changed else yen
        heappush(q, [money+[yen, sunuke][changed], to_city])
        

  return res


min_yen_path = dijkstra(Start, 0)
min_sunuke_path = dijkstra(Goal, 1)

res = []
max_sunuke = 0
for i in reversed(range(N)):
  s = 10**15-min_yen_path[i]-min_sunuke_path[i]
  max_sunuke = max([s, max_sunuke]) 
  res.append(max_sunuke)
  
for i in reversed(res):
  print(i)