TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
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())

n,m=map(int, input().split())
uf=UnionFind(n)
for _ in range(m):
    a,b=map(int, input().split())
    uf.union(a-1, b-1)
cnt=0


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())

n,m=map(int, input().split())
uf=UnionFind(n)
for _ in range(m):
    a,b=map(int, input().split())
    uf.union(a-1, b-1)
cnt=0
for i in range(n):
    cnt=max(cnt, uf.size(i))
print(cnt)

Verdicts: Wrong Answer

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
N,M = map(int,input().split())
f = []
for i in range(M):
    A,B = map(int,input().split())
    a = {A,B}
    for i in f:
        if i & a != set():
            a = i | a
            f.remove(i)
#            print(f,a,i)
    f.append(a)

#print(f)
print(len(max(f)))

N,M = map(int,input().split())
f = [[] for i in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    f[A-1].append(B-1)
    f[B-1].append(A-1)
from collections import deque
d = deque()
x = [-1]*N
for i in range(N):
    if x[i] == -1:
        x[i] = i
        d.append(f[i])
    while len(d) > 0:
        z = d.popleft()
        for j in z:
            if x[j] == -1:
                x[j] = i
                d.append(f[j])
import collections
ans = collections.Counter(x)
print(ans.most_common()[0][1])

Verdicts: Runtime Error

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
from collections import Counter

class UnionFind:
    def __init__(self,num:int):
        self.r = [-1 for i in range(num)]
    def root(self,x:int):
        if(self.r[x] < 0):
            return x
        self.r[x] = self.root(self.r[x])
        return self.r[x]
    def unite(self,x:int,y:int):
        rx = self.root(x)
        ry = self.root(y)
        if(rx == ry):
            return False
        if(self.r[rx] > self.r[ry]):
            rx,ry = ry,rx
        self.r[rx] += self.r[ry]
        self.r[ry] = rx
        return True
    def size(self,x:int):
        return -self.r[self.root(x)]

N,M = map(int,input().split())
group = UnionFind(N)
for i in range(M):
    A,B = map(int,input().split())
    group.unite(A-1,B-1)
ans = 0
for i in range(N):
    ans = max(ans,group.size(i))
print(group.r)
print(ans)


from collections import Counter

class UnionFind:
    def __init__(self,num:int):
        self.r = [-1 for i in range(num)]
    def root(self,x:int):
        if(self.r[x] < 0):
            return x
        self.r[x] = self.root(self.r[x])
        return self.r[x]
    def unite(self,x:int,y:int):
        rx = self.root(x)
        ry = self.root(y)
        if(rx == ry):
            return False
        if(self.r[rx] > self.r[ry]):
            rx,ry = ry,rx
        self.r[rx] += self.r[ry]
        self.r[ry] = rx
        return True
    def size(self,x:int):
        return -self.r[self.root(x)]

N,M = map(int,input().split())
group = UnionFind(N)
for i in range(M):
    A,B = map(int,input().split())
    group.unite(A-1,B-1)
ans = 0
for i in range(N):
    ans = max(ans,group.size(i))
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
from collections import defaultdict

N, M = map(int, input().split())
friend = defaultdict(set)
leader = []
for i in range(M):
    Ai, Bi = map(int, input().split())
    friend[Ai].add(Bi)
    friend[Bi].add(Ai)
print(friend)
already = {}
answer = 0
for i in range(1, N + 1):
    if i in already:
        continue
    if i not in friend:
        continue

    queue = []
    for f in friend[i]:
        already[f] = True
        queue.append(f)
    already[i] = True
    size = 0
    while len(queue) > size:
        item = queue[size]
        size += 1
        if item in friend:
            for f in friend[item]:
                if f not in already:
                    already[f] = True
                    queue.append(f)
    if size > answer:
        answer = size
print(answer + 1)

from collections import defaultdict

N, M = map(int, input().split())
friend = defaultdict(set)
leader = []
for i in range(M):
    Ai, Bi = map(int, input().split())
    friend[Ai].add(Bi)
    friend[Bi].add(Ai)
already = {}
answer = 0
for i in range(1, N + 1):
    if i in already:
        continue
    if i not in friend:
        continue

    queue = []
    for f in friend[i]:
        already[f] = True
        queue.append(f)
    already[i] = True
    size = 0
    while len(queue) > size:
        item = queue[size]
        size += 1
        if item in friend:
            for f in friend[item]:
                if f not in already:
                    already[f] = True
                    queue.append(f)
    if size > answer:
        answer = size
print(answer + 1)

Verdicts: Wrong Answer

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
from collections import defaultdict
from collections import deque


def main():
    N, M = map(int, input().split())
    A = [0] * M
    B = [0] * M

    for i in range(M):
        a, b = map(int, input().split())
        A[i] = a - 1
        B[i] = b - 1

    friends = defaultdict(set)

    for i in range(M):
        a, b = A[i], B[i]
        friends[a].add(b)
        friends[b].add(a)

    seen = [False] * N

    print(friends)

    def dfs(start):
        cnt = 0
        nodes = []

        todo = deque([start])
        while len(todo) > 0:
            v = todo.pop()
            cnt += 1
            nodes.append(v)

            for next_v in friends[v]:
                if seen[next_v]:
                    continue
                else:
                    todo.append(next_v)
                    seen[next_v] = True

        return cnt, nodes

    trees = []
    counts = []
    for v in range(N):
        if seen[v]:
            continue
        else:
            seen[v] = True
            c, nodes = dfs(v)
            counts.append(c)
            trees.append(nodes)

    # print(counts)
    # print(trees)
    print(max(counts))


if __name__ == '__main__':
    main()


from collections import defaultdict
from collections import deque


def main():
    N, M = map(int, input().split())
    A = [0] * M
    B = [0] * M

    for i in range(M):
        a, b = map(int, input().split())
        A[i] = a - 1
        B[i] = b - 1

    friends = defaultdict(set)

    for i in range(M):
        a, b = A[i], B[i]
        friends[a].add(b)
        friends[b].add(a)

    seen = [False] * N

    # print(friends)

    def dfs(start):
        cnt = 0
        nodes = []

        todo = deque([start])
        while len(todo) > 0:
            v = todo.pop()
            cnt += 1
            nodes.append(v)

            for next_v in friends[v]:
                if seen[next_v]:
                    continue
                else:
                    todo.append(next_v)
                    seen[next_v] = True

        return cnt, nodes

    trees = []
    counts = []
    for v in range(N):
        if seen[v]:
            continue
        else:
            seen[v] = True
            c, nodes = dfs(v)
            counts.append(c)
            trees.append(nodes)

    # print(counts)
    # print(trees)
    print(max(counts))


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
from collections import Counter

class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * n
        
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
            
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            

N, M = map(int, input().split())
UF = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    big = max(a, b)
    small = min(a, b)
    
    if UF.par[big] == big:
        UF.par[big] = small
    else:
        UF.union(big, small)
        
for i in range(N):
    _ = UF.find(i)

print(UF.par)

c = Counter(UF.par)
print(max(c.values()))

from collections import Counter

class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
                
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.union(a, b)

for i in range(n):
    uf.find(i)

c = Counter(uf.par)
print(max(c.values()))

Verdicts: Runtime Error

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
N,M = map(int,input().split())
lsa = [{i} for i in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    lsa[a] = lsa[a] | lsa[b]
    lsa[b] = lsa[a] | lsa[b]
ans = 0
for i in range(N+1):
    ans = max(ans,len(lsa[i]))
print(lsa)
print(ans)

from collections import deque

n, m = map(int, input().split())

graph = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

lsloop = []
used = [False for i in range(n+1)]

for j in range(1,n+1):
    if used[j]:
        continue        
    ii = 1
    d = deque()
    d.append(j)
    used[j] = True
    while d:
        v = d.popleft()
        for i in graph[v]:
            if used[i]:
                continue
            ii += 1
            d.append(i)
            used[i] = True
    lsloop.append(ii)
print(max(lsloop))

Verdicts: Wrong Answer

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
from collections import Counter

def main(N, M, C):
    lst = [n for n in range(N)]

    def get_root(x):
        if lst[x] == x:
            return x
        else:
            lst[x] = get_root(lst[x])
            return lst[x]

    def is_same(x, y):
        return get_root(x) == get_root(y)

    def unite(x, y):
        lst[x] = get_root(y)

    get_index = lambda x, y:(x-1, y-1)

    for c in C:
        indexes = get_index(*c)
        if not is_same(*indexes):
            unite(*indexes)
    print(max(Counter(lst).values()))


if __name__ == '__main__':
    N, M = list(map(int, input().split()))
    C = set()
    for _ in range(M):
        C.add(tuple(map(int, input().split())))
    main(N, M, C)

from collections import Counter



import sys
sys.setrecursionlimit(10 ** 9)

lst = [n for n in range(N)] 

def get_root(x):    
    if lst[x] == x: 
        return x
    else:   
        lst[x] = get_root(lst[x])   
        return lst[x]
        

def unite(x, y):    
    root_x = get_root(x)
    root_y = get_root(y)
    if root_x != root_y:    
        lst[root_x] = root_y

def main(N, M, C):
    {unite(*c) for c in C}  
    print(max(Counter(map(get_root, lst)).values()))    


if __name__ == '__main__':
    N, M = list(map(int, input().split()))
    C = set()
    for _ in range(M):
        C.add(tuple(map(lambda x:int(x)-1, input().split())))   
    main(N, M, C)


from collections import Counter



import sys
sys.setrecursionlimit(10 ** 9)

def main(N, M, C):
    lst = [n for n in range(N)] 

    def get_root(x):    
        if lst[x] == x: 
            return x
        else:   
            lst[x] = get_root(lst[x])   
            return lst[x]
            

    def unite(x, y):    
        root_x = get_root(x)
        root_y = get_root(y)
        if root_x != root_y:    
            lst[root_x] = root_y
            
    {unite(*c) for c in C}  
    print(max(Counter(map(get_root, lst)).values()))    


if __name__ == '__main__':
    N, M = list(map(int, input().split()))
    C = set()
    for _ in range(M):
        C.add(tuple(map(lambda x:int(x)-1, input().split())))   
    main(N, M, C)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
from numba import njit


class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]

@njit
def main():
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for i in range(m):
        a, b = map(int, input().split())
        uf.unite(a, b)
        
    ans = 0
    
    for i in range(1, n+1):
        ans = max(ans, uf.size(i))
        
    print(ans)
        


main()


class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]


def main():
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for i in range(m):
        a, b = map(int, input().split())
        uf.unite(a, b)
        
    ans = 0
    
    for i in range(1, n+1):
        ans = max(ans, uf.size(i))
    
    print(ans)
        

if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
class UnionFind:
    def __init__(self, length):
        self.r = [-1] * length

    def root(self, x):
        if (self.r[x]) < 0:
            return x

        return self.r[x] - self.root(self.r[x])

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False
        r = self.r

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

        r[x] += r[y]
        r[y] = x

        return True

    def size(self, x):
        return -self.r[self.root(x)]


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


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

max_ = -1
for i in range(N):
    max_ = max(relateions.size(i), max_)

print(max_)


class UnionFind:
    def __init__(self, length):
        self.r = [-1] * length

    def root(self, x):
        rx = self.r[x]
        if (rx) < 0:
            return x

        return self.root(rx)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False
        r = self.r

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

        r[x] += r[y]
        r[y] = x

        return True

    def size(self, x):
        return -self.r[self.root(x)]

    def debug(self):
        print(self.r)


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


relations = UnionFind(N)
for _ in range(M):
    A, B = map(int, input().split())
    relations.unite(A-1, B-1)

max_ = -1
for i in range(N):
    max_ = max(relations.size(i), max_)

print(max_)


Verdicts: Runtime Error

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
(n,m),*e=[[*map(int,i.split())]for i in open(0)]
d=[[]for i in range(n+1)]
dd=[[]for i in range(n+1)]
for i,j in e:
    d[i]+=[j]
    d[j]+=[i]
for i in range(n+1):
    for j in set(d[i]):
        dd[i]+=d[j]
print(max(len(set(dd[i]))for i in range(n+1)))

def find(x):
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def unite(x,y):
    x=find(x)
    y=find(y)
    if x == y:
        return 0
    if x<y:x,y=y,x    
    par[x]=y
n,m=map(int,input().split())
par=[i for i in range(n+1)]
for _ in range(m):
    i,j=map(int,input().split())
    unite(i,j)
ans=[0]*(n+1)
for i in range(n+1):
    find(i)
for i in par:
    ans[i]+=1
print(max(ans))

Verdicts: Wrong Answer

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
N,M=map(int,input().split())

P=[[0,0,0]]
for i in range(1,N+1):
    P.append([i,i,1])

R=[]
for i in range(M):
    a,b=map(int,input().split())
    c=max(a,b)
    a=min(a,b)
    b=c
    R.append((a,b))

R=sorted(list(set(R)))

for i in range(len(R)):
    
    x=0
    
    y=0
    
    cnt=0
    a=R[i][0]
    b=R[i][1]
    
    u=P[P[a][1]][1]
    v=P[P[b][1]][1]
    
    P[a][1]=u
    P[b][1]=v
    if P[a][1]==P[b][1]:
        continue
    else:
        x=min(P[a][1],P[b][1])
        y=max(P[a][1],P[b][1])
    
    
    if u!=x:
        P[u][1]=x
    if v!=x:
        P[v][1]=x

    cnt=P[y][2]
    P[a][1]=x
    P[b][1]=x
    P[x][2]+=cnt


ans=0
for i in range(1,N+1):
    x=P[i][1]
    P[i][2]=P[x][2]

for i in range(1,N+1):
    ans=max(ans,P[i][2])

print(R)
print(P)
print(ans)

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

def same(x,y):
    return find(x)==find(y)

def union(x,y):
    root_x=find(x)
    root_y=find(y)
    if root_x==root_y:
        return
    if parent[root_x]>parent[root_y]:
        root_x,root_y=root_y,root_x
    parent[root_x]+=parent[root_y]
    parent[root_y]=root_x

def members(n,x):
    root=find(x)
    return [i for i in range(n) if find(i)==root]

def get_size(x):
    return -parent[find(x)]

def get_root():
    return [i for i, root in enumerate(parent) if root<0]

N,M=map(int,input().split())
parent=[-1 for i in range(N)]
for i 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,get_size(i))
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
# Union find

# https://www.youtube.com/watch?time_continue=916&v=zxor0DdwoXA&feature=emb_logo
# https://www.slideshare.net/chokudai/union-find-49066733

import sys
sys.setrecursionlimit(10 ** 9)

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

root = [-1]*n

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

def unite(x, y):
    gx = find(x)
    gy = find(y)
    
    if gx == gy:
        return
      
    if root[gx] > root[gy]:
        gx, gy = gy, gx
        
    root[gx] += root[gy]
    root[gy] = gx
    print(root)

def size(x):
    x = find(x)
    return -root[x]

for a, b in AB:
    a -= 1
    b -= 1
    unite(a, b)

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

import sys
sys.setrecursionlimit(10**9)

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

root = [-1] * n

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

def unity(x, y):
    gx = find(x)
    gy = find(y)

    if gx == gy:
        return

    if root[gx] > root[gy]:
        gx, gy = gy, gx

    root[gx] += root[gy]
    root[gy] = gx

for a, b in AB:
    a -= 1
    b -= 1
    unity(a, b)

print(-min(root))

Verdicts: Runtime Error

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
n,m = (int(x) for x in input().split())
friendlist = [0]*n
classes = 1
for i in range(m):
    a,b = (int(x)-1 for x in input().split())
    if friendlist[a]!=0:
        friendlist[b] = friendlist[a]
    elif friendlist[b]!=0:
        friendlist[a] = friendlist[b]
    else:
        friendlist[a] = classes
        friendlist[b] = classes
        classes += 1

count = [0]*classes
for i in range(n):
    count[friendlist[i]] += 1

print(count)
print(max(count[1:]))


import os

n,m = (int(x) for x in input().split())

#Union Find


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

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

    if x == y:
        return False
    else:
        
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True


def same(x,y):
    return find(x) == find(y)


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



par = [-1]*n

for i in range(m):
    a,b = (int(x)-1 for x in input().split())
    unite(a,b)

ans = 0
for i in range(0,n):
    ans = max([ans,size(i)])

print(ans)


Verdicts: Runtime Error

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
class UnionFind():
    def __init__(self, n):
        self.par = [-1]*n

    def root(self, x):
        if self.par[x] < 0:
            return x
        return self.root(self.par[x])

    def unite(self, x, y):
        if x > y:
            x, y = y, x
        rx = self.root(x)
        ry = self.root(y)
        if rx != ry:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx

    def size(self, x):
        return -self.par[self.root(x)]

    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry

    def return_par(self):
        return self.par

n, m = map(int, input().split())
uf = UnionFind(n)
for i in m:
    a, b = map(int, input().split())
    uf.unite(a-1, b-1)

ans = 0
for i in range(n):
    ans = max(ans, uf.size(i))
print(ans)


import sys
sys.setrecursionlimit(10**8)

class UnionFind():
    def __init__(self, n):
        self.par = [-1]*n

    def find(self, x):
        if self.par[x] < 0:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def union(self, x, y):
        if x > y:
            x, y = y, x
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx

    def size(self, x):
        return -self.par[self.find(x)]

    def same(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        return rx == ry

    def return_par(self):
        return self.par

n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)

ans = 0
for i in range(n):
    ans = max(ans, uf.size(i))
print(ans)


Verdicts: Runtime Error

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
N,M=map(int,input().split())
par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]
def find(x):
    if x!=par[x]:
        par[x]=find(par[x])
    return par[x]
def union(x,y):
    if find(x)!=find(y):
        par[y] = par[x]
        size[x] += size[y]
res=N
for i in range(M):
    s,e=map(int,input().split())
    union(s,e)
c=0
for i in range(len(par)):
    if par[i]==i and size[i]!=1:

        c+=size[i]
print((c-1)//2+(c-1)%2)

N,M=map(int,input().split())
par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]
def find(x):
    if x!=par[x]:
        par[x]=find(par[x])
    return par[x]
def union(x,y):
    if find(x)!=find(y):
        par[y] = par[x]
        size[x] += size[y]
res=N
for i in range(M):
    s,e=map(int,input().split())
    union(s,e)
c=0
for i in range(len(par)):
    if par[i]==i and size[i]!=1:

        c+=size[i]
print(c-1)

N,M=map(int,input().split())
par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]
def find(x):
    if x!=par[x]:
        par[x]=find(par[x])
    return par[x]
def union(x,y):
    if find(x)!=find(y):
        x, y = par[x], par[y]
        par[y] = par[x]
        size[x] += size[y]
res=N
for i in range(M):
    s,e=map(int,input().split())
    union(s,e)
print(max(size))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
class UnionFind:
  def __init__(self, n):
    self.parent = [-1] * n
    self.rank = [-1] * n
    self.count = [-1] * n

  def get_root(self, i):
    while self.parent[i] != -1:
      i = self.parent[i]
    return i

  def is_same_tree(self, i, j):
    return self.get_root(i) == self.get_root(j)

  def merge(self, i, j):
    i = self.get_root(i)
    j = self.get_root(j)
    if i == j:
      return

    if self.rank[i] > self.rank[j]:
      self.parent[j] = i
      self.rank[i] = max(self.rank[i], self.rank[j] + 1)
      self.count[i] += self.count[j]
    else:
      self.parent[i] = j
      self.rank[j] = max(self.rank[j], self.rank[i] + 1)
      self.count[j] += self.count[i]


n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
  a, b = [int(i) - 1 for i in input().split()]
  uf.merge(a, b)
print(max(uf.count))


class UnionFind:
  def __init__(self, n):
    self.parent = [-1] * n
    self.rank = [1] * n
    self.count = [1] * n

  def get_root(self, i):
    while self.parent[i] != -1:
      i = self.parent[i]
    return i

  def is_same_tree(self, i, j):
    return self.get_root(i) == self.get_root(j)

  def merge(self, i, j):
    i = self.get_root(i)
    j = self.get_root(j)
    if i == j:
      return

    if self.rank[i] > self.rank[j]:
      self.parent[j] = i
      self.rank[i] = max(self.rank[i], self.rank[j] + 1)
      self.count[i] += self.count[j]
    else:
      self.parent[i] = j
      self.rank[j] = max(self.rank[j], self.rank[i] + 1)
      self.count[j] += self.count[i]


n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
  a, b = [int(i) - 1 for i in input().split()]
  uf.merge(a, b)
print(max(uf.count))


Verdicts: Wrong Answer

Accepted
Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
import numpy as np
N, M = map(int, input().split())
A = np.zeros((M,2), dtype=int)

for i in range(M):
    Ai = input().split()
    A[i,0] = int(Ai[0])
    A[i,1] = int(Ai[1])

Asort = np.sort(A, axis=0)

Grp_lst = np.arange(1, N+1)
for i in range(M):
    Grp_lst[Asort[i,1] - 1] = Grp_lst[Asort[i,0] - 1]

count = np.zeros(N,dtype=int)

for i in range(N):
    count[Grp_lst[i]-1] += 1

print(max(count))




from sys import setrecursionlimit, stdin
 
def find(parent, i):
    #print("f:" + str(i))
    #print(parent)
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t
 
def unite(parent, i, j):
    i = find(parent, i)
    #print("i:" + str(i) )
    j = find(parent, j)
    
    if i == j:
        return
    parent[j] += parent[i]
    parent[i] = j
    #print(parent)
 
readline = stdin.readline
setrecursionlimit(10 ** 6)

def resolve(): 
    N, M = map(int, readline().split())
    parent = [-1] * N
    for _ in range(M):
        A, B = map(lambda x: int(x) - 1, readline().split())
        unite(parent, A, B)
    print(-min(parent))

resolve()

Verdicts: Wrong Answer

Accepted
Problem: We have N integers. The i-th number is A_i.  \\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.  \\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.  Determine if \\{A_i\\} is pairwise coprime, setwise coprime, or neither.  Here, GCD(\ldots) denotes greatest common divisor.

Submission attempts (in order):
from subprocess import*
call(('pypy3','-c',))

import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict 
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  
  
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright






n=int(input())

A=list(map(int,input().split()))
from math import sqrt
def eratosu(n):
  if not isinstance(n,int):
    raise TypeError("nがint型になってねえぞ")
  if n<2:
    raise ValueError('nが2よりちっちぇえぞ')
  prime = []
  limit = sqrt(n)
  data = [i+1 for i in range(1, n)]  #2,3,4,...,n
  while True:
    p = data[0]
    if limit <= p:
        return prime + data
    prime.append(p)
    data = [e  for e in data if e % p != 0]
PRIME=eratosu(10**6+10)
@lru_cache(maxsize=10**10)
def bunkai(n):
    if n==1:return []
    ans=[]
    temp=n
    
    
    primelist= PRIME
    for i in primelist:
        if i>sqrt(n):break
        if temp % i ==0:
            ji=0
            while temp%i==0:
                ji+=1
                temp//=i
            ans.append(i)
    if ans==[]:return([n])  
    if temp!=1:
        ans.append(temp)  
    return ans

flag=1
seen={i:0 for i in PRIME}

for i in A:
    for l in bunkai(i):
        now=l
        if now==1:continue
        if seen[now]!=0:
            flag=0
        seen[now]+=1
if flag:
    print("pairwise coprime")
elif max(seen.values())!=n:
    print("setwise coprime")
else:
    print("not coprime")




import numpy as np
n=int(input())
A=list(map(int,input().split()))
cnt=[0]*(10**6+10)
for i in A:
    cnt[i]+=1


if np.gcd.reduce(A) !=1:
    print("not coprime");exit()
elif np.all([sum(cnt[i::i])<=1 for i in range(2,10**6+1)]):
    print("pairwise coprime")
else:
    print("setwise coprime")


Verdicts: Time Limit Exceeded

Time Limit Exceeded

Accepted
Problem: We have N integers. The i-th number is A_i.  \\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.  \\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.  Determine if \\{A_i\\} is pairwise coprime, setwise coprime, or neither.  Here, GCD(\ldots) denotes greatest common divisor.

Submission attempts (in order):
import numpy as np
N=int(input())
A=list(map(int,input().split()))
# cnt=[0]*(10**6+1)
cnt=np.zeros(10**6+1, dtype='int')
for a in A:cnt[a]+=1
 
if np.gcd.reduce(A)!=1:
  print("not coprime")
elif np.all([sum(cnt[i::i])<=1 for i in range(2,10**6+1)]):
  print("pairwise coprime")
else:
  print("setwise coprime")

import numpy as np
n = int(input())
aa = np.array(input().split(), dtype='int')
ma = np.max(aa)

cnt = [0] * (ma+1)

for a in aa:
    cnt[a] += 1

if np.gcd.reduce(aa) != 1:
    print('not coprime')
elif np.all([sum(cnt[i::i]) <= 1 for i in range(2, ma)]):
    print('pairwise coprime')
else:
    print('setwise coprime')

Verdicts: Time Limit Exceeded

Accepted
Problem: We have N integers. The i-th number is A_i.  \\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.  \\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.  Determine if \\{A_i\\} is pairwise coprime, setwise coprime, or neither.  Here, GCD(\ldots) denotes greatest common divisor.

Submission attempts (in order):
M=10**6+1
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
n,*l=map(int,open(0).read().split())
from math import *
g=l[0]
for x in l: g=gcd(g,x)
if g>1: f(2)
C=[0]*M
for x in l: C[x]=1
for i in range(2,M):
  if sum(C[j] for j in range(i,M,i))>1: f(1)
f(0)

M=10**6+1
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
n=int(input())
l=[*map(int,input().split())]
g=0
from math import *
for x in l:
  g=gcd(g,x)
if g>1: f(2)
def sieve(x):
  p=[]
  s=[0]*x
  for i in range(2,x):
    if s[i]<1:
      p+=[i]
      for j in range(i,x,i): s[j]=i
  return s
s=sieve(M)
C=[0]*M
for x in l:
  t=set()
  while x>1:
    t.add(s[x])
    x//=s[x]
  for y in t:
    if C[y]: f(1)
    C[y]=1
f(0)

Verdicts: Time Limit Exceeded

Accepted
Problem: We have N integers. The i-th number is A_i.  \\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.  \\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.  Determine if \\{A_i\\} is pairwise coprime, setwise coprime, or neither.  Here, GCD(\ldots) denotes greatest common divisor.

Submission attempts (in order):
from math import gcd

n = int(input())
a = list(map(int, input().split()))


ans = 0
cnt = [0] * (max(a) + 1)
for ai in a:
    ans = gcd(ans, ai)
    cnt[ai] += 1

if ans != 1:
    print('not coprime')
elif any(sum(cnt[i::i]) > 1 for i in range(max(a) + 1)):
    print('setwise coprime')
else:
    print('pairwise coprime')


from math import gcd

n = int(input())
a = list(map(int, input().split()))


ans = 0
cnt = [0] * (max(a) + 1)
for ai in a:
    ans = gcd(ans, ai)
    cnt[ai] += 1

if ans != 1:
    print('not coprime')
elif any(sum(cnt[i::i]) > 1 for i in range(2, max(a) + 1)):
    print('setwise coprime')
else:
    print('pairwise coprime')


Verdicts: Runtime Error

Accepted
Problem: We have N integers. The i-th number is A_i.  \\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.  \\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.  Determine if \\{A_i\\} is pairwise coprime, setwise coprime, or neither.  Here, GCD(\ldots) denotes greatest common divisor.

Submission attempts (in order):
from math import gcd
n=int(input())
l=list(map(int,input().split()))
mal=max(l)
e=[i for i in range(mal+1)]

x=2
while x*x <= mal:
    if x == e[x]:
        for m in range(x, len(e), n):
            if e[m] == m:
                e[m] = x
    x+=1
#print(e)    
s=set()
f=1
for i in l:
  st = set()
  while i > 1:
    st.add(e[i])
    i//=e[i]
  if not s.isdisjoint(st):
    f=1
    break
  s |= st

if f==0:
    print('pairwise coprime')
    exit()
p=l[0]
for i in range(1,n):
    p=gcd(p,l[i])
if p==1:
    print('setwise coprime')
else:
    print('not coprime')

from math import gcd
n=int(input())
l=list(map(int,input().split()))
mal=max(l)
e=[0 for i in range(mal+1)]

import numpy as np
def searchPrimeNum(N):
    ma = int(np.sqrt(N))
    searchList = [i for i in range(2,N+1)]
    primeNum = []
    while searchList[0] <= ma:
        primeNum.append(searchList[0])
        tmp = searchList[0]
        for i in searchList:
            if i%tmp==0:
                e[i]=tmp
        searchList = [i for i in searchList if i % tmp != 0]
        primeNum.extend(searchList)
    return primeNum
searchPrimeNum(mal)
#print(e)    
s=set()
f=1
for i in l:
  st = set()
  while i > 1:
    st.add(e[i])
    i//=e[i]
  if not s.isdisjoint(st):
    f=1
    break
  s |= st

if f==0:
    print('pairwise coprime')
    exit()
p=l[0]
for i in range(1,n):
    p=gcd(p,l[i])
if p==1:
    print('setwise coprime')
else:
    print('not coprime')

from math import gcd
n=int(input())
l=list(map(int,input().split()))
mal=max(l)
e=[i for i in range(mal+1)]

x=2
while x*x <= mal:
    if x == e[x]:
        for m in range(x, len(e), x):
            if e[m] == m:
                e[m] = x
    x+=1
#print(e)    
s=set()
f=0
for i in l:
  st = set()
  while i > 1:
    st.add(e[i])
    i//=e[i]
  if not s.isdisjoint(st):
    f=1
    break
  s |= st

if f==0:
    print('pairwise coprime')
    exit()
p=l[0]
for i in range(1,n):
    p=gcd(p,l[i])
if p==1:
    print('setwise coprime')
else:
    print('not coprime')


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have N integers. The i-th number is A_i.  \\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.  \\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.  Determine if \\{A_i\\} is pairwise coprime, setwise coprime, or neither.  Here, GCD(\ldots) denotes greatest common divisor.

Submission attempts (in order):
N = int(input())
M = 10**6 + 1

counts = [0 for _ in range(M)]
for a in map(int, input().split()):
  counts[a] += 1

max_count = 0
for i in range(2,M):
  count = 0
  for j in range(i,M,i):
    count += counts[j]
  max_count = max(max_count,count)

if max_count == N:
  answer = 'not coprime'
elif max_count >= 2:
  answer = 'setwise coprime'
else:
  answer = 'pairwise coprime'

print(answer)

N = int(input())
M = 10**6 + 1

counts = [0 for _ in range(M)]
for a in map(int, input().split()):
  counts[a] += 1

max_count = 0
for i in range(2,M):
  max_count = max(max_count,sum(counts[i::i]))

if max_count == N:
  answer = 'not coprime'
elif max_count >= 2:
  answer = 'setwise coprime'
else:
  answer = 'pairwise coprime'

print(answer)

Verdicts: Time Limit Exceeded

Accepted