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

n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1.append({})
root2 = []
for i in range(n):
    root2.append({})
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[u - 1][v] = a
    root1[v - 1][u] = a
    root2[u - 1][v] = b
    root2[v - 1][u] = b

def min_cost(root, start): # 経路の端点を１つ指定して任意の点への最小コストを計算
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        """
        if D[site - 1] > cost:
            D[site - 1] = cost
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                heapq.heappush(S, [cost + cost2, site2])
        """
        if D[site - 1] < cost:
            continue
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                D[site2 - 1] = cost + cost2
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s) # 円で両替地点まで移動する最小コスト
snuke = min_cost(root2, t) # 両替地点からスヌークで移動する最小コスト
cost = [jpy[i] + snuke[i] for i in range(n)] # 両替地点についてループ

for i in range(n):
    print(10 ** 15 - min(cost[i:]))


Fixed submission:
import heapq

n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1.append({})
root2 = []
for i in range(n):
    root2.append({})
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[u - 1][v] = a
    root1[v - 1][u] = a
    root2[u - 1][v] = b
    root2[v - 1][u] = b

def min_cost(root, start): # 経路の端点を１つ指定して任意の点への最小コストを計算
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] < cost:
            continue
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                D[site2 - 1] = cost + cost2
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s) # 円で両替地点まで移動する最小コスト
snuke = min_cost(root2, t) # 両替地点からスヌークで移動する最小コスト
cost = [jpy[i] + snuke[i] for i in range(n)] # 両替地点についてループ

minimum_cost = []
temp_min = cost[n - 1]
for i in reversed(range(n)):
    temp_min = min(temp_min, cost[i])
    minimum_cost.append(temp_min)

for i in reversed(range(n)):
    print(10 ** 15 - minimum_cost[i])

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

n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1.append({})
root2 = []
for i in range(n):
    root2.append({})
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[u - 1][v] = a
    root1[v - 1][u] = a
    root2[u - 1][v] = b
    root2[v - 1][u] = b

def min_cost(root, start):
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] > cost:
            D[site - 1] = cost
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s)
snuke = min_cost(root2, t)
cost = [jpy[i] + snuke[i] for i in range(n)]

for i in range(n):
    print(10 ** 15 - min(cost[i:]))

Fixed submission:
import heapq

n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1.append({})
root2 = []
for i in range(n):
    root2.append({})
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[u - 1][v] = a
    root1[v - 1][u] = a
    root2[u - 1][v] = b
    root2[v - 1][u] = b

def min_cost(root, start): # 経路の端点を１つ指定して任意の点への最小コストを計算
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] < cost:
            continue
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                D[site2 - 1] = cost + cost2
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s) # 円で両替地点まで移動する最小コスト
snuke = min_cost(root2, t) # 両替地点からスヌークで移動する最小コスト
cost = [jpy[i] + snuke[i] for i in range(n)] # 両替地点についてループ

minimum_cost = []
temp_min = cost[n - 1]
for i in reversed(range(n)):
    temp_min = min(temp_min, cost[i])
    minimum_cost.append(temp_min)

for i in reversed(range(n)):
    print(10 ** 15 - minimum_cost[i])

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

n, m, s, t = map(int, input().split())

root1 = {}
root2 = {}
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[(u, v)] = a
    root2[(u, v)] = b

def edge(root, x):
    return([(b, root[(a, b)]) for (a, b) in root if a == x] + [(a, root[(a, b)]) for (a, b) in root if b == x])

root1 = [edge(root1, i + 1) for i in range(n)]
root2 = [edge(root2, i + 1) for i in range(n)]

def min_cost(root, start):
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] > cost:
            D[site - 1] = cost
        for (site2, cost2) in root[site - 1]:
            if D[site2 - 1] > cost + cost2:
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s)
snuke = min_cost(root2, t)
cost = [jpy[i] + snuke[i] for i in range(n)]

for i in range(n):
    print(10 ** 15 - min(cost[i:]))

Fixed submission:
import heapq

n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1.append({})
root2 = []
for i in range(n):
    root2.append({})
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[u - 1][v] = a
    root1[v - 1][u] = a
    root2[u - 1][v] = b
    root2[v - 1][u] = b

def min_cost(root, start): # 経路の端点を１つ指定して任意の点への最小コストを計算
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] < cost:
            continue
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                D[site2 - 1] = cost + cost2
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s) # 円で両替地点まで移動する最小コスト
snuke = min_cost(root2, t) # 両替地点からスヌークで移動する最小コスト
cost = [jpy[i] + snuke[i] for i in range(n)] # 両替地点についてループ

minimum_cost = []
temp_min = cost[n - 1]
for i in reversed(range(n)):
    temp_min = min(temp_min, cost[i])
    minimum_cost.append(temp_min)

for i in reversed(range(n)):
    print(10 ** 15 - minimum_cost[i])

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

n, m, s, t = map(int, input().split())

root1 = {}
root2 = {}
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[(u, v)] = a
    root2[(u, v)] = b

def edge(G, x):
    return([(b, G[(a, b)]) for (a, b) in G if a == x] + [(a, G[(a, b)]) for (a, b) in G if b == x])

def min_cost(G, start):
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] > cost:
            D[site - 1] = cost
        for (site2, cost2) in edge(G, site):
            if D[site2 - 1] > cost + cost2:
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s)
snuke = min_cost(root2, t)
cost = [jpy[i] + snuke[i] for i in range(n)]

for i in range(n):
    print(10 ** 15 - min(cost[i:]))

Fixed submission:
import heapq

n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1.append({})
root2 = []
for i in range(n):
    root2.append({})
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[u - 1][v] = a
    root1[v - 1][u] = a
    root2[u - 1][v] = b
    root2[v - 1][u] = b

def min_cost(root, start): # 経路の端点を１つ指定して任意の点への最小コストを計算
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] < cost:
            continue
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                D[site2 - 1] = cost + cost2
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s) # 円で両替地点まで移動する最小コスト
snuke = min_cost(root2, t) # 両替地点からスヌークで移動する最小コスト
cost = [jpy[i] + snuke[i] for i in range(n)] # 両替地点についてループ

minimum_cost = []
temp_min = cost[n - 1]
for i in reversed(range(n)):
    temp_min = min(temp_min, cost[i])
    minimum_cost.append(temp_min)

for i in reversed(range(n)):
    print(10 ** 15 - minimum_cost[i])

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

n, m, s, t = map(int, input().split())

root1 = {}
root2 = {}
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[(u, v)] = a
    root2[(u, v)] = b

def edge(G, x):
    return([(b, G[(a, b)]) for (a, b) in G if a == x] + [(a, G[(a, b)]) for (a, b) in G if b == x])

def min_cost(G, start, end):
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] > cost:
            D[site - 1] = cost
        for (site2, cost2) in edge(G, site):
            if D[site2 - 1] > cost + cost2:
                heapq.heappush(S, [cost + cost2, site2])
    return D[end - 1]

cost = []
for i in range(n):
    cost.append(min_cost(root1, s, i + 1) + min_cost(root2, i + 1, t))

for i in range(n):
    print(10 ** 15 - min(cost[i:]))

Fixed submission:
import heapq

n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1.append({})
root2 = []
for i in range(n):
    root2.append({})
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[u - 1][v] = a
    root1[v - 1][u] = a
    root2[u - 1][v] = b
    root2[v - 1][u] = b

def min_cost(root, start): # 経路の端点を１つ指定して任意の点への最小コストを計算
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] < cost:
            continue
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                D[site2 - 1] = cost + cost2
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s) # 円で両替地点まで移動する最小コスト
snuke = min_cost(root2, t) # 両替地点からスヌークで移動する最小コスト
cost = [jpy[i] + snuke[i] for i in range(n)] # 両替地点についてループ

minimum_cost = []
temp_min = cost[n - 1]
for i in reversed(range(n)):
    temp_min = min(temp_min, cost[i])
    minimum_cost.append(temp_min)

for i in reversed(range(n)):
    print(10 ** 15 - minimum_cost[i])

Buggy python submission (verdict: Time Limit Exceeded):
n, m, s, t = map(int, input().split())

root1 = {}
root2 = {}
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[(u, v)] = a
    root2[(u, v)] = b

def edge(G, x):
    return([(b, G[(a, b)]) for (a, b) in G if a == x] + [(a, G[(a, b)]) for (a, b) in G if b == x])

def min_cost(G, start, end):
    S = {start: 0}
    D = {}
    while len(S) > 0:
        x = select_min(S)
        m = S[x]
        del S[x]
        D[x] = m
        for (y, w) in edge(G, x):
            if y in S:
                if S[y] > m + w:
                    S[y] = m + w
            elif y not in D:
                S[y] = m + w
    return D[end]

def select_min(S):
    m = -1
    for a in S:
        if m == -1 or m > S[a]:
            x = a
            m = S[a]
    return x

cost = []
for i in range(n):
    cost.append(min_cost(root1, s, i + 1) + min_cost(root2, i + 1, t))

for i in range(n):
    print(10 ** 15 - min(cost[i:]))

Fixed submission:
import heapq

n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1.append({})
root2 = []
for i in range(n):
    root2.append({})
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[u - 1][v] = a
    root1[v - 1][u] = a
    root2[u - 1][v] = b
    root2[v - 1][u] = b

def min_cost(root, start): # 経路の端点を１つ指定して任意の点への最小コストを計算
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] < cost:
            continue
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                D[site2 - 1] = cost + cost2
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s) # 円で両替地点まで移動する最小コスト
snuke = min_cost(root2, t) # 両替地点からスヌークで移動する最小コスト
cost = [jpy[i] + snuke[i] for i in range(n)] # 両替地点についてループ

minimum_cost = []
temp_min = cost[n - 1]
for i in reversed(range(n)):
    temp_min = min(temp_min, cost[i])
    minimum_cost.append(temp_min)

for i in reversed(range(n)):
    print(10 ** 15 - minimum_cost[i])

Buggy python submission (verdict: Time Limit Exceeded):
n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1_ = [0] * n
    root1.append(root1_)
root2 = []
for i in range(n):
    root2_ = [0] * n
    root2.append(root2_)
    
for i in range(m):
    root = list(map(int, input().split()))
    root1[root[0] - 1][root[1] - 1] = root[2]
    root1[root[1] - 1][root[0] - 1] = root[2]
    root2[root[0] - 1][root[1] - 1] = root[3]
    root2[root[1] - 1][root[0] - 1] = root[3]

def min_cost(start, end, root):
    confirmed = [[start, 0]]
    edge = [start]
    while len(confirmed) < n:
        candidate = []
        for i in range(len(edge)):
            for j in range(n):
                if root[edge[i] - 1][j] != 0:
                    for k in range(len(confirmed)):
                        if confirmed[k][0] == edge[i]:
                            candidate.append([j + 1, confirmed[k][1] + root[edge[i] - 1][j]])
                            break
        candidate.sort(key = lambda x: x[1])
        for i in range(len(candidate)):
            if candidate[i][0] in [confirmed[i][0] for i in range(len(confirmed))]:
                continue
            else:
                confirmed.append(candidate[i])
                break
        for i in range(len(confirmed)):
            edge.append(confirmed[i][0])
        exclude = []
        for i in range(len(edge)):
            flag = True
            for j in range(n):                
                if root[edge[i] - 1][j] != 0 and (j + 1) not in edge:
                    flag = False
                    break
            if flag == True:
                exclude.append(edge[i])
        edge = list(set(edge) - set(exclude))
    for i in range(len(confirmed)):
        if confirmed[i][0] == end:
            return confirmed[i][1]

cost = []
for i in range(n):
    cost1 = min_cost(s, i + 1, root1)
    cost2 = min_cost(i + 1, t, root2)
    cost.append(cost1 + cost2)
for i in range(n):
    new_cost = cost[i:]
    print(10 ** 15 - min(new_cost))

Fixed submission:
import heapq

n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1.append({})
root2 = []
for i in range(n):
    root2.append({})
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[u - 1][v] = a
    root1[v - 1][u] = a
    root2[u - 1][v] = b
    root2[v - 1][u] = b

def min_cost(root, start): # 経路の端点を１つ指定して任意の点への最小コストを計算
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] < cost:
            continue
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                D[site2 - 1] = cost + cost2
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s) # 円で両替地点まで移動する最小コスト
snuke = min_cost(root2, t) # 両替地点からスヌークで移動する最小コスト
cost = [jpy[i] + snuke[i] for i in range(n)] # 両替地点についてループ

minimum_cost = []
temp_min = cost[n - 1]
for i in reversed(range(n)):
    temp_min = min(temp_min, cost[i])
    minimum_cost.append(temp_min)

for i in reversed(range(n)):
    print(10 ** 15 - minimum_cost[i])

Buggy python submission (verdict: Time Limit Exceeded):
n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1_ = [0] * n
    root1.append(root1_)
root2 = []
for i in range(n):
    root2_ = [0] * n
    root2.append(root2_)
    
for i in range(m):
    root = list(map(int, input().split()))
    root1[root[0] - 1][root[1] - 1] = root[2]
    root1[root[1] - 1][root[0] - 1] = root[2]
    root2[root[0] - 1][root[1] - 1] = root[3]
    root2[root[1] - 1][root[0] - 1] = root[3]

def min_cost(start, end, root):
    confirmed = [[start, 0]]
    while len(confirmed) < n:
        candidate = []
        for i in range(len(confirmed)):
            for j in range(n):
                if root[confirmed[i][0] - 1][j] != 0:
                    candidate.append([j + 1, confirmed[i][1] + root[confirmed[i][0] - 1][j]])
        candidate.sort(key = lambda x: x[1])
        for i in range(len(candidate)):
            if candidate[i][0] in [confirmed[i][0] for i in range(len(confirmed))]:
                continue
            else:
                confirmed.append(candidate[i])
                break       
    for i in range(len(confirmed)):
        if confirmed[i][0] == end:
            return confirmed[i][1]

cost = []
for i in range(n):
    cost1 = min_cost(s, i + 1, root1)
    cost2 = min_cost(i + 1, t, root2)
    cost.append(cost1 + cost2)
for i in range(n):
    new_cost = cost[i:]
    print(10 ** 15 - min(new_cost))

Fixed submission:
import heapq

n, m, s, t = map(int, input().split())

root1 = []
for i in range(n):
    root1.append({})
root2 = []
for i in range(n):
    root2.append({})
   
for i in range(m):
    u, v, a, b = map(int, input().split())
    root1[u - 1][v] = a
    root1[v - 1][u] = a
    root2[u - 1][v] = b
    root2[v - 1][u] = b

def min_cost(root, start): # 経路の端点を１つ指定して任意の点への最小コストを計算
    S = [[0, start]]
    heapq.heapify(S)
    D = [float("inf")] * n
    D[start - 1] = 0
    while len(S) > 0:
        cost, site = heapq.heappop(S)
        if D[site - 1] < cost:
            continue
        for site2, cost2 in root[site - 1].items():
            if D[site2 - 1] > cost + cost2:
                D[site2 - 1] = cost + cost2
                heapq.heappush(S, [cost + cost2, site2])
    return D

jpy = min_cost(root1, s) # 円で両替地点まで移動する最小コスト
snuke = min_cost(root2, t) # 両替地点からスヌークで移動する最小コスト
cost = [jpy[i] + snuke[i] for i in range(n)] # 両替地点についてループ

minimum_cost = []
temp_min = cost[n - 1]
for i in reversed(range(n)):
    temp_min = min(temp_min, cost[i])
    minimum_cost.append(temp_min)

for i in reversed(range(n)):
    print(10 ** 15 - minimum_cost[i])