Problem p02573 (python)

Fixed submission:
N,M = tuple(map(int,input().split()))
# matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
friendlist = list(range(N))
# [所属先,[所属メンバー]]
gplist = [[i] for i in range(N)]

def getgroup(a):
    A = friendlist[a]
    if A == a:
        return a
    else:
        return getgroup(A)

def match(ab):
    A = getgroup(ab[0])
    B = getgroup(ab[1])
    if A==B:
        return
    elif len(gplist[A])<len(gplist[B]):
        gplist[B].extend(gplist[A])
        friendlist[A] = B
    else:
        gplist[A].extend(gplist[B])
        friendlist[B] = A

for i in range(M):
    # print(friendlist)
    # print(gplist)
    match(tuple(map(lambda x:int(x)-1,input().split())))

# print(friendlist)
# print(gplist)

print(max([len(item) for item in gplist]))

Buggy submission (verdict: Runtime Error):
N,M = tuple(map(int,input().split()))
# matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
friendlist = list(range(N))
# [所属先,[所属メンバー]]
gplist = [[i] for i in range(N)]

def getgroup(a):
    A = friendlist[a]
    if A == a:
        return a
    else:
        return getgroup(A)

def match(ab):
    A = getgroup(ab[0])
    B = getgroup(ab[1])
    if A==B:
        return
    else:
        gplist[A].extend(gplist[B])
        friendlist[B] = A

for i in range(M):
    # print(friendlist)
    # print(gplist)
    match(tuple(map(lambda x:int(x)-1,input().split())))

# print(friendlist)
# print(gplist)

print(max([len(item) for item in gplist]))

Buggy submission (verdict: Runtime Error):
N,M = tuple(map(int,input().split()))
matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
friendlist = [0 for i in range(N)]
gplist = [[-1]]
def match(ab):
    a,b=ab
    gpa=friendlist[a]
    gpb=friendlist[b]
    if bool(gpa) and gpa==gpb:
        return
    elif not bool(gpa) and not bool(gpb):
        friendlist[a]=len(gplist)
        friendlist[b]=len(gplist)
        gplist.append([a,b])
    elif bool(gpa) and not bool(gpb):
        friendlist[b] = gpa
        gplist[gpa].append(b)
    elif not bool(gpa) and bool(gpb):
        friendlist[a] = gpb
        gplist[gpb].append(a)
    else:
        for i in gplist[gpb]:
            friendlist[i] = gpa
        gplist[gpa].extend(gplist[gpb])
        gplist[gpb] = -1
# print(gplist)
for i in range(M):
    match(matchlist[i])
    # print(gplist)
    # print(friendlist)
print(max([len(item) for item in gplist]))

Buggy submission (verdict: Runtime Error):
N,M = tuple(map(int,input().split()))
matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
friendlist = [0 for i in range(N)]
gplist = [[]]
def match(ab):
    a,b=ab
    gpa=friendlist[a]
    gpb=friendlist[b]
    if bool(gpa) and gpa==gpb:
        return
    elif not bool(gpa) and not bool(gpb):
        friendlist[a]=len(gplist)
        friendlist[b]=len(gplist)
        gplist.append([a,b])
    elif bool(gpa) and not bool(gpb):
        friendlist[b] = gpa
        gplist[gpa].append(b)
    elif not bool(gpa) and bool(gpb):
        friendlist[a] = gpb
        gplist[gpb].append(a)
    else:
        for i in gplist[gpb]:
            friendlist[i] = gpa
        gplist[gpa].extend(gplist[gpb])
        gplist.remove(gplist[gpb])
# print(gplist)
for i in range(M):
    match(matchlist[i])
    # print(gplist)
    # print(friendlist)
print(max([len(item) for item in gplist]))