Problem p02573 (python)

Fixed submission:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)


N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = Counter(find(i) for i in range(N))
print(count.most_common(1)[0][1])

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

sys.setrecursionlimit(10 ** 5)


N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = Counter(find(i) for i in range(N))
print(count.most_common(1)[0][1])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = [0] * N
for i in range(N - 1):
    find(i)
print(0)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = [0] * N
for i in range(N):
    if 0 <= find(i) < N:
        count[find(i)] += 1
    else:
        print(N)
        break
else:
    print(max(count))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = [0] * N
for i in range(N):
    count[find(i)] += 1
# res = 0
# for value in count.values():
#     res = max(res, value)
print(max(count))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = {}
for i in range(N):
    if (g := find(i)) in count:
        count[g] += 1
    else:
        count[g] = 1
# res = 0
# for value in count.values():
#     res = max(res, value)
print(N + 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = {}
for i in range(N):
    if (g := find(i)) in count:
        count[g] += 1
    else:
        count[g] = 1
res = 0
for value in count.values():
    res = max(res, value)
print(res)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict


N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = defaultdict(int)
for i in range(N):
    count[find(i)] += 1
print(max(count.values()))

Buggy submission (verdict: Runtime Error):
from collections import Counter


N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = Counter(find(i) for i in range(N))
for x in count.most_common():
    print(x[1])
    break

Buggy submission (verdict: Runtime Error):
from collections import defaultdict


N, M = map(int, input().split())
parent = defaultdict(lambda: -1)


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = defaultdict(int)
for i in range(N):
    count[find(i)] += 1
print(max(count.values()))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict


N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = defaultdict(int)
for i in range(N):
    count[find(i)] += 1
print(max(count.values()))