Problem p02726 (python)

Fixed submission:
N, X, Y = map(int, input().split())
ans = [0]*(N-1)
for i in range(1, N):
    for j in range(i+1, N+1):
        d = min(j-i, abs(X-i)+abs(j-Y)+1)
        ans[d-1] += 1

print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
import heapq
n,X,Y = map(int,input().split())

def dijkstra_heap(s,edge):
    d=[10**20]*n
    used = [True]*n
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d
E = []
for i in range(n-1):
    E.append([i,i+1,1])
E.append([X-1,Y-1,1])

edge = [[] for i in range(n)]
for i in range(w):
    for e in E:
        x,y,z = map(int,e)
        edge[x].append([z,y])
        edge[y].append([z,x])

for i in range(1,n):
    cnt = 0
    for j in range(n):
        tmp = dijkstra_heap(j,edge)
        for t in tmp[j:]:
            if t==i:
                cnt += 1
    print(cnt)

Buggy submission (verdict: Runtime Error):
import heapq
n,X,Y = map(int,input().split())

def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

E = []
for i in range(n-1):
    E.append([i,i+1,1])
E.append([X-1,Y-1,1])

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w):
    for e in E:
        x,y,z = map(int,e)
        edge[x].append([z,y])
        edge[y].append([z,x])

for i in range(1,n):
    cnt = 0
    for j in range(n):
        tmp = dijkstra_heap(j,edge)
        for t in tmp[j:]:
            if t==i:
                cnt += 1
    print(cnt)

Buggy submission (verdict: Runtime Error):
n,X,Y = map(int,input().split())

import heapq
def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

E = []
for i in range(n-1):
    E.append([i,i+1,1])
E.append([X-1,Y-1,1])

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w):
    for e in E:
        x,y,z = map(int,e)
        edge[x].append([z,y])
        edge[y].append([z,x])

for i in range(1,n):
    cnt = 0
    for j in range(n):
        tmp = dijkstra_heap(j,edge)
        for t in tmp[j:]:
            if t==i:
                cnt += 1
    print(cnt)

Buggy submission (verdict: Runtime Error):
n,X,Y = map(int,input().split())

import heapq
def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

E = []
for i in range(n-1):
    E.append([i,i+1,1])
E.append([X-1,Y-1,1])

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w):
    for e in E:
        x,y,z = map(int,e)
        edge[x].append([z,y])
        edge[y].append([z,x])

for i in range(1,n):
    cnt = 0
    for j in range(n):
        tmp = dijkstra_heap(j)
        for t in tmp[j:]:
            if t==i:
                cnt += 1
    print(cnt)