Problem p02726 (python)

Fixed submission:
N, X, Y = map(int, input().split())

X = X-1
Y = Y-1

kDict = {}

for kIndx in range(1, N+1):
    kDict[kIndx] = 0

for jIndx in range(N):
    for iIndx in range(jIndx):
        if (jIndx <= X) or (iIndx >= Y):
            kDict[jIndx - iIndx] += 1
        elif (iIndx <= X) and (jIndx >= Y):
            kDict[(jIndx - iIndx) - (Y - X - 1)] += 1
        elif (iIndx <= X) and ((jIndx > X) and (jIndx < Y)):
            if 2 * jIndx - (X + Y) - 1 > 0:
                kDict[(jIndx - iIndx) - (2 * jIndx - (X + Y) - 1)] += 1
            else:
                kDict[jIndx - iIndx] += 1
        elif ((iIndx > X) and (iIndx < Y)) and (jIndx >= Y):
            if (X + Y) - 2 * iIndx - 1 > 0:
                kDict[(jIndx - iIndx) - ((X + Y) - 2 * iIndx - 1)] += 1
            else:
                kDict[jIndx - iIndx] += 1
        else:
            if (2 * (jIndx - iIndx) - (Y - X) - 1) > 0:
                kDict[(jIndx - iIndx) - (2 * (jIndx - iIndx) - (Y - X) - 1)] += 1
            else:
                kDict[jIndx - iIndx] += 1

for kIndx in range(1, N):
    print(kDict[kIndx])

Buggy submission (verdict: Runtime Error):
def bfs(linkL, chckL, nextNL, breath):
    pasNL = []
    for item in nextNL:
        for lnkItem in linkL[item]:
            linkL[lnkItem].remove(item)
            if chckL[lnkItem] == -1:
                chckL[lnkItem] = breath+1
                pasNL.append(lnkItem)
        linkL[item] = []

    if len(pasNL) == 0:
        return chckL
    else:
        chckL = bfs(linkL, chckL, pasNL, breath+1)
        return chckL


import copy

N, X, Y = map(int, input().split())
mySum = [0] * (N-1)

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X-1: tmpList.append(Y-1)
    if indx == Y-1: tmpList.append(X-1)
    lList.append(tmpList)


for baseIndx in range(N):
    tmpLink = copy.deepcopy(lList)

    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(tmpLink, chckList, [baseIndx], 0)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Buggy submission (verdict: Runtime Error):
def bfs(linkL, chckL, nextNL, breath):
    pasNL = []
    for item in nextNL:
        for lnkItem in linkL[item]:
            linkL[lnkItem].remove(item)
            if chckL[lnkItem] == -1:
                chckL[lnkItem] = breath+1
                pasNL.append(lnkItem)
        linkL[item] = []

    if len(pasNL) == 0:
        return chckL
    else:
        chckL = bfs(linkL, chckL, pasNL, breath+1)
        return chckL


N, X, Y = map(int, input().split())
mySum = [0] * (N-1)

for baseIndx in range(N):

    lList = []

    for indx in range(N):
        tmpList = []
        if indx != 0:   tmpList.append(indx-1)
        if indx != N-1: tmpList.append(indx+1)
        if indx == X-1: tmpList.append(Y-1)
        if indx == Y-1: tmpList.append(X-1)
        lList.append(tmpList)

    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(lList, chckList, [baseIndx], 0)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Buggy submission (verdict: Runtime Error):
def bfs(linkL, chckL, nextNL, breath):
    pasNL = []
    for item in nextNL:
        # print(item, breath)
        chckL[item] = breath

    for item in nextNL:
        for lnkItem in linkL[item]:
            # linkL[lnkItem].remove(item)
            if (chckL[lnkItem] == -1) and (lnkItem not in pasNL):
                pasNL.append(lnkItem)
        # linkL[item] = []
    
    if len(pasNL) == 0:
        return chckL
    else:
        chckL = bfs(linkL, chckL, pasNL, breath+1)
        return chckL

N, X, Y = map(int, input().split())

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X-1: tmpList.append(Y-1)
    if indx == Y-1: tmpList.append(X-1)
    lList.append(tmpList)

mySum = [0] * (N-1)

for baseIndx in range(N):
    chckList = [-1] * N

    chckList = bfs(lList, chckList, [baseIndx], 0)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Buggy submission (verdict: Runtime Error):
def bfs(linkL, chckL, nextNL, breath):
    for item in nextNL:
        chckL[item] = breath
    
    NL = []
    for nextItem in nextNL:
        for chckItem in linkL[nextItem]:
            if chckL[chckItem] == -1:
                NL.append(chckItem)
                chckL[chckItem] = -2
    
    if len(NL) == 0:
        return chckL
    
    chckL = bfs(linkL, chckL, NL, breath+1)
    
    return chckL


N, X, Y = map(int, input().split())

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X-1:   tmpList.append(Y-1)
    if indx == Y-1:   tmpList.append(X-1)
    lList.append(tmpList)

mySum = [0] * (N-1)

for baseIndx in range(N):
    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(lList, chckList, lList[baseIndx], 1)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Buggy submission (verdict: Runtime Error):
def bfs(linkL, chckL, nextNL, breath):
    for item in nextNL:
        chckL[item] = breath
    
    NL = []
    for nextItem in nextNL:
        for chckItem in linkL[nextItem]:
            if chckL[chckItem] == -1:
                NL.append(chckItem)
    
    if len(NL) == 0:
        return chckL
    
    chckL = bfs(linkL, chckL, NL, breath+1)
    
    return chckL


N, X, Y = map(int, input().split())

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X-1:   tmpList.append(Y-1)
    if indx == Y-1:   tmpList.append(X-1)
    lList.append(tmpList)

mySum = [0] * (N-1)

for baseIndx in range(N):
    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(lList, chckList, lList[baseIndx], 1)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Buggy submission (verdict: Runtime Error):
def bfs(linkL, chckL, nextNL, breath):
    unsrchedNL = []
    for item in nextNL:
        chckL[item] = breath
        unsrchedNL.append(item)
    
    if len(unsrchedNL) == 0:
        return chckL
    
    NL = []
    for unsrchedItem in unsrchedNL:
        for chckItem in linkL[unsrchedItem]:
            if chckL[chckItem] == -1:
                NL.append(chckItem)
    
    chckL = bfs(linkL, chckL, NL, breath+1)
    
    return chckL


N, X, Y = map(int, input().split())

X -= 1
Y -= 1

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X:   tmpList.append(Y)
    if indx == Y:   tmpList.append(X)
    lList.append(tmpList)

mySum = [0] * (N-1)

for baseIndx in range(N):
    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(lList, chckList, lList[baseIndx], 1)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])

Buggy submission (verdict: Runtime Error):
def bfs(linkL, chckL, nextNL, breath):
    unsrchedNL = []
    for item in nextNL:
        if chckL[item] == -1:
            chckL[item] = breath
            unsrchedNL.append(item)
    
    if len(unsrchedNL) == 0:
        return chckL
    
    NL = []
    for unsrchedItem in unsrchedNL: NL += linkL[unsrchedItem]
    chckL = bfs(linkL, chckL, NL, breath+1)
    
    return chckL


N, X, Y = map(int, input().split())

X -= 1
Y -= 1

lList = []

for indx in range(N):
    tmpList = []
    if indx != 0:   tmpList.append(indx-1)
    if indx != N-1: tmpList.append(indx+1)
    if indx == X:   tmpList.append(Y)
    if indx == Y:   tmpList.append(X)
    lList.append(tmpList)

mySum = [0] * (N-1)

for baseIndx in range(N):
    chckList = [-1] * N

    chckList[baseIndx] = 0

    chckList = bfs(lList, chckList, lList[baseIndx], 1)
    chckList = chckList[baseIndx+1:N]

    for sumIndx in range(N-1):
        mySum[sumIndx] += chckList.count(sumIndx+1)

for printIndx in range(N-1):
    print(mySum[printIndx])