Problem p02573 (python)

Fixed submission:
import sys


def main():

    input = sys.stdin.readline

    N,M = map(int,input().split())

    AB = [list(map(int,input().split())) for _ in range(M)]

    UF = UnionFind(N)

    for i in range(M):
        A,B = AB[i]

        A = A - 1
        B = B - 1

        UF.union(A,B)


    ans = 1
    for i in range(N):
        ans = max(ans,UF.size(i))

    print(ans)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

parents = [-1] * 20000

def main():

    input = sys.stdin.readline

    N,M = map(int,input().split())

    AB = [list(map(int,input().split())) for _ in range(M)]

    for i in range(M):
        A,B = AB[i]

        A = A - 1
        B = B - 1

        union(A,B)


    ans = 1
    for i in range(20000):
        ans = max(ans,size(i))

    print(ans)

def find(x):
    if parents[x] < 0:
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]

def union(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return 0

    if parents[x] > parents[y]:
        x, y = y, x

    parents[x] += parents[y]
    parents[y] = x

def size(x):
    return -parents[find(x)]


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

parents = [-1] * 20000

def main():

    input = sys.stdin.readline

    N,M = map(int,input().split())


    for _ in range(M):
        A,B = map(int,input().split())

        A = A - 1
        B = B - 1

        union(A,B)

    ans = 1
    for i in range(20000):
        ans = max(ans,size(i))

    print(ans)

def find(x):
    if parents[x] < 0:
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]

def union(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return 0

    if parents[x] > parents[y]:
        x, y = y, x

    parents[x] += parents[y]
    parents[y] = x

def size(x):
    return -parents[find(x)]


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

parents = [-1] * 20000

def main():

    input = sys.stdin.readline

    N,M = map(int,input().split())


    for _ in range(M):
        A,B = map(int,input().split())

        A = A - 1
        B = B - 1

        union(A,B)

    ans = 1
    for i in range(20000):
        ans = max(ans,size(i))

    print(ans)

def find(x):
    if parents[x] < 0:
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]

def union(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return

    if parents[x] > parents[y]:
        x, y = y, x

    parents[x] += parents[y]
    parents[y] = x

def size(x):
    return -parents[find(x)]


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

parents = [-1] * 20000

def main():

    input = sys.stdin.readline

    N,M = map(int,input().split())


    for _ in range(M):
        A,B = map(int,input().split())

        A = A - 1
        B = B - 1

        union(A,B)

    ans = 1
    for i in range(N):
        ans = max(ans,size(i))

    print(ans)

def find(x):
    if parents[x] < 0:
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]

def union(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return

    if parents[x] > parents[y]:
        x, y = y, x

    parents[x] += parents[y]
    parents[y] = x

def size(x):
    return -parents[find(x)]


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

parents = [-1] * 20000

def main():

    input = sys.stdin.readline

    N,M = map(int,input().split())


    for _ in range(M):
        A,B = map(int,input().split())

        A = A - 1
        B = B - 1

        union(A,B)

    ans = 0
    for i in range(N):
        ans = max(ans,size(i))

    print(ans)

def find(x):
    if parents[x] < 0:
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]

def union(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return

    if parents[x] > parents[y]:
        x, y = y, x

    parents[x] += parents[y]
    parents[y] = x

def size(x):
    return -parents[find(x)]


if __name__ == "__main__":
    main()