problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 262k
1.05M
| problem_description
stringlengths 48
1.55k
| codes
stringlengths 35
98.9k
| status
stringlengths 28
1.7k
| submission_ids
stringlengths 28
1.41k
| memories
stringlengths 13
808
| cpu_times
stringlengths 11
610
| code_sizes
stringlengths 7
505
|
---|---|---|---|---|---|---|---|---|---|---|
p02573 | u411923565 | 2,000 | 1,048,576 | 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? | ['\nimport sys\nsys.setrecursionlimit(10**6)\n\nN,M = map(int,input().split())\n\nlis = [[] for _ in range(N+1)]\nfor i in range(M):\n A,B = map(int,input().split())\n A,B = min(A,B),max(A,B)\n lis[A].append(B)\nprint(lis)\n \ncnt = 0\nseen = [False]*(N+1)\ndef dfs(v,graph):\n global cnt\n seen[v] = True\n for next_v in graph[v]:\n if seen[next_v] == True:\n continue\n if seen[next_v] == []:\n continue\n cnt += 1\n dfs(next_v,graph)\n return cnt\n\nma = 0\nfor j in range(N):\n cnt = 0\n if seen[j] == True:\n continue\n ma = max(ma,dfs(j,lis))\nprint(ma+1)', 'import sys\nsys.setrecursionlimit(10**6)\n\nN,M = map(int,input().split())\n\nlis = [[] for _ in range(N+1)]\nfor i in range(M):\n A,B = map(int,input().split())\n lis[A].append(B)\n lis[B].append(A)\n \ncnt = 0\nseen = [False]*(N+1)\ndef dfs(v,graph):\n global cnt\n seen[v] = True\n for next_v in graph[v]:\n if seen[next_v] == True:\n continue\n if seen[next_v] == []:\n continue\n cnt += 1\n dfs(next_v,graph)\n return cnt\n\nma = 0\nfor j in range(N):\n cnt = 0\n if seen[j] == True:\n continue\n ma = max(ma,dfs(j,lis))\nprint(ma+1)'] | ['Wrong Answer', 'Accepted'] | ['s992700051', 's381924763'] | [204184.0, 210608.0] | [801.0, 711.0] | [618, 599] |
p02573 | u414050834 | 2,000 | 1,048,576 | 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? | ['from collections import Counter\nn,m=map(int,input().split())\nl=[]\nfor i in range(m):\n s=[]\n a,b=map(int,input().split())\n s.append(a)\n s.append(b)\n l.append(s)\ndef get_unique_list(seq):\n seen = []\n return [x for x in seq if (x or reversed(x)) not in seen and not seen.append(x)]\nls=get_unique_list(l)\ncnt=Counter([x[0] for x in ls])\nprint(max(cnt.values)+1)', 'from collections import Counter\nn,m=map(int,input().split())\nl=[]\nfor i in range(m):\n s=[]\n a,b=map(int,input().split())\n s.append(a)\n s.append(b)\n l.append(s)\ndef get_unique_list(seq):\n seen = []\n return [x for x in seq if (x or reversed(x)) not in seen and not seen.append(x)]\nls=get_unique_list(l)\ncnt=Counter([x[0] for x in ls])\nprint(max(cnt.values())+1)\n', 'n,m=map(int,input().split())\nroot=[-1]*n\ndef r(x):\u3000\n if root[x]<0: \n return x \n else: \n root[x]=r(root[x]) \n return root[x] \ndef unite(x,y):\n x=r(x)\n y=r(y)\n if x==y: \n return\n root[x]+=root[y] \n root[y]=x \nfor i in range(m):\n a,b=map(int,input().split())\n a-=1 \n b-=1\n unite(a,b) \nans=0\nfor i in range(n):\n ans=max(ans,-root[i]) \nprint(ans)\n', 'n,m=map(int,input().split())\nroot=[-1]*n\ndef r(x): \n if root[x]<0: \n return x \n else: \n root[x]=r(root[x]) \n return root[x] \ndef unite(x,y):\n x=r(x)\n y=r(y)\n if x==y: \n return\n root[x]+=root[y] \n root[y]=x \nfor i in range(m):\n a,b=map(int,input().split())\n a-=1 \n b-=1\n unite(a,b) \nans=0\nfor i in range(n):\n ans=max(ans,-root[i]) \nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s195921835', 's423412823', 's813687048', 's092146275'] | [43032.0, 42960.0, 9020.0, 13240.0] | [2207.0, 2207.0, 25.0, 668.0] | [368, 371, 809, 807] |
p02573 | u417365712 | 2,000 | 1,048,576 | 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? | ['class UnionFind():\n def __init__(self, n):\n self._n = n\n self._table = [-1]*n\n\n def _root(self, x):\n stack = []\n while self._table[x] >= 0:\n stack.append(x)\n x = self._table[x]\n for y in stack:\n self._table[y] = x\n return x\n \n def unite(self, x, y):\n x, y = self._root(x), self._root(y)\n if x == y:\n return\n if x > y:\n x, y = y, x\n self._table[x] += self._table[y]\n self._table[y] = x\n \n def same(self, x, y):\n return self._root(x) == self._root(y)\n\n def count_members(self, x):\n return -self._table[self._root(x)]\n \n def count_groups(self):\n return len({self._root(i) for i in range(self._n)})\n \n def __str__(self):\n return str([self._root(i) for i in range(self._n)])\n \n def __repr__(self): \n return repr([self._root(i) for i in range(self._n)])\n\nn, m, *AB = map(int, open(0).read().split())\nuf = UnionFind(n)\nfor a, b in zip(AB[::2], AB[1::2]):\n uf.unite(a, b)\ns = 0\nfor group in {uf._root(i) for i in range(n)}:\n s += uf.count_members(group)-1\nprint(s)', 'class UnionFind:\n def __init__(self, n):\n self._n = n\n self._table = [-1]*n\n\n def _root(self, x):\n stack = []\n while self._table[x] >= 0:\n stack.append(x)\n x = self._table[x]\n for y in stack:\n self._table[y] = x\n return x\n \n def unite(self, x, y):\n x, y = self._root(x), self._root(y)\n if x == y:\n return\n if x > y:\n x, y = y, x\n self._table[x] += self._table[y]\n self._table[y] = x\n\n def same(self, x, y):\n return self._root(x) == self._root(y)\n\n def count_members(self, x):\n return -self._table[self._root(x)]\n\n def count_groups(self):\n return len({self._root(i) for i in range(self._n)})\n\n def __iter__(self):\n return (self._root(i) for i in range(self._n))\n\n def __str__(self):\n return str([self._root(i) for i in range(self._n)])\n\n def __repr__(self):\n return repr([self._root(i) for i in range(self._n)])\n\nn, m, *AB = map(int, open(0).read().split())\nuf = UnionFind(n)\nfor a, b in zip(AB[::2], AB[1::2]):\n uf.unite(a-1, b-1)\nprint(max(uf.count_members(group) for group in set(uf)))'] | ['Runtime Error', 'Accepted'] | ['s606673727', 's780656197'] | [57280.0, 57412.0] | [327.0, 453.0] | [1178, 1194] |
p02573 | u427427681 | 2,000 | 1,048,576 | 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? | ['N,M = tuple(map(int,input().split()))\n# matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]\n\n\ngplist = [[-1]]\ndef match(ab):\n a,b=ab\n igpa = 0\n igpb = 0\n for i,gp in enumerate(gplist):\n if a in gp:\n igpa = i\n if b in gp:\n return\n elif b in gp:\n igpb = i\n if bool(igpa) and bool(igpb):\n break\n if not bool(igpa) and not bool(igpb):\n gplist.append([a,b])\n elif bool(igpa) and not bool(igpb):\n gplist[igpa].append(b)\n elif not bool(igpa) and bool(igpb):\n gplist[igpb].append(a)\n else:\n gplist[igpa].extend(gplist[igpb])\n gplist.remove(gplist[igpb])\n\n\nprint(gplist)\nfor i in range(M):\n \n match(tuple(map(lambda x:int(x)-1,input().split())))\n # print(gplist)\nprint(max([len(item) for item in gplist]))', 'N,M = tuple(map(int,input().split()))\nmatchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]\n\nfriendlist = [[i] for i in range(N)]\n\ndef match(ab):\n a,b=ab\n lsa = friendlist[a].copy()\n lsb = friendlist[b].copy()\n if a in lsb:\n return\n else:\n for ip in lsa:\n friendlist[ip].extend(lsb)\n for ip in lsb:\n friendlist[ip].extend(lsa)\n\nfor i in range(M):\n match(matchlist[i])\n print(friendlist)\nprint(max([len(item) for item in friendlist]))', 'N,M = tuple(map(int,input().split()))\n# matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]\n\nfriendlist = list(range(N))\n\ngplist = [[i] for i in range(N)]\n\ndef getgroup(a):\n A = friendlist[a]\n if A == a:\n return a\n else:\n return getgroup(A)\n\ndef match(ab):\n A = getgroup(ab[0])\n B = getgroup(ab[1])\n if A==B:\n return\n elif len(gplist[A])<len(gplist[B]):\n gplist[B].extend(gplist[A])\n friendlist[A] = B\n else:\n gplist[A].extend(gplist[B])\n friendlist[B] = A\n\nfor i in range(M):\n \n # print(gplist)\n match(tuple(map(lambda x:int(x)-1,input().split())))\n\n\n# print(gplist)\n\nprint(max([len(item) for item in gplist]))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s315940826', 's795397412', 's932017523'] | [9960.0, 162676.0, 50256.0] | [2206.0, 2345.0, 912.0] | [970, 564, 834] |
p02573 | u432621419 | 2,000 | 1,048,576 | 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? | ['\n\nn,m = map(int,input().split())\n\na = [list(map(int,input().split())) for i in range(m)]\n\n#print(a[0][1])\n\nl = [n+1]*n\n\np = [1]*n\n\n\n\n\n\n\nfor j in range(m):\n if(l[a[j][0]] == n+1 & l[a[j][1]] == n+1):\n if(a[j][0] > a[j][1]):\n l[a[j][0]] = a[j][1]\n l[a[j][1]] = a[j][1]\n p[a[j][1]] = 2\n else:\n l[a[j][0]] = a[j][0]\n l[a[j][1]] = a[j][0]\n p[a[j][0]] = 2\n\n elif(l[a[j][0]] != n+1 & l[a[j][1]] != n+1):\n if(l[a[j][0]] < l[a[j][1]]):\n\n ###give up\n', '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nclass UnionFind():\n def __init__(self, n):\n self.parents = [-1]*n \n \n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y) \n if x==y:\n return\n \n if self.parents[x] > self.parents[y]:\n x,y = y,x\n \n self.parents[x] += self.parents[y]\n self.parents[y] = x\n \n def size(self,x):\n return -self.parents[self.find(x)]\n \ndef main():\n n,m = map(int,input().split())\n uf = UnionFind(n)\n for _ in range(m):\n a, b = map(int, input().split())\n uf.union(a-1,b-1)\n \n ans = 1\n for i in range(n):\n ans = max(ans, uf.size(i))\n print(ans)\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s604344579', 's557698661'] | [9052.0, 14408.0] | [28.0, 731.0] | [893, 2664] |
p02573 | u446782476 | 2,000 | 1,048,576 | 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? | ["NM = input()\nN = int(NM.split()[0])\nM = int(NM.split()[1])\ninfo = []\nfor i in range(M):\n info += [input()]\n\ninfo_friend = [info[i].split() for i in range(M)]\nprint(info)\nfriends = ['']*N\nfor j in range(N):\n friends[j] = str(j+1)\n for i in range(M):\n AB = info[i].split()\n A = AB[0]\n B = AB[1]\n if str(j+1) == A:\n friends[j] += B\n if str(j+1) == B:\n friends[j] += A\nfriends = [len(''.join(set(friends[i]))) for i in range(N)]\nprint(max(friends))", "# in[]:\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r))\n for r in self.roots())\n\n\n# in[]:\nNM = input()\nN = int(NM.split()[0])\nM = int(NM.split()[1])\n\ninfo = [input() for i in range(M)]\nuf = UnionFind(N)\n\nfor i in range(M):\n AB = info[i].split()\n A = int(AB[0]) - 1\n B = int(AB[1]) - 1\n uf.union(A, B)\n\nroots = uf.roots()\nrootsize = [uf.size(rt) for rt in roots]\nprint(max(rootsize))"] | ['Wrong Answer', 'Accepted'] | ['s678137795', 's029709295'] | [88068.0, 28700.0] | [2211.0, 556.0] | [510, 1480] |
p02573 | u452512115 | 2,000 | 1,048,576 | 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? | ['N, M = map(int, input().split())\n\n\n\ngraph = [[i+1] for i in range(M)]\n\nfor _ in range(M):\n a, b = map(int, input().split())\n graph[a-1].append(b)\n graph[b-1].append(a)\n\nans = -1\nfor g in graph:\n ans = max(ans, len(set(g)))\nprint(ans)\n', 'N, M = map(int, input().split())\n\n\n\ngraph = [[i+1] for i in range(N)]\n\nfor _ in range(M):\n a, b = map(int, input().split())\n graph[a-1].append(b)\n graph[b-1].append(a)\n\nans = -1\nprint(graph)\nfor g in graph:\n ans = max(ans, len(set(g)))\nprint(ans)\n', 'N, M = map(int, input().split())\nAB = [tuple(map(int,input().split())) for i in range(M)]\n\nclass UnionFind:\n def __init__(self,N):\n self.parent = [i for i in range(N)]\n self._size = [1] * N\n self.count = 0\n\n def root(self,a):\n if self.parent[a] == a:\n return a\n else:\n self.parent[a] = self.root(self.parent[a])\n return self.parent[a]\n def is_same(self,a,b):\n return self.root(a) == self.root(b)\n\n def unite(self,a,b):\n ra = self.root(a)\n rb = self.root(b)\n if ra == rb: return\n if self._size[ra] < self._size[rb]: ra,rb = rb,ra\n self._size[ra] += self._size[rb]\n self.parent[rb] = ra\n self.count += 1\n\n def size(self,a):\n return self._size[self.root(a)]\n\nuf = UnionFind(N)\nfor a,b in AB:\n a,b = a-1,b-1\n if uf.is_same(a,b): continue\n uf.unite(a,b)\n\nans = 0\nfor i in range(N):\n ans = max(ans, uf.size(i))\nprint(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s708619191', 's902390575', 's074596705'] | [52564.0, 64456.0, 45580.0] | [773.0, 935.0, 981.0] | [336, 349, 974] |
p02573 | u457554982 | 2,000 | 1,048,576 | 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? | ['import sys\nsys.setrecursionlimit(99999999)\n\n\n[n,m]=list(map(int,input().split()))\nfriends=[]\nfor i in range(m):\n friends.append(list(map(int,input().split())))\n\ntomodachi=[[]for i in range(n)]\n\nfor i in range(m):\n tomodachi[friends[i][0]-1].append(friends[i][1]-1)\n tomodachi[friends[i][1]-1].append(friends[i][0]-1)\n\nfor i in range(n):\n tomodachi[i]=list(set(tomodachi[i]))\n\nnamelist=[1 for i in range(n)]\nteams=[]\n\ndef haba(x,kari,tomodachi,namelist):\n for i in range(len(tomodachi[x])):\n if namelist[tomodachi[x][i]]==1:\n kari.append(tomodachi[x][i])\n namelist[tomodachi[x][i]]=0\n haba(tomodachi[x][i],kari,tomodachi,namelist)\n return(kari)\n \n\n\nfor i in range(n):\n if namelist[i]==1:\n teams.append(haba(i,[i],tomodachi,namelist))\n\nsaidai=99999999\n\nfor i in range(len(teams)):\n if saidai<len(teams[i]):\n saidai=len(teams[i])\n\nans=saidai\n\nprint(ans)', 'import sys\nsys.setrecursionlimit(99999999)\n\n\n[n,m]=list(map(int,input().split()))\nfriends=[]\nfor i in range(m):\n friends.append(list(map(int,input().split())))\n\ntomodachi=[[]for i in range(n)]\n\nfor i in range(m):\n tomodachi[friends[i][0]-1].append(friends[i][1]-1)\n tomodachi[friends[i][1]-1].append(friends[i][0]-1)\n\nfor i in range(n):\n tomodachi[i]=list(set(tomodachi[i]))\n\nnamelist=[1 for i in range(n)]\nteams=[]\n\ndef haba(x,kari,tomodachi,namelist):\n for i in range(len(tomodachi[x])):\n if namelist[tomodachi[x][i]]==1:\n kari.append(tomodachi[x][i])\n namelist[tomodachi[x][i]]=0\n haba(tomodachi[x][i],kari,tomodachi,namelist)\n return(kari)\n \n\n\nfor i in range(n):\n if namelist[i]==1:\n teams.append(list(set(haba(i,[i],tomodachi,namelist))))\n\nsaidai=0\n\nfor i in range(len(teams)):\n if saidai<len(teams[i]):\n saidai=len(teams[i])\n\nans=saidai\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s406432851', 's824371303'] | [263100.0, 263064.0] | [1185.0, 1316.0] | [974, 978] |
p02573 | u458967973 | 2,000 | 1,048,576 | 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? | ['n, m = map(int, input().split())\ndata2 = []\nfor i in range(m):\n data2.append(input().split())\n\n\ngraph = [[] for i in range(n)]\nfor i in range(m):\n a, b = map(lambda z: int(z) - 1, data2[m])\n graph[a].append(b)\n graph[b].append(a)\n\nprint(graph)\nsize = [0 for i in range(n)]\ncheck = [True for i in range(n)]\nfor i in range(n):\n if check[i]:\n tmp = 1\n stack = [i]\n check[i] = False\n while stack:\n now = stack.pop()\n size[now] = tmp\n print(size)\n tmp += 1\n for to in graph[now]:\n if check[to]:\n check[to] = False\n stack.append(to)\nprint(max(size))', 'n, m = map(int, input().split())\ndata2 = []\nfor i in range(m):\n data2.append(input().split())\n\ngraph = [[] for i in range(n)]\nfor i in range(0,m):\n a, b = map(lambda z: int(z) - 1, data2[i])\n graph[a].append(b)\n graph[b].append(a)\n\nsize = [0 for i in range(n)]\ncheck = [True for i in range(n)]\nfor i in range(n):\n if check[i]:\n tmp = 1\n stack = [i]\n check[i] = False\n while stack:\n now = stack.pop()\n size[now] = tmp\n tmp += 1\n for to in graph[now]:\n if check[to]:\n check[to] = False\n stack.append(to)\nprint(max(size))'] | ['Runtime Error', 'Accepted'] | ['s700301702', 's497548558'] | [150528.0, 110432.0] | [2373.0, 1074.0] | [694, 658] |
p02573 | u470560351 | 2,000 | 1,048,576 | 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? | ["N, M=map(int, input().split())\nimport collections\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n \n def main(self):\n return max([len(self.members(r)) for r in self.roots()])\nuf = UnionFind(N)\n\nfor _ in range(M):\n A, B = map(int, input().split())\n uf.union(A-1,B-1)\n\nc = collections.Counter(uf.parents)\nprint(c.most_common()[0][1])\n", "N, M=map(int, input().split())\nimport collections\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n \n def main(self):\n return max([len(self.members(r)) for r in self.roots()])\nuf = UnionFind(N)\n\nfor _ in range(M):\n A, B = map(int, input().split())\n uf.union(A-1,B-1)\n\nc = collections.Counter([i for i in uf.parents if i>0])\nprint(c.most_common()[0][1] + 1)\n", "N, M=map(int, input().split())\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n \n def main(self):\n return max([len(self.members(r)) for r in self.roots()])\nuf = UnionFind(N)\n\nfor _ in range(M):\n A, B = map(int, input().split())\n uf.union(A-1,B-1)\n \nprint(-min(uf.parents))\n"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s064886842', 's768132211', 's863922291'] | [17612.0, 17856.0, 14528.0] | [626.0, 657.0, 582.0] | [1447, 1471, 1389] |
p02573 | u490489966 | 2,000 | 1,048,576 | 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? | ['# D\nfrom collections import Counter\nn, m = map(int, input().split())\nab = [list(map(int, input().split()))for _ in range(m)]\nab.sort(key=lambda x:x[1])\nab.sort(key=lambda x:x[0])\n# print(ab)\npeople=[0]*n\nfor i in ab:\n if people[i[0]-1]==0:\n people[i[0]-1]=i[0]\n if people[i[1]-1]==0:\n people[i[1]-1]=people[i[0]-1]\n# print(people)\npeople=Counter(people).most_common()\nprint(people[0][1])', '# D\nfrom collections import Counter\nn, m = map(int, input().split())\nab = [list(map(int, input().split()))for _ in range(m)]\nfor i in ab:\n if i[0] > i[1]:\n i[0], i[1] = i[1], i[0]\nab.sort(key=lambda x: x[1])\nab.sort(key=lambda x: x[0])\nprint(ab)\npeople = [0]*n\nfor i in ab:\n if people[i[0]-1] == 0:\n people[i[0]-1] = i[0]\n people[i[1]-1] = people[i[0]-1]\nprint(people)\n# Counter.(list).most_common()\npeople = Counter(people).most_common()\nprint(people[0][1])\n', '# D\nfrom collections import Counter\nn, m = map(int, input().split())\nab = [list(map(int, input().split()))for _ in range(m)]\nfor i in ab:\n if i[0]>i[1]:\n i[0],i[1]=i[1],i[0]\nab.sort(key=lambda x:x[1])\nab.sort(key=lambda x:x[0])\nprint(ab)\npeople=[0]*n\nfor i in ab:\n if people[i[0]-1]==0:\n people[i[0]-1]=i[0]\n if people[i[1]-1]==0:\n people[i[1]-1]=people[i[0]-1]\nprint(people)\npeople=Counter(people).most_common()\nprint(people[0][1])', "class UnionFind():\n def __init__(self,n):\n self.n=n\n self.parents=[-1]*n\n\n def find(self,x): \n \n if self.parents[x]<0: \n return x \n \n else:\n \n self.parents[x]=self.find(self.parents[x])\n return self.parents[x]\n \n def union(self,x,y): \n \n x=self.find(x)\n y=self.find(y)\n\n if x==y:\n return\n if self.parents[x]>self.parents[y]: \n x,y=y,x\n\n self.parents[x]+=self.parents[y] \n self.parents[y]=x\n\n def size(self,x): \n return -self.parents[self.find(x)]\n \n def same(self,x,y): \n return self.find(x)==self.find(y)\n\n def members(self,x): \n root=self.find(x)\n return [i for i in range(self.n) if self.find(i)==root]\n \n def roots(self): \n return [i for i ,x in enumerate(self.parents) if x<0]\n\n def group_count(self): \n return len(self.roots())\n\n def all_group_members(self): \n return {r:self.members(r) for r in relf.roots()}\n\n def __str__(self): \n return '\\n'.join('{}:{}'.format(r,self.members(r)) for r in self.roots())\n\nN,M=map(int,input().split())\nuf=UnionFind(N)\n\n\nfor i in range(M):\n a,b=map(int,input().split())\n uf.union(a-1,b-1)\n\nans=0\nroots=uf.roots()\n\nfor i in roots:\n ans=max(ans,uf.size(i))\n\nprint(ans)\n"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s117079495', 's843675974', 's913825775', 's996961195'] | [73468.0, 56964.0, 57028.0, 18480.0] | [853.0, 1008.0, 1035.0, 605.0] | [407, 482, 462, 2300] |
p02573 | u513434790 | 2,000 | 1,048,576 | 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? | ['import sys\nsys.setrecursionlimit(10*100)\n\nN, M = map(int, input().split())\nUF = [-1] * (N+1)\ndef find(x):\n global UF\n if UF[x] == -1:\n return x\n else:\n UF[x] = find(UF[x])\n return UF[x]\ndef union(x,y):\n global UF\n xx = find(x)\n yy = find(y)\n if UF[x] == UF[y] == -1:\n UF[y] = xx\n return\n elif xx == yy:\n return \n else:\n UF[yy] = xx\n return \n \nfor _ in range(M):\n x, y = map(int, input().split())\n union(x,y)\n \ncnt = [0] * (N+1)\n\nprint(max(cnt))\n\n', 'import sys\nsys.setrecursionlimit(500*500)\n\nN, M = map(int, input().split())\nUF = [-1] * (N+1)\ndef find(x):\n global UF\n if UF[x] == -1:\n return x\n else:\n UF[x] = find(UF[x])\n return UF[x]\ndef union(x,y):\n global UF\n xx = find(x)\n yy = find(y)\n if UF[x] == UF[y] == -1:\n UF[y] = xx\n return\n elif xx == yy:\n return \n else:\n UF[yy] = xx\n return \n \nfor _ in range(M):\n x, y = map(int, input().split())\n union(x,y)\n \ncnt = [0] * (N+1)\nfor i in range(1,N+1):\n z = find(i)\n cnt[z] += 1\n\nprint(max(cnt))\n\n'] | ['Wrong Answer', 'Accepted'] | ['s847218776', 's611913428'] | [14816.0, 36784.0] | [595.0, 694.0] | [603, 597] |
p02573 | u521271655 | 2,000 | 1,048,576 | 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? | ['from collections import Counter\nn,m = map(int,input().split())\ngroup = {}\nfor i in range(1,n+1):\n group[i] = i\nfor _ in range(m):\n a,b = map(int,input().split())\n k = min(group[a],group[b])\n group[a] = k\n group[b] = k\np = Counter(group.values())\nprint(max(p.values()) + 1)\n', 'from collections import Counter\ndef find(x):\n if par[x] < 0:\n return x\n else:\n par[x] = find(par[x])\n return par[x]\n\ndef unite(x,y):\n x = find(x)\n y = find(y)\n \n if x == y:\n return False\n else:\n \n if par[x] > par[y]:\n x,y = y,x\n par[x] += par[y]\n par[y] = x\n return True\n\n\ndef same(x,y):\n return find(x) == find(y)\n\n\ndef size(x):\n return -par[find(x)]\n\nn,m = map(int,input().split())\npar = [-1]*n\nfor _ in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n unite(a,b)\nans = 0\nfor i in range(n):\n ans = max(size(i),ans)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s921799573', 's192020581'] | [46044.0, 14884.0] | [568.0, 693.0] | [288, 787] |
p02573 | u521866787 | 2,000 | 1,048,576 | 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? | ['class UnionFind:\n def __init__(self, n):\n self.par = list(range(n)) \n self.rank = [0] * n \n\n \n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n \n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n # if they have the same parent, no need to union\n return\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n else:\n self.par[y] = x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n\nN, M = map(int, input().split())\nuf = UnionFind(N)\n\nfor _ in range(M):\n a, b = map(int, input().split())\n uf.unite(a-1, b-1)\n\n# from collections import Counter\n\n\n# print(max(c.values()))\n\ncnt = [0] *n\nfor i in range(N):\n cnt[uf.par[i]] += 1\nprint(max(cnt))', 'class UnionFind:\n \n \n def __init__(self, n):\n self.n = n\n \n \n self.root = [-1]*(n+1)\n \n self.rank = [0]*(n+1)\n\n \n def findRoot(self, x):\n if(self.root[x] < 0): \n return x\n else:\n \n self.root[x] = self.findRoot(self.root[x])\n return self.root[x]\n \n def unite(self, x, y):\n \n x = self.findRoot(x)\n y = self.findRoot(y)\n \n if x == y:\n return \n \n if self.rank[x] > self.rank[y]:\n self.root[x] += self.root[y]\n self.root[y] = x\n\n else:\n self.root[y] += self.root[x]\n self.root[x] = y\n \n if self.rank[x] == self.rank[y]:\n self.rank[y] += 1\n \n def isSameGroup(self, x, y):\n return self.findRoot(x) == self.findRoot(y)\n\n \n def count(self, x):\n return -self.root[self.findRoot(x)]\n\nn,m = map(int,input().split())\nunion = UnionFind(n)\n\nfor i in range(m):\n x, y = map(int,input().split())\n union.unite(x, y)\n\nans = 0\n\nfor i in range(n):\n ans = max(union.count(i), ans)\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s951173297', 's453321576'] | [18312.0, 14504.0] | [721.0, 766.0] | [1147, 1967] |
p02573 | u522293645 | 2,000 | 1,048,576 | 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? | ["import collections \n# import itertools # accumulate, compress, permutations(nPr), combinations(nCr)\n\n\n# import heapq\n\n# from fractions import Fraction\n# from math import gcd # <Python3.5\n# --------------------------------------------------------------\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\n\nn,m = map(int,input().split())\nlis = [list(map(int,input().split())) for _ in range(m)]\n \ncmax = 0\n \nuf = UnionFind(n)\n\nfor i in lis:\n uf.union(i[0],i[1])\n\nfor i in range(n):\n cmax = max(cmax, uf.size(i))\n\nprint(cmax)", "import collections \n# import itertools # accumulate, compress, permutations(nPr), combinations(nCr)\n\n\n# import heapq\n\n# from fractions import Fraction\n# from math import gcd # <Python3.5\n# --------------------------------------------------------------\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\n\nn,m = map(int,input().split())\nlis = [list(map(int,input().split())) for _ in range(m)]\n\nroad = [[] for i in range(n)] \n \nfor i in lis:\n i[0]-=1\n i[1]-=1\n road[i[0]].append(i[1])\n road[i[1]].append(i[0])\n\ncmax = 0\n \nuf = UnionFind(n)\n\nfor i in lis:\n uf.union(i[0],i[1])\n\nfor i in range(n):\n cmax = max(cmax, uf.size(i))\n\nprint(cmax)"] | ['Runtime Error', 'Accepted'] | ['s638093355', 's147106947'] | [47656.0, 68012.0] | [591.0, 1275.0] | [1860, 2029] |
p02573 | u531599639 | 2,000 | 1,048,576 | 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? | ['from collections import deque\nn,m = map(int,input().split())\nl = [set([]) for i in range(n+1)]\nfor i in range(m):\n a,b = map(int,input().split())\n l[a].add(b)\n l[b].add(a)\nQ = deque()\nfor i in range(n):\n Q.append(i+1)\nvis = [-1]*(n+1)\nvis[1] = 1\nwhile Q:\n temp = Q.popleft()\n for v in l[temp]:\n if vis[temp]!=-1:\n continue\n vis[v] = vis[temp]+1\n Q.appendleft(v)\nprint(max(vis)+1)', "class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\nn,m = map(int,input().split())\nuf = UnionFind(n)\nfor _ in range(m):\n a,b = map(int,input().split())\n uf.union(a-1,b-1)\nroot = [0]*n\nfor i in range(n):\n root[uf.find(i)] += 1\nprint(max(root))"] | ['Wrong Answer', 'Accepted'] | ['s477958872', 's524312913'] | [80204.0, 16112.0] | [2209.0, 710.0] | [399, 1340] |
p02573 | u540627185 | 2,000 | 1,048,576 | 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? | ["import sys\nsys.setrecursionlimit(10**7)\ndef input(): return sys.stdin.readline().rstrip()\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\ndef main():\n n, m = map(int, input().split())\n\n uf = UnionFind(n)\n for _ in range(m):\n a, b = map(int, input().split())\n uf.unite(a-1, b-1)\n roots = uf.roots()\n cnt = []\n for r in roots:\n cnt.append(uf.size(r))\n print(max(cnt))\n\nif __name__ == '__main__':\n main()\n", "import sys\nsys.setrecursionlimit(10**7)\ndef input(): return sys.stdin.readline().rstrip()\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\ndef main():\n n, m = map(int, input().split())\n\n uf = UnionFind(n)\n for _ in range(m):\n a, b = map(int, input().split())\n uf.unite(a-1, b-1)\n roots = uf.roots()\n cnt = []\n for r in roots:\n cnt.append(uf.size(r))\n print(max(cnt))\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s601036891', 's152242557'] | [9060.0, 19956.0] | [26.0, 381.0] | [1445, 1439] |
p02573 | u543016260 | 2,000 | 1,048,576 | 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? | ["import sys\nimport math\nN=int(input())\nA=list(map(int,input().split()))\n\n\ndef sieve_of_eratosthenes(n): \n candidate = list(range(2, n+1)) \n prime = []\n limit = n**0.5 + 1 \n\n while True:\n p = candidate[0] \n if limit <= p:\n prime.extend(candidate) \n break\n prime.append(p) \n\n candidate = [i for i in candidate if i % p != 0]\n\n \n # while True:\n \n # break\n \n \n \n\n return prime\n\n\n\nmaxA=max(A)\n\nprime = sieve_of_eratosthenes(maxA)\n\nX=[0]*(maxA+1)\nfor i in range(N):\n X[A[i]]+=1\n\ncheck=0\nfor i in prime:\n count=0\n for j in range(1,int(maxA/i)+1):\n count+=X[j*i]\n if count==N:\n print('not coprime')\n sys.exit()\n elif count>1:\n check=1\n \nif check==1:\n print('setwise coprime')\nelse:\n print('pairwise coprime')", 'N, M=map(int, input().split())\nA=[]\nB=[]\nfor i in range(M):\n a,b=map(int, input().split())\n A.append(a)\n B.append(b)\n# AB= [map(int, input().split()) for _ in range(M)]\n\ndef find(x,parent):\n if parent[x]==x:\n return x\n else:\n parent[x]=find(parent[x],parent)\n return(parent[x])\n \ndef union(x,y,parent,rank):\n xroot=find(x,parent)\n yroot=find(y,parent)\n if rank[xroot]>rank[yroot]:\n parent[yroot]=xroot\n elif rank[yroot]>rank[xroot]:\n parent[xroot]=yroot\n elif rank[yroot]==rank[xroot]:\n parent[yroot]=xroot\n rank[xroot]+=1\n return(parent,rank)\n\n \nparent=[i for i in range(N+1)]\nrank=[0]*(N+1)\nfor i in range(M):\n parent,rank=union(A[i],B[i],parent,rank)\nfor i in range(N+1):\n find(i,parent)\nG=parent[1:]\nimport collections\nc=collections.Counter(G)\nprint(int(c.most_common()[0][1]))'] | ['Runtime Error', 'Accepted'] | ['s273461688', 's532545408'] | [9092.0, 46220.0] | [24.0, 733.0] | [1250, 915] |
p02573 | u544587633 | 2,000 | 1,048,576 | 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? | ['#!/usr/bin/env python3\nimport sys\nimport networkx as nx\nfrom random import randint\ndef solve(N: int, M: int, A: "List[int]", B: "List[int]"):\n G=nx.Graph()\n\n if M == 0 :\n print(1)\n return\n\n for a, b in zip(A,B):\n G.add_edge(a, b)\n\n Gc = max(nx.connected_components(G), key=len)\n print(len(Gc))\n return\n\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n \n # for line in sys.stdin:\n # for word in line.split():\n \n \n while True:\n N = randint(10000, 100000) # type: int\n M = 0 # type: int\n\n A = [randint(1, N) for i in range(M)] # type: "List[int]"\n B = [randint(1, N) for i in range(M)] # type: "List[int]"\n solve(N, M, A, B)\n\nif __name__ == \'__main__\':\n main()\n', '#!/usr/bin/env python3\nimport sys\nimport networkx as nx\n\ndef solve(N: int, M: int, A: "List[int]", B: "List[int]"):\n G=nx.Graph()\n\n if M == 0 :\n print(1)\n return\n\n for a, b in zip(A,B):\n G.add_edge(a, b)\n\n Gc = max(nx.connected_components(G), key=len)\n print(len(Gc))\n return\n\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n M = int(next(tokens)) # type: int\n A = [int()] * (M) # type: "List[int]"\n B = [int()] * (M) # type: "List[int]"\n for i in range(M):\n A[i] = int(next(tokens))\n B[i] = int(next(tokens))\n solve(N, M, A, B)\n\nif __name__ == \'__main__\':\n main()\n'] | ['Time Limit Exceeded', 'Accepted'] | ['s937897216', 's650085983'] | [53544.0, 258428.0] | [2208.0, 1751.0] | [975, 963] |
p02573 | u572271833 | 2,000 | 1,048,576 | 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? | ["#Union Find\n\n\ndef find(x):\n if par[x] < 0:\n return x\n else:\n par[x] = find(par[x])\n return par[x]\n\ndef unite(x,y):\n x = find(x)\n y = find(y)\n \n if x == y:\n return False\n else:\n \n if par[x] > par[y]:\n x,y = y,x\n par[x] += par[y]\n par[y] = x\n return True\n\n\ndef same(x,y):\n return find(x) == find(y)\n\n\ndef size(x):\n return -par[find(x)]\n\nimport numpy as np\nn, m = map(int, input().split( ))\n\n\n\npar = [-1]*n\n\nfor i in range(m):\n x,y=map(int,input().split(' '))\n unite(x,y)\n\n# print(par)\nprint(-min(par))", "#Union Find\n\n\ndef find(x):\n if par[x] < 0:\n return x\n else:\n par[x] = find(par[x])\n return par[x]\n\ndef unite(x,y):\n x = find(x)\n y = find(y)\n \n if x == y:\n return False\n else:\n \n if par[x] > par[y]:\n x,y = y,x\n par[x] += par[y]\n par[y] = x\n return True\n\n\ndef same(x,y):\n return find(x) == find(y)\n\n\ndef size(x):\n return -par[find(x)]\n\nimport numpy as np\nn, m = map(int, input().split( ))\n\n\n\npar = [-1]*n\n\nfor i in range(m):\n x,y=map(int,input().split(' '))\n unite(x-1,y-1)\n\n# print(par)\nprint(-min(par))"] | ['Runtime Error', 'Accepted'] | ['s291581001', 's919203040'] | [32384.0, 32444.0] | [593.0, 648.0] | [807, 811] |
p02573 | u576335153 | 2,000 | 1,048,576 | 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? | ['n, m = map(int, input().split())\nab = [list(map(int, input().split()))]\n\nfriends = [0]*n\ngroup = [-1]*n\n\nfor a, b in ab:\n if a > b:\n a, b = b, a\n a -= 1\n b -= 1\n if group[a] == -1 and group[b] == -1:\n group[a] = a\n group[b] = b\n friends[a] += 2\n elif group[a] != -1 and group[b] != -1:\n group[b] = group[a]\n friends[group[a]] += friends[group[b]]\n elif group[a] == -1:\n group[a] = group[b]\n friends[group[b]] += 1\n elif group[b] == -1:\n group[b] = group[a]\n friends[group[a]] += 1\n\nprint(max(friends))\n', "import typing\n\n\nclass DSU:\n '''\n Implement (union by size) + (path compression)\n Reference:\n Zvi Galil and Giuseppe F. Italiano,\n Data structures and algorithms for disjoint set union problems\n '''\n\n def __init__(self, n: int = 0):\n self._n = n\n self.parent_or_size = [-1] * n\n\n def merge(self, a: int, b: int) -> int:\n assert 0 <= a < self._n\n assert 0 <= b < self._n\n\n x = self.leader(a)\n y = self.leader(b)\n\n if x == y:\n return x\n\n if -self.parent_or_size[x] < -self.parent_or_size[y]:\n x, y = y, x\n\n self.parent_or_size[x] += self.parent_or_size[y]\n self.parent_or_size[y] = x\n\n return x\n\n def same(self, a: int, b: int) -> bool:\n assert 0 <= a < self._n\n assert 0 <= b < self._n\n\n return self.leader(a) == self.leader(b)\n\n def leader(self, a: int) -> int:\n assert 0 <= a < self._n\n\n if self.parent_or_size[a] < 0:\n return a\n\n self.parent_or_size[a] = self.leader(self.parent_or_size[a])\n return self.parent_or_size[a]\n\n def size(self, a: int) -> int:\n assert 0 <= a < self._n\n\n return -self.parent_or_size[self.leader(a)]\n\n def groups(self) -> typing.List[typing.List[int]]:\n leader_buf = [self.leader(i) for i in range(self._n)]\n\n result = [[] for _ in range(self._n)]\n for i in range(self._n):\n result[leader_buf[i]].append(i)\n\n return list(filter(lambda r: r, result))\n\nn, m = map(int, input().split())\n \nuf = DSU(n)\n \nfor _ in range(m):\n a, b = map(int, input().split())\n uf.marge(a-1, b-1)\n \nans = 0\n \nfor i in range(n):\n ans = max(ans, uf.size(i))\n \nprint(ans)", "import typing\n\n\nclass DSU:\n '''\n Implement (union by size) + (path compression)\n Reference:\n Zvi Galil and Giuseppe F. Italiano,\n Data structures and algorithms for disjoint set union problems\n '''\n\n def __init__(self, n: int = 0):\n self._n = n\n self.parent_or_size = [-1] * n\n\n def merge(self, a: int, b: int) -> int:\n assert 0 <= a < self._n\n assert 0 <= b < self._n\n\n x = self.leader(a)\n y = self.leader(b)\n\n if x == y:\n return x\n\n if -self.parent_or_size[x] < -self.parent_or_size[y]:\n x, y = y, x\n\n self.parent_or_size[x] += self.parent_or_size[y]\n self.parent_or_size[y] = x\n\n return x\n\n def same(self, a: int, b: int) -> bool:\n assert 0 <= a < self._n\n assert 0 <= b < self._n\n\n return self.leader(a) == self.leader(b)\n\n def leader(self, a: int) -> int:\n assert 0 <= a < self._n\n\n if self.parent_or_size[a] < 0:\n return a\n\n self.parent_or_size[a] = self.leader(self.parent_or_size[a])\n return self.parent_or_size[a]\n\n def size(self, a: int) -> int:\n assert 0 <= a < self._n\n\n return -self.parent_or_size[self.leader(a)]\n\n def groups(self) -> typing.List[typing.List[int]]:\n leader_buf = [self.leader(i) for i in range(self._n)]\n\n result = [[] for _ in range(self._n)]\n for i in range(self._n):\n result[leader_buf[i]].append(i)\n\n return list(filter(lambda r: r, result))\n\n\nn, m = map(int, input().split())\n\nuf = DSU(n)\n\nfor _ in range(m):\n a, b = map(int, input().split())\n uf.merge(a - 1, b - 1)\n\nans = 0\n\nfor i in range(n):\n ans = max(ans, uf.size(i))\n\nprint(ans)\n"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s581672160', 's804048831', 's295013484'] | [11936.0, 11656.0, 15796.0] | [38.0, 143.0, 860.0] | [593, 1728, 1729] |
p02573 | u581022379 | 2,000 | 1,048,576 | 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? | ['from collections import Counter\nN, M = map(int, input().split())\ngroups = [0] * (N + 1)\ngroup_num_list = [[0]]\ngroup_num = 1\nfor _ in range(M):\n A, B = map(int, input().split())\n if groups[A] != 0 and groups[B] != 0:\n if groups[A] != groups[B]:\n lower = min(groups[A], groups[B])\n higher = max(groups[A], groups[B])\n for i in group_num_list[higher]:\n groups[i] = lower\n tmp = group_num_list[higher]\n group_num_list[lower].extend(tmp)\n \n elif groups[A] != 0:\n groups[B] = groups[A]\n group_num_list[groups[A]].append(B)\n elif groups[B] != 0:\n groups[A] = groups[B]\n group_num_list[groups[B]].append(A)\n else:\n groups[A] = group_num\n groups[B] = group_num\n #group_num_list.append([A, B])\n group_num += 1\ncounter = Counter(groups)\n# print(collection)\n# print(group_num_list)\nif counter.most_common()[0][0] != 0:\n print(counter.most_common()[0][1])\nelse:\n print(counter.most_common()[1][1])\n', 'from collections import Counter\nN, M = map(int, input().split())\ngroups = [0] * (N + 1)\ngroup_num_list = [[0]]\ngroup_num = 1\nfor _ in range(M):\n A, B = map(int, input().split())\n if groups[A] != 0 and groups[B] != 0:\n if groups[A] != groups[B]:\n lower = min(groups[A], groups[B])\n higher = max(groups[A], groups[B])\n for i in group_num_list[higher]:\n groups[i] = lower\n tmp = group_num_list[higher]\n group_num_list[lower].extend(tmp)\n \n elif groups[A] != 0:\n groups[B] = groups[A]\n group_num_list[groups[A]].append(int(B))\n elif groups[B] != 0:\n groups[A] = groups[B]\n group_num_list[groups[B]].append(int(A))\n else:\n groups[A] = group_num\n groups[B] = group_num\n group_num_list.append([int(A), int(B)])\n group_num += 1\ncounter = Counter(groups)\n# print(collection)\n# print(group_num_list)\nif len(group_num_list) == 1:\n print(1)\nelif int(counter.most_common()[0][0]) != 0:\n print(counter.most_common()[0][1])\nelse:\n print(counter.most_common()[1][1])\n'] | ['Runtime Error', 'Accepted'] | ['s730237974', 's983318990'] | [10908.0, 31380.0] | [43.0, 727.0] | [1079, 1147] |
p02573 | u581403769 | 2,000 | 1,048,576 | 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? | ['n, m = map(int, input().split())\n\npar = [i + 1 for i in range(n)]\nrank = [0] * n\nsize = [1] * n\n\ndef find(x):\n if par[x - 1] == x:\n return x\n else:\n return find(par[x - 1])\n\ndef union(x, y):\n x = find(x)\n y = find(y)\n if rank[x] < rank[y]:\n par[x] = y\n size[x] += size[y]\n else:\n par[y] = x\n size[y] += size[x]\n if rank[x] == rank[y]:\n rank[x] += 1\n\nfor i in range(m):\n a, b = map(int, input().split())\n union(a, b)\n\nprint(max(size))', 'n, m = map(int, input().split())\n\npar = [i + 1 for i in range(n)]\nrank = [1] * n\nsize = [1] * n\n\ndef find(x):\n if par[x - 1] == x:\n return x\n else:\n return find(par[x - 1])\n\ndef union(x, y):\n x = find(x)\n y = find(y)\n if x == y:\n return\n if rank[x - 1] < rank[y - 1]:\n par[x - 1] = y\n size[y - 1] += size[x - 1]\n else:\n par[y - 1] = x\n size[x - 1] += size[y - 1]\n if rank[x - 1] == rank[y - 1]:\n rank[x - 1] += 1\n\nfor i in range(m):\n a, b = map(int, input().split())\n union(a, b)\n\nprint(max(size))'] | ['Runtime Error', 'Accepted'] | ['s134951086', 's548524353'] | [63560.0, 20136.0] | [619.0, 691.0] | [517, 591] |
p02573 | u583285098 | 2,000 | 1,048,576 | 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? | ['import collections\n\nn, m = map(int, input().split())\nif m == 0:\n print(1)\n exit()\nif m == 1:\n print(2)\n exit()\nids = {i: 0 for i in range(1, n+1)}\nid = 1\nfor _ in range(m):\n a, b = map(int, input().split())\n if ids[a] == 0 and ids[b] != 0:\n ids[a] = ids[b]\n elif ids[a] != 0 and ids[b] == 0:\n ids[b] = ids[a]\n elif ids[a] == 0 and ids[b] == 0:\n ids[a] = id\n ids[b] = id\n id += 1\ntmp = collections.Counter(ids.values())\ntmp.pop(0)\nprint(max(tmp.values()))\n', 'import collections\n\nn, m = map(int, input().split())\nif m == 0:\n print(1)\n exit()\nif m == 1:\n print(2)\n exit()\nboss = list(range(n))\n\ndef look_boss(target):\n num = target\n if boss[num] == 0:\n boss[target] = num\n return num\n while num != boss[num]:\n num = boss[num]\n boss[target] = num\n return num\n\nfor _ in range(m):\n a, b = map(int, input().split())\n boss_a = look_boss(a-1)\n boss_b = look_boss(b-1)\n if boss_a != boss_b:\n boss[boss_b] = boss_a\n\ncount = [0]*n\nfor i in range(n):\n count[look_boss(i)] += 1\nprint(max(count))\n', 'import collections\n\nn, m = map(int, input().split())\nif m == 0:\n print(1)\n exit()\nif m == 1:\n print(2)\n exit()\nboss = list(range(n))\n\ndef look_boss(num):\n if boss[num] == 0:\n return num\n while num != boss[num]:\n num = boss[num]\n return num\n\nfor _ in range(m):\n a, b = map(int, input().split())\n boss_a = look_boss(a-1)\n boss[a-1] = boss_a\n boss_b = look_boss(b-1)\n boss[b-1] = boss_b\n if boss_a != boss_b:\n boss[boss_b] = boss_a\n\ncount = [0]*n\nfor i in range(n):\n count[look_boss(i)] += 1\nprint(max(count))\n', 'import collections\n\nn, m = map(int, input().split())\nif m == 0:\n print(1)\n exit()\nif m == 1:\n print(2)\n exit()\nboss = list(range(n))\n\ndef look_boss(target):\n num = target\n while num != boss[num]:\n num = boss[num]\n boss[target] = num\n return num\n\nfor _ in range(m):\n a, b = map(int, input().split())\n boss_a = look_boss(a-1)\n boss_b = look_boss(b-1)\n if boss_a != boss_b:\n boss[boss_b] = boss_a\n\ncount = [0]*n\nfor i in range(n):\n count[look_boss(i)] += 1\nprint(max(count))\n'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s025451698', 's307342392', 's338344245', 's501133574'] | [32476.0, 18596.0, 18740.0, 18760.0] | [564.0, 1989.0, 2206.0, 1857.0] | [514, 594, 570, 525] |
p02573 | u585963734 | 2,000 | 1,048,576 | 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? | ['import collections as col\nfrom collections import defaultdict as dd\n\nd=dd(list)\n\nN,M=map(int, input().split())\np=[-1]*N\ncnt=[0]*N\n\nfor _ in range(M):\n i,j=map(int, input().split())\n if i>j:\n i,j=j,i\n d[i].append(j)\n\nfor i in d:\n for j in d[i]:\n print(i,j)\n if p[j-1]!=-1:\n if p[i-1]==-1:\n p[i-1]=j\n cnt[p[j-1]]+=1\n continue\n if p[i-1]==-1:\n p[j-1]=i\n cnt[i]+=1\n else:\n p[j-1]=p[i-1]\n cnt[p[i-1]]+=1\n\ncnt.sort(reverse=True)\nprint(cnt[0]+1)', 'import numpy as np\nfrom collections import deque\nfrom collections import defaultdict as dd\nimport sys\nsys.setrecursionlimit(10**8)\n\ndef DFS():\n temp=q.pop()\n\n for i in range(len(d[temp])):\n if chk[d[temp][i]-1]==0:\n chk[d[temp][i]-1]=1\n q.append(d[temp][i])\n else:break\n\n if d[temp][i] not in d[temp]:\n d[temp].append(d[temp][i])\n\n if len(q)>0:\n DFS()\n else:\n f=0\n for i in range(N):\n if chk[i]==0:\n f=1\n chk[i]=1\n q.append(i+1)\n break\n\n if f==0:\n ans()\n else:\n DFS()\n return\n\ndef ans():\n a=0\n for i in range(len(d)):\n a=max(a,len(d[i])+1)\n print(a) \n exit(0)\n \n return\n\n\nq=[]\nd=dd(list)\nN,M=map(int, input().split())\nchk=np.zeros(N,dtype=np.int)\n\nfor _ in range(M):\n i,j=map(int, input().split())\n if i>j:\n i,j=j,i\n\n if j not in d[i]:\n d[i].append(j)\n if i not in d[j]:\n d[j].append(i)\n\nq.append(1)\nchk[0]=1\n\nDFS()', '\nfrom collections import defaultdict as dd\nfrom collections import deque\nimport collections as col\nd=dd(list)\nq=deque([])\n\nN,M=map(int, input().split())\nfor _ in range(M):\n f=0\n i,j=map(int, input().split())\n if i>j:\n i,j=j,i\n d[i].append(j)\nchk=[0]*N\nchk[0]=1\ntemp=1\na=0\nwhile a<N:\n for i in range(len(d[temp])):\n if chk[d[temp][i]-1]==0:\n chk[d[temp][i]-1]=1\n for j in range(len(d[d[temp][i]])):\n chk[d[d[temp][i]][j]-1]=1\n d[temp].append(d[d[temp][i]][j])\n q.append(d[d[temp][i]][j])\n\n if len(q)>0:\n temp=q.pop()\n if chk[temp-1]==0:\n continue\n\n else:\n while a<N:\n if chk[a]==0:\n chk[a]=1\n temp=a+1\n break\n a+=1\nprint(d)\nans=0\nfor i in range(N):\n ans=max(ans,len(col.Counter(d[i]))+1)\nprint(ans)', 'import numpy as np\nfrom collections import deque\nfrom collections import defaultdict as dd\nimport collections as col\nimport sys\nsys.setrecursionlimit(10**8)\n\ndef DFS():\n temp=q.pop()\n\n for i in range(len(d[temp])):\n if chk[d[temp][i]-1]==0:\n chk[d[temp][i]-1]=1\n q.append(d[temp][i])\n else:break\n\n if d[temp][i] not in d[temp]:\n d[temp].append(d[temp][i])\n\n if len(q)>0:\n DFS()\n else:\n f=0\n for i in range(N):\n if chk[i]==0:\n f=1\n chk[i]=1\n q.append(i+1)\n break\n\n if f==0:\n ans()\n else:\n DFS()\n return\n\ndef ans():\n ans=0\n for i in d:\n if len(d[i])>0:\n ans=max(ans,len(col.Counter(d[i]))+1)\n print(ans)\n exit(0)\n\n return\n\n\nq=[]\nd=dd(list)\nN,M=map(int, input().split())\nchk=np.zeros(N,dtype=np.int)\n\nfor _ in range(M):\n i,j=map(int, input().split())\n if i>j:\n i,j=j,i\n d[i].append(j)\n\nq.append(1)\nchk[0]=1\n\nDFS()', 'from collections import defaultdict as dd\nfrom collections import deque\nimport collections as col\nd=dd(list)\nq=deque([])\n\nN,M=map(int, input().split())\nfor _ in range(M):\n f=0\n i,j=map(int, input().split())\n if i>j:\n i,j=j,i\n d[i].append(j)\nchk=[0]*N\nchk[0]=1\ntemp=1\na=0\nwhile a<N:\n for i in range(len(d[temp])):\n for j in range(len(d[d[temp][i]])):\n chk[d[d[temp][i]][j]-1]=1\n d[temp].append(d[d[temp][i]][j])\n q.append(d[d[temp][i]][j])\n\n if len(q)==0:\n while a<N:\n if chk[a]==0:\n chk[a]=1\n temp=a+1\n break\n a+=1\n else:\n temp=q.pop()\nprint(d)\nans=0\nfor i in range(N):\n ans=max(ans,len(col.Counter(d[i]))+1)\nprint(ans)', 'from collections import defaultdict as dd\nfrom collections import deque\nimport collections as col\nd=dd(list)\nq=deque([])\n\nN,M=map(int, input().split())\nfor _ in range(M):\n i,j=map(int, input().split())\n if i>j:\n i,j=j,i\n f=0\n for a in range(i):\n if i in d[a]:\n f=1\n d[a].append(j)\n break\n \n if f==1:continue\n else:d[i].append(j)\n\n\n\nprint(d)\nans=0\nfor i in range(N):\n if len(d[i])>0:\n ans=max(ans,len(col.Counter(d[i]))+1)\nprint(ans)', "import sys\nsys.setrecursionlimit(10**8)\n\ndef find(x):\n if par[x]==x:\n return x\n else:\n par[x]=find(par[x])\n return par[x]\n\ndef union(a,b):\n a=find(a)\n b=find(b)\n if a==b:\n return\n \n if rank[a]<rank[b]:\n par[a]=b\n rank[b]+=rank[a]\n rank[a]=rank[b]\n else:\n par[b]=a\n rank[a]+=rank[b]\n rank[b]=rank[a]\n\n return\n\ndef chk(a,b):\n if par[a]==par[b]:\n print('Yes')\n else:\n print('No')\n\n return\n\nN,M=map(int, input().split())\n\npar=(list(range(N+1)))\nrank=[1]*(N+1)\n\nfor _ in range(M):\n A,B=map(int, input().split())\n union(A,B)\n\nprint(max(rank))"] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s018416900', 's056183100', 's088353080', 's240530425', 's787641035', 's807840027', 's366987523'] | [55496.0, 240688.0, 63984.0, 240544.0, 83100.0, 41408.0, 22140.0] | [727.0, 2212.0, 1202.0, 2211.0, 2208.0, 2206.0, 598.0] | [581, 1069, 894, 1056, 772, 519, 662] |
p02573 | u594803920 | 2,000 | 1,048,576 | 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? | ['import sys\ninput=sys.stdin.readline\nsys.setrecursionlimit(10 ** 8)\nfrom itertools import accumulate\nfrom itertools import permutations\nfrom itertools import combinations\nfrom collections import defaultdict\nfrom collections import Counter\nimport fractions\nimport math\nfrom collections import deque\nfrom bisect import bisect_left\nfrom bisect import bisect_right\nfrom bisect import insort_left\nimport itertools\nfrom heapq import heapify\nfrom heapq import heappop\nfrom heapq import heappush\nimport heapq\nfrom copy import deepcopy\nfrom decimal import Decimal\nalf = list("abcdefghijklmnopqrstuvwxyz")\nALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")\n#import numpy as np\nINF = float("inf")\n\n\nN,M = map(int,input().split())\ncount = [[0]*N for _ in range(N)]\nfr = [[] for _ in range(N)]\nfor _ in range(M):\n a,b = map(int,input().split())\n a,b = a-1,b-1\n if count[a][b] == 1:\n continue\n count[a][b] = 1\n count[b][a] = 1\n fr[a].append(b)\n fr[b].append(a)\nused = [-1]*N \nMAX = 0\ndef dfs(fr,cur,parent,cnt):\n global MAX\n MAX = max(cnt,MAX)\n children = fr[cur]\n for chi in children:\n if chi == parent or used[chi] != -1:\n continue\n print(chi, used)\n used[chi] = 0\n cnt += 1\n dfs(fr,chi,cur,cnt)\n return\n\nfor i in range(N):\n print(i, 999)\n cnt = 1\n if used[i] != -1:\n continue\n used[i] = 0\n dfs(fr,i,-1,cnt)\nprint(MAX)\n\n \n\n\n\n\n\n\n', 'import sys\ninput=sys.stdin.readline\nsys.setrecursionlimit(10 ** 6)\nfrom itertools import accumulate\nfrom itertools import permutations\nfrom itertools import combinations\nfrom collections import defaultdict\nfrom collections import Counter\nimport fractions\nimport math\nfrom collections import deque\nfrom bisect import bisect_left\nfrom bisect import bisect_right\nfrom bisect import insort_left\nimport itertools\nfrom heapq import heapify\nfrom heapq import heappop\nfrom heapq import heappush\nimport heapq\nfrom copy import deepcopy\nfrom decimal import Decimal\nalf = list("abcdefghijklmnopqrstuvwxyz")\nALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")\n#import numpy as np\nINF = float("inf")\n\n\nN,M = map(int,input().split())\nfr = [[] for _ in range(N)]\nfor _ in range(M):\n a,b = map(int,input().split())\n a,b = a-1,b-1\n fr[a].append(b)\n fr[b].append(a)\nused = [-1]*N \nMAX = 0\ndef dfs(fr,cur,parent):\n global cnt\n children = fr[cur]\n for chi in children:\n if used[chi] != -1:\n continue\n if chi == parent:\n continue\n used[chi] = 0\n cnt += 1\n dfs(fr,chi,cur)\n return\n\nfor i in range(N):\n cnt = 1\n if used[i] != -1:\n continue\n used[i] = 0\n dfs(fr,i,-1)\n MAX = max(MAX, cnt)\nprint(MAX)\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s818480816', 's009997368'] | [2689616.0, 223100.0] | [2344.0, 594.0] | [1470, 1312] |
p02573 | u604522449 | 2,000 | 1,048,576 | 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? | ["import sys,os\nimport math\nfrom fractions import Fraction \nfrom collections import defaultdict\nfrom random import randint\n\n# sys.stderr=open('err.txt','w')\n# sys.stdout=open('output.txt','w')\n# sys.stdin=open('input.txt','r')\n\ndef linput():\n return list(minput())\n\ndef minput():\n return map(int, sys.stdin.readline().strip().split())\n\n###############################################################\n\ndef make_set(a,parent):\n parent[a]=a\n\ndef find_set(a,parent):\n if parent[a]==a:\n return a\n parent[a]=find_set(parent[a])\n return parent[a]\n\ndef union_set(a,b,parent):\n x=find_set(a)\n y=find_set(b)\n if x==y:\n return\n else:\n parent[y]=x\n\nn,m=minput()\nparent=[0]*n\nfor i in range(n):\n make_set(i,parent)\nans=0\nfor i in range(m):\n x,y=minput()\n if x>y:\n x,y=y,x\n x=x-1\n y=y-1\n union_set(x,y,parent)\n# print(parent)\ndi = defaultdict(int)\nfor i in parent:\n di[i]+=1\n# print(di)\nfor k,v in di.items():\n ans=max(ans,v)\nprint(ans)\n", "import sys,os\nimport math\nfrom fractions import Fraction \nfrom collections import defaultdict\nfrom random import randint\n\n# sys.stderr=open('err.txt','w')\n# sys.stdout=open('output.txt','w')\n# sys.stdin=open('input.txt','r')\n\ndef linput():\n return list(minput())\n\ndef minput():\n return map(int, sys.stdin.readline().strip().split())\n\n###############################################################\n\ndef make_set(a):\n parent[a]=a\n sizen[a]=1\n\ndef find_set(a):\n if parent[a]==a:\n return a\n parent[a]=find_set(parent[a])\n return parent[a]\n\ndef union_set(a,b):\n x=find_set(a)\n y=find_set(b)\n if x==y:\n return\n else:\n if sizen[x]>sizen[y]:\n parent[y]=x\n sizen[x]+=sizen[y]\n else:\n parent[x]=y\n sizen[y]+=sizen[x]\n\nn,m=minput()\nparent=[0]*n\nsizen=[0]*n\nfor i in range(n):\n make_set(i)\nans=0\nfor i in range(m):\n x,y=minput()\n if x>y:\n x,y=y,x\n x=x-1\n y=y-1\n union_set(x,y)\n# print(parent)\ndi = defaultdict(int)\n\n# di[i]+=1\n# print(di)\n\nfor v in sizen:\n ans=max(ans,v)\nprint(ans)\n"] | ['Runtime Error', 'Accepted'] | ['s329706787', 's834306286'] | [33672.0, 19728.0] | [164.0, 473.0] | [1003, 1127] |
p02573 | u610042046 | 2,000 | 1,048,576 | 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? | ['n, m = map(int, input().split())\nfr = [set() for x in range(n+1)]\nfor _ in range(m):\n a, b = map(int, input().split())\n fr[a].add(b)\n fr[b].add(a)\nprint(fr)\nmax_fr = 0\nfor i in fr:\n max_fr = max(len(i)+1, max_fr)\nprint(max_fr)', 'n, m = map(int, input().split())\nfr = [[] for _ in range(n)]\nfor _ in range(m):\n a, b = list(map(int, input().split()))\n fr[a-1].append(b-1)\n fr[b-1].append(a-1)\nmax_gr = 0\ncheck = [False for _ in range(n)]\nans = 0\n\nfor per in range(n):\n if check[per]:\n continue\n\n else:\n tank = [per]\n count = 0\n while tank:\n now = tank.pop()\n if check[now]:\n continue\n else:\n check[now] = True\n count += 1\n for j in fr[now]:\n if not check[j]:\n tank.append(j)\n\n ans = max(ans, count)\n\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s282737312', 's495418404'] | [77444.0, 44484.0] | [979.0, 810.0] | [238, 665] |
p02573 | u618251217 | 2,000 | 1,048,576 | 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? | ['from sys import stdin\ninput = stdin.readline\n\nN,M = map(int, input().split())\nlis = [0]*(N+1)\nA = [0]*M; B = [0]*M\nfor i in range(M):\n a, b = map(int, input().split())\n a,b = min(a,b), max(a,b)\n if lis[a] == 0:\n lis[a] = a\n else:\n lis[b] = lis[a]\n\nlis.sort()\nmaxcnt = 0\ncnt = 0\nprev = -1\nfor i in range(1,N+1):\n if lis[i] == 0:\n continue\n if prev == -1:\n prev = lis[i]\n cnt += 1\n elif lis[i] == prev:\n cnt += 1\n else:\n maxcnt = max(maxcnt, cnt)\n cnt = 0\nprint(maxcnt)', '#BFS\nfrom collections import deque\nfrom sys import stdin\ninput = stdin.readline\n\nN,M = map(int, input().split())\nneighbor = [[] for _ in range(N)]\nfor i in range(M):\n a,b = map(lambda x: int(x) - 1, input().split())\n neighbor[a].append(b)\n neighbor[b].append(a)\n\nchecked = [0]*N\nqueue = deque()\ngroup = [0]*N\ngroupnum = 0\nfor i in range(N):\n if group[i] == 0:\n groupnum += 1\n queue.append(i)\n group[i] = groupnum\n while queue:\n x = queue.popleft()\n for p in neighbor[x]:\n if group[p] == 0:\n queue.append(p)\n group[p] = groupnum\n\ngroup_membercnt = [0]*(N+1)\nfor num in group:\n group_membercnt[num] += 1\nprint(max(group_membercnt[1:]))'] | ['Wrong Answer', 'Accepted'] | ['s266735195', 's787396951'] | [19696.0, 49432.0] | [411.0, 590.0] | [547, 751] |
p02573 | u619850971 | 2,000 | 1,048,576 | 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? | ['class UnionFind(): \n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n\nif __name__ == "__main__":\n N, M = map(int, input().split()) \n union_find = UnionFind(N)\n for _ in range(M):\n A, B = map(int, input().split())\n A -= 1\n B -= 1\n union_find.union(A, B)\n\n answer = 0\n for i in range(N):\n answer = max(answer, union_find.size(i))\n\n print(answer)\n', 'class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n\nif __name__ == "__main__":\n N, M = map(int, input().split()) \n union_find = UnionFind(N)\n for _ in range(M):\n A, B = map(int, input().split())\n A -= 1\n B -= 1\n union_find.union(A, B)\n\n answer = 0\n for i in range(N):\n answer = max(answer, union_find.size(i))\n\n print(answer)\n'] | ['Runtime Error', 'Accepted'] | ['s867463274', 's837967562'] | [8928.0, 14516.0] | [29.0, 759.0] | [911, 937] |
p02573 | u623283955 | 2,000 | 1,048,576 | 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? | ['n,m=map(int,input().split())\np=[(i,1)for i in range(n)]\ndef find(i):\n if p[i][0]==i:return i\n else:\n c=find(p[i][0])\n p[i]=(c,0)\n return c\ndef union(i,j):\n pi=find(i)\n pj=find(j)\n if not pi==pj:\n if p[pi][1]>p[pj][1]:\n p[pi]=(pi,p[pi][1]+p[pj][1])\n p[pj]=(pi,0)\n else:\n p[pj]=(pj,p[pi][1]+p[pj][1])\n p[pi]=(pj,0)\n \n\nfor i in range(m):\n a,b=map(int,input().split())\n union(a,b)\nans=0\nfor i in range(n):\n if p[i][0]==i:ans=max(ans,p[i][1])\nprint(ans)', 'n,m=map(int,input().split())\np=[(i,1)for i in range(n)]\ndef find(i):\n if p[i][0]==i:return i\n else:\n c=find(p[i])\n p[i]=(c,0)\n return c\ndef union(i,j):\n pi=find(i)\n pj=find(j)\n if not pi==pj:\n if p[pi][1]>p[pj][1]:\n p[pj]=(pi,p[pi][1]+p[pj][1])\n else:\n p[pi]=(pj,p[pi][1]+p[pj][1])\n\nfor i in range(m):\n a,b=map(int,input().split())\n union(a-1,b-1)\nans=0\nfor i in range(n):\n if p[i][0]==i:ans=max(ans,p[i][1])\nprint(ans)', 'n,m=map(int,input().split())\np=[(i,1)for i in range(n)]\ndef find(i):\n if p[i][0]==i:return i\n else:\n c=find(p[i][0])\n p[i]=(c,0)\n return c\ndef union(i,j):\n pi=find(i)\n pj=find(j)\n if not pi==pj:\n if p[pi][1]>p[pj][1]:\n p[pi]=(pi,p[pi][1]+p[pj][1])\n p[pj]=(pi,0)\n else:\n p[pj]=(pj,p[pi][1]+p[pj][1])\n p[pi]=(pj,0)\n \n\nfor i in range(m):\n a,b=map(int,input().split())\n union(a-1,b-1)\nans=0\nfor i in range(n):\n if p[i][0]==i:ans=max(ans,p[i][1])\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s296801397', 's334849136', 's700342851'] | [29640.0, 29628.0, 29624.0] | [639.0, 538.0, 969.0] | [496, 452, 500] |
p02573 | u627600101 | 2,000 | 1,048,576 | 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? | ["from math import gcd\n\n# = map(int, input().split())\nN = int(input())\nA = list(map(int, input().split()))\nmA = max(A)\ncounter = [0 for _ in range(mA+1)]\n\nprimenum = [2]\nsgn = [-1 for _ in range(int(mA**0.5)+1)]\nk = 3\nwhile k**2 <= mA:\n if sgn[k] == -1:\n primenum.append(k)\n add = k*k\n ok = k\n while ok**2 <= mA:\n sgn[ok] = 1\n ok += add\n k += 2\n\ndef factorization(n):\n M = n\n for p in primenum:\n if p**2 > M:\n break\n else:\n if M%p == 0:\n if counter[p] == 0:\n counter[p] = 1\n else:\n return False\n while M%p == 0:\n M //= p\n\n if M > 1:\n if counter[M] == 0:\n counter[M] = 1\n else:\n return False\n return True\n\n\n\ng = A[0]\nflag = True\nfor k in range(N):\n a = A[k]\n g = gcd(g, a)\n if flag:\n flag = factorization(a)\n\n\nif flag:\n print('pairwise coprime')\n exit()\nif g == 1:\n print('setwise coprime')\nelse:\n print('not coprime')\n", 'import sys\nsys.setrecursionlimit(2*10**9)\n\nN, M = map(int, input().split())\nfriends = [[] for _ in range(N)]\nfor k in range(M):\n A, B = map(int, input().split())\n A -= 1\n B -= 1\n friends[A].append(B)\n friends[B].append(A)\ngroup = []\nsgn = [0 for _ in range(N)] \ndef make_group(person, groupnum):\n sgn[person] = 1\n for f in friends[person]:\n if sgn[f] == 0:\n group[groupnum].append(f)\n make_group(f, groupnum)\n return None\n\nc = 0\nfor k in range(N):\n if sgn[k] == 0:\n group.append([k])\n make_group(k, c)\n c += 1\nans = 0\nfor g in group:\n ans = max(len(g), ans)\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s267844419', 's890205191'] | [9156.0, 212224.0] | [27.0, 873.0] | [975, 617] |
p02573 | u630554891 | 2,000 | 1,048,576 | 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? | ['n,m= map(int, input().split())\npar = [i for i in range(n)]\n\ndef find(x):\n if par[x] == x:\n return x\n else:\n par[x] = find(par[x])\n return par[x]\n\ndef unite(x, y):\n x = find(x)\n y = find(y)\n if x > y:\n par[x] = y\n find(x)\n else:\n par[y] = x\n find(y)\n\nif m > 0: \n for i in range(m):\n a, b = map(int, input().split())\n unite(a - 1, b - 1)\n\n print(par)\n ans=0\n for i in range(n):\n tmp = par.count(i)\n if tmp > ans:\n ans = tmp\n print(ans)', 'n,m= map(int, input().split())\npar = [i for i in range(n)]\n\ndef find(x):\n if par[x] == x:\n return x\n else:\n par[x] = find(par[x])\n return par[x]\n\ndef unite(x, y):\n x = find(x)\n y = find(y)\n if x > y:\n par[x] = y\n find(x)\n else:\n par[y] = x\n find(y)\n\nif m > 0: \n for i in range(m):\n a, b = map(int, input().split())\n unite(a - 1, b - 1)\n \n ans = [0] * n\n Max = 0\n for i in range(n):\n find(i)\n for i in par:\n ans[i] += 1\n for i in ans:\n if i > Max:\n Max = i\n \n print(Max)\nelse:\n print(1)'] | ['Wrong Answer', 'Accepted'] | ['s077712083', 's463058719'] | [19672.0, 18384.0] | [2206.0, 683.0] | [515, 543] |
p02573 | u638902622 | 2,000 | 1,048,576 | 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? | ["import sys\n\ndef IS(): return sys.stdin.readline().rstrip()\ndef II(): return int(IS())\ndef MII(): return list(map(int, IS().split()))\ndef MIIZ(): return list(map(lambda x: x-1, MII()))\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n def find(self, x):\n if self.parents[x] < 0: return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y: return\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n def size(self, x):\n return -self.parents[self.find(x)]\n def same(self, x, y):\n return self.find(x) == self.find(y)\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n def group_count(self):\n return len(self.roots())\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n#======================================================#\n\ndef main():\n n, m = MII()\n group = [MIIZ() for _ in range(m)]\n uf = UnionFind(n)\n for a, b in group:\n uf.union(a, b)\n\n \n # maxv = max([len(gi) for gi in g])\n # print(maxv)\n\n\nif __name__ == '__main__':\n main()", "import sys\n\ndef IS(): return sys.stdin.readline().rstrip()\ndef II(): return int(IS())\ndef MII(): return list(map(int, IS().split()))\ndef MIIZ(): return list(map(lambda x: x-1, MII()))\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n def find(self, x):\n if self.parents[x] < 0: return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y: return\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n def size(self, x):\n return -self.parents[self.find(x)]\n def same(self, x, y):\n return self.find(x) == self.find(y)\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n def group_count(self):\n return len(self.roots())\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n def count_member_nums(self):\n return [len(self.members(r)) for r in self.roots()]\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n#======================================================#\n\ndef main():\n n, m = MII()\n group = [MIIZ() for _ in range(m)]\n uf = UnionFind(n)\n for a, b in group:\n uf.union(a, b)\n print(abs(sorted(uf.parents)[0]))\n\n\nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Accepted'] | ['s611482931', 's004526767'] | [47324.0, 49532.0] | [534.0, 609.0] | [1637, 1667] |
p02573 | u649769812 | 2,000 | 1,048,576 | 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? | ['n, m = map(int, input().split())\n\nfriend_list = [set()]\ninput_list = []\n\nfor i in range(m):\n a, b = map(int, input().split())\n input_list.append([sorted([a, b])])\n\nsorted(input_list)\n\nfor inp in input_list:\n found = False\n for friend_set in friend_list:\n if inp[0] in friend_set:\n friend_set.add(b)\n found = True\n break\n # elif b in friend_set:\n # friend_set.add(a)\n \n # break\n if not found:\n friend_set = set()\n friend_set.add(a)\n friend_set.add(b)\n friend_list.append(friend_set)\n\nans = 0\nfor friend_set in friend_list:\n ans = max(len(friend_set), ans)\n\nprint(ans)', 'import sys\n\nsys.setrecursionlimit(10 ** 9)\n\nn, m = map(int, input().split())\n\n\nclass UnionFind:\n def __init__(self, n):\n self.n = n\n self.root = [-1] * n\n\n def find(self, x):\n if self.root[x] < 0:\n return x\n else:\n self.root[x] = self.find(self.root[x])\n return self.root[x]\n\n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n self.root[x] += self.root[y]\n self.root[y] = x\n\n def size(self, x):\n return -1 * self.root[self.find(x)]\n\n\nunion_find = UnionFind(n)\n\nfor i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n union_find.unite(a, b)\n\nans = 0\nfor i in range(n):\n ans = max(ans, union_find.size(i))\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s187618790', 's922593161'] | [63580.0, 35884.0] | [1019.0, 829.0] | [706, 801] |
p02573 | u649840780 | 2,000 | 1,048,576 | 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? | ['class Node():\n def __init__(self,index):\n self.index = index\n self.parent = self \n self.size = 1\n\n @staticmethod\n def find_set(node):\n return node\n if node.parent == node:\n return node \n root = Node.find_set(node.parent)\n node.parent = root\n root.size += 1\n return root\n\n @staticmethod\n def union(node_a,node_b):\n root_a = Node.find_set(node_a)\n root_b = Node.find_set(node_b)\n if root_a != root_b:\n if root_a.size < root_b.size:\n root_a.parent = root_b\n else:\n root_b.parent = root_a\n\n\n\nif __name__ == "__main__":\n n,m = [int(val) for val in input().split()]\n \n persons = []\n count = []\n for i in range(n):\n persons.append(Node(i))\n count.append(0)\n \n for i in range(m):\n a,b = [int(val) for val in input().split()]\n if a > b:\n Node.union(persons[a-1],persons[b-1])\n else:\n Node.union(persons[b-1],persons[a-1])\n\n\n for idx,person in enumerate(persons):\n count[Node.find_set(person).index] += 1\n \n # print(count)\n result = max(count)\n print(result)\n\n', 'class Node():\n def __init__(self,index):\n self.index = index\n self.parent = self \n self.size = 1\n\n @staticmethod\n def find_set(node):\n if node.parent == node:\n return node \n root = Node.find_set(node.parent)\n node.parent = root\n return root\n\n @staticmethod\n def union(node_a,node_b):\n root_a = Node.find_set(node_a)\n root_b = Node.find_set(node_b)\n if root_a != root_b:\n if root_a.size < root_b.size:\n root_a.parent = root_b\n root_b.size == root_a.size\n else:\n root_b.parent = root_a\n root_a.size += root_b.size\n\n\n\nif __name__ == "__main__":\n n,m = [int(val) for val in input().split()]\n \n persons = []\n count = []\n for i in range(n):\n persons.append(Node(i))\n count.append(0)\n \n for i in range(m):\n a,b = [int(val) for val in input().split()]\n if a > b:\n Node.union(persons[a-1],persons[b-1])\n else:\n Node.union(persons[b-1],persons[a-1])\n\n\n for idx,person in enumerate(persons):\n count[Node.find_set(person).index] += 1\n \n # print(count)\n result = max(count)\n print(result)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s401170925', 's382871358'] | [50428.0, 50432.0] | [957.0, 1092.0] | [1212, 1255] |
p02573 | u667084803 | 2,000 | 1,048,576 | 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? | ['N, M = map(int, input().split())\npath = [set() for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n path[a-1].add(b-1)\n path[b-1].add(a-1)\nvisited = [0] * N\n\nans = 1\nfor u in range(N):\n if visited[u] == 1:\n continue\n curr = 1\n next_u = path[u]\n while next_u:\n v = next_u.pop()\n if visited[v] == 1:\n continue\n visited[v] = 1\n curr += 1\n for w in path[v]:\n if visited[w] == 0:\n next_u.add(w)\n ans = max(ans, curr)\n\nprint(ans)', 'N, M = map(int, input().split())\npath = [[] for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n path[a-1] += [b-1]\n path[b-1] += [a-1]\nvisited = [1] + [0] * (N-1)\n\nans = 1\nfor u in range(N):\n if visited[u] == 1:\n continue\n curr = 1\n next_u = path[u]\n while next_u:\n v = next_u.pop()\n if visited[v] == 1:\n continue\n visited[v] = 1\n curr += 1\n for w in path[v]:\n if visited[w] == 0:\n next_u += [w]\n print(u, curr)\n ans = max(ans, curr)\n\nprint(ans)', 'N, M = map(int, input().split())\npath = [set() for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n path[a-1].add(b-1)\n path[b-1].add(a-1)\nvisited = [0] * N\n\nans = 1\nfor u in range(N):\n if visited[u] == 1:\n continue\n curr = 1\n visited[u] = 1\n next_u = path[u]\n while next_u:\n v = next_u.pop()\n if visited[v] == 1:\n continue\n visited[v] = 1\n curr += 1\n for w in path[v]:\n if visited[w] == 0:\n next_u.add(w)\n ans = max(ans, curr)\n\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s118700669', 's351256715', 's508024818'] | [77552.0, 158472.0, 77724.0] | [917.0, 2209.0, 886.0] | [546, 572, 565] |
p02573 | u671455949 | 2,000 | 1,048,576 | 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? | ['n, m = map(int, input().split())\ngroup_idx = [i for i in range(n)]\n\nfor i in range(m):\n a, b = map(int, input().split())\n if a > b:\n a, b = b, a\n group_idx[b - 1] = group_idx[a - 1]\n print(group_idx)\n\ngroups = [0 for i in range(n)]\n\nfor i in range(n):\n groups[group_idx[i]] += 1\n\nprint(group_idx)\nprint(max(groups))', 'def find(x):\n if par[x] < 0:\n return x\n else:\n par[x] = find(par[x])\n return par[x]\n\ndef unite(x,y):\n x = find(x)\n y = find(y)\n \n if x == y:\n return False\n else:\n \n if par[x] > par[y]:\n x,y = y,x\n par[x] += par[y]\n par[y] = x\n return True\n\n\ndef same(x,y):\n return find(x) == find(y)\n\n\ndef size(x):\n return -par[find(x)]\n\n\n\nn, m = map(int, input().split())\npar = [-1]*n\n\nfor i in range(m):\n a, b = map(int, input().split())\n unite(a - 1, b - 1)\n\nans = 0\nfor i in range(n):\n ans = max(ans, size(i))\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s370472496', 's832455988'] | [149524.0, 14288.0] | [3774.0, 692.0] | [323, 793] |
p02573 | u686036872 | 2,000 | 1,048,576 | 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? | ['class UnionFind:\n def __init__(self, N):\n self.N = N\n self.parent = [-1] * N\n\n def root(self, A):\n if (self.parent[A] < 0):\n return A\n self.parent[A] = self.root(self.parent[A])\n return self.parent[A]\n\n def size(self, A):\n return -self.parent[self.root(A)]\n\n def unite(self, A, B):\n A = self.root(A)\n B = self.root(B)\n\n if (A == B):\n return False\n\n if (self.size(A) < self.size(B)):\n A, B = B, A\n\n self.parent[A] += self.parent[B]\n self.parent[B] = A\n\n return True\n\n def is_in_same(self, A, B):\n return self.root(A) == self.root(B)\n\n\nN, M = map(int, input().split())\nuf = UnionFind(N)\n\nfor i in range(M):\n a, b = map(int, input().split())\n uf.union(a, b)\n\nprint(max(uf.size(i)) for i in range(1, N+1))\n', 'class UnionFind:\n def __init__(self, N):\n self.N = N\n self.parent = [-1] * N\n\n def root(self, A):\n if (self.parent[A] < 0):\n return A\n self.parent[A] = self.root(self.parent[A])\n return self.parent[A]\n\n def size(self, A):\n return -self.parent[self.root(A)]\n\n def unite(self, A, B):\n A = self.root(A)\n B = self.root(B)\n\n if (A == B):\n return False\n\n if (self.size(A) < self.size(B)):\n A, B = B, A\n\n self.parent[A] += self.parent[B]\n self.parent[B] = A\n\n return True\n\n def is_in_same(self, A, B):\n return self.root(A) == self.root(B)\n\n\nN, M = map(int, input().split())\nuf = UnionFind(N)\n\nfor i in range(M):\n a, b = map(int, input().split())\n uf.unite(a-1, b-1)\n\nans = 0\nfor i in range(N):\n ans = max(ans, uf.size(i))\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s305963280', 's209573870'] | [10556.0, 14784.0] | [34.0, 909.0] | [854, 880] |
p02573 | u686230543 | 2,000 | 1,048,576 | 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? | ['def zero_origin(s: str):\n return int(s) - 1\n\n\nclass UnionFindTree:\n """Union Find Tree for disjoint-set data structure.\n\n Args:\n n (int): number of the vertices.\n """\n def __init__(self, n: int):\n self.parent = list(range(n))\n self.rank = [0] * n\n self.size = [1] * n\n\n def find(self, i: int) -> int:\n if self.parent[i] != i:\n self.parent[i] = self.find(self.parent[i])\n return self.parent[i]\n\n def unite(self, i: int, j: int):\n ri = self.find(i)\n rj = self.find(j)\n size = self.size[ri] + self.size[rj]\n self.size[ri] = size\n self.size[rj] = size\n if ri != rj:\n if self.rank[ri] < self.rank[rj]:\n self.parent[ri] = rj\n else:\n self.parent[rj] = ri\n if self.rank[ri] == self.rank[rj]:\n self.rank[ri] += 1\n\n def is_same(self, i: int, j: int) -> bool:\n return self.find(i) == self.find(j)\n\n\nn, m = map(int, input().split())\nuft = UnionFindTree(n)\nfor _ in range(m):\n a, b = map(zero_origin, input().split())\n uft.unite(a, b)\nprint(max(utf.size))', 'def zero_origin(s: str):\n return int(s) - 1\n\n\nclass UnionFindTree:\n """Union Find Tree for disjoint-set data structure.\n\n Args:\n n (int): number of the vertices.\n """\n def __init__(self, n: int):\n self.parent = list(range(n))\n self.rank = [0] * n\n self.size = [1] * n\n\n def find(self, i: int) -> int:\n if self.parent[i] != i:\n self.parent[i] = self.find(self.parent[i])\n return self.parent[i]\n\n def unite(self, i: int, j: int):\n ri = self.find(i)\n rj = self.find(j)\n size = self.size[ri] + self.size[rj]\n self.size[ri] = size\n self.size[rj] = size\n if ri != rj:\n if self.rank[ri] < self.rank[rj]:\n self.parent[ri] = rj\n else:\n self.parent[rj] = ri\n if self.rank[ri] == self.rank[rj]:\n self.rank[ri] += 1\n\n def is_same(self, i: int, j: int) -> bool:\n return self.find(i) == self.find(j)\n\n\nn, m = map(int, input().split())\nuft = UnionFindTree(n)\nfor _ in range(m):\n a, b = map(zero_origin, input().split())\n uft.unite(a, b)\nprint(max(utf.size))', 'def zero_origin(s: str):\n return int(s) - 1\n\n\nclass UnionFindTree:\n """Union Find Tree for disjoint-set data structure.\n\n Args:\n n (int): number of the vertices.\n """\n def __init__(self, n: int):\n self.parent = list(range(n))\n self.rank = [0] * n\n self.size = [1] * n\n\n def find(self, i: int) -> int:\n if self.parent[i] != i:\n self.parent[i] = self.find(self.parent[i])\n return self.parent[i]\n\n def unite(self, i: int, j: int):\n ri = self.find(i)\n rj = self.find(j)\n if ri != rj:\n if self.rank[ri] < self.rank[rj]:\n self.parent[ri] = rj\n self.size[rj] += self.size[ri]\n else:\n self.parent[rj] = ri\n self.size[ri] += self.size[rj]\n if self.rank[ri] == self.rank[rj]:\n self.rank[ri] += 1\n\n def is_same(self, i: int, j: int) -> bool:\n return self.find(i) == self.find(j)\n\n\nn, m = map(int, input().split())\nuft = UnionFindTree(n)\nfor _ in range(m):\n a, b = map(zero_origin, input().split())\n uft.unite(a, b)\nprint(max(uft.size))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s198593637', 's251128056', 's953118159'] | [105000.0, 104980.0, 20080.0] | [1073.0, 1069.0, 726.0] | [1036, 1036, 1023] |
p02573 | u698902360 | 2,000 | 1,048,576 | 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? | ['import sys\nfrom collections import defaultdict\nimport collections\n\n\nclass UnionFind2:\n def __init__(self, size):\n \n \n self.table = [-1 for _ in range(size)]\n\n \n def find(self, x):\n if self.table[x] < 0:\n return x\n else:\n \n self.table[x] = self.find(self.table[x])\n return self.table[x]\n\n \n def union(self, x, y):\n s1 = self.find(x)\n s2 = self.find(y)\n if s1 != s2:\n self.table[s2] = s1\n return True\n return False\n\n\nN, M = map(int, input().split())\nuf = UnionFind2(N+1)\n\nfor i in range(M):\n A, B = map(int, input().split())\n uf.union(A, B)\n\nhoge = [uf.find(i) for i in range(N)]\n\n# print(hoge)\nhogehoge = collections.Counter(hoge).most_common()\n\nprint(hogehoge[0][1])', 'import sys\nfrom collections import defaultdict\nimport collections\n\nsys.setrecursionlimit(1000000)\n\nclass UnionFindPathCompression():\n def __init__(self, n):\n self.parents = list(range(n))\n\n def find(self, x):\n if self.parents[x] == x:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n self.parents[y] = x\n\n\nN, M = map(int, input().split())\nuf = UnionFindPathCompression(N)\n\nfor i in range(M):\n A, B = map(int, input().split())\n uf.union(A - 1, B - 1)\n\nhoge = [uf.find(i) for i in range(N)]\n\n#print(hoge)\nhogehoge = collections.Counter(hoge).most_common()\n\nprint(hogehoge[0][1])\n'] | ['Runtime Error', 'Accepted'] | ['s263687645', 's521067431'] | [44568.0, 51028.0] | [781.0, 925.0] | [946, 807] |
p02573 | u719260857 | 2,000 | 1,048,576 | 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? | ["import collections\n\nn, m = map(int, input().split(' '))\n\nf = [x for x in range(n)]\n\ndef find(x):\n if f[x] == x:\n return x\n root = find(f[x])\n f[x] = root\n return root\n\nfor i in range(m):\n a, b = map(int, input().split(' '))\n a -= 1\n b -= 1\n if find(a) != find(b):\n f[find(a)] = find(b)\n\nfor i in range(n):\n find(i)\n \nprint(max(collections.Counter(f).values()))\nprint(f)", "import collections\nimport sys\nimport resource\nsys.setrecursionlimit(1000000)\n\nn, m = map(int, input().split(' '))\n\nf = [x for x in range(n)]\n\ndef find(x):\n if f[x] == x:\n return x\n root = find(f[x])\n f[x] = root\n return root\n\nfor i in range(m):\n a, b = map(int, input().split(' '))\n a -= 1\n b -= 1\n if find(a) != find(b):\n f[find(a)] = find(b)\n\nfor i in range(n):\n find(i)\n \nprint(max(collections.Counter(f).values()))\n"] | ['Runtime Error', 'Accepted'] | ['s242481920', 's844527971'] | [32228.0, 174528.0] | [765.0, 751.0] | [385, 435] |
p02573 | u732061897 | 2,000 | 1,048,576 | 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? | ['from collections import deque\n\nn, m = list(map(int, input().split()))\nedges = [list(map(int, input().split())) for _ in range(m)]\n\nneighbor = [[] for _ in range(n)]\nfor edge in edges:\n neighbor[edge[0] - 1].append(edge[1] - 1) \n neighbor[edge[1] - 1].append(edge[0] - 1)\n\nprint(neighbor)\nvisited = [-1] * n\nans = 1\nfor idx in range(n):\n if visited[idx] == -1:\n queue = deque()\n queue.append(idx)\n group_population = 1\n visited[idx] = 0\n while len(queue) > 0:\n vertex = queue.popleft()\n for nei in neighbor[vertex]:\n if visited[nei] == -1:\n visited[nei] = 0\n queue.append(nei)\n group_population += 1\n\n ans = max(ans, group_population)\n\nprint(ans)', 'N, M = map(int, input().split())\nt = [-1] * N\n\nimport sys\nsys.setrecursionlimit(10 ** 6)\ndef find(e):\n if t[e] < 0:\n return e\n else:\n t[e] = find(t[e])\n return t[e]\n\n\ndef unite(a, b):\n a_root = find(a)\n b_root = find(b)\n if a_root == b_root:\n return\n t[a_root] += t[b_root]\n t[b_root] = a_root\n\n\nfor i in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n unite(a, b)\n\n\ndef size(x):\n x = find(x)\n return -t[x]\n\n\nans = 0\nfor i in range(N):\n ans = max(ans, size(i))\nprint(ans)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s450797333', 's780360434'] | [85756.0, 36000.0] | [1012.0, 718.0] | [803, 556] |
p02573 | u740284863 | 2,000 | 1,048,576 | 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? | ['from collections import *\nn,m = map(int,input().split())\npar = [-1 for _ in range(n)]\n\ndef root(i):\n if par[i] < 0:\n return i\n else:\n return root(par[i])\n\ndef size(a):\n return -par[root(a)]\n\ndef union(a,b):\n a = root(a)\n b = root(b)\n if a == b:\n return False\n if size(a) < size(b):\n a,b = b,a\n par[a] += par[b]\n par[b] = a\n return True\n\nfor i in range(m):\n a = [int(j)-1 for j in input().split()]\n if root(a[0]) != root(a[1]):\n union(a[0],a[1])\npar = [ i for i in par if i > 0]\nprint(Counter(par).most_common()[0][1]+1)', 'from collections import *\nn,m = map(int,input().split())\npar = [-1 for _ in range(n)]\n\ndef root(i):\n if par[i] < 0:\n return i\n else:\n return root(par[i])\n\ndef size(a):\n return -par[root(a)]\n\ndef union(a,b):\n a = root(a)\n b = root(b)\n if a == b:\n return False\n if size(a) < size(b):\n a,b = b,a\n par[a] += par[b]\n par[b] = a\n return True\n\nfor i in range(m):\n a = [int(j)-1 for j in input().split()]\n if root(a[0]) != root(a[1]):\n union(a[0],a[1])\nprint(max([ size(i) for i in par]))'] | ['Runtime Error', 'Accepted'] | ['s114842605', 's806654260'] | [22000.0, 22640.0] | [749.0, 765.0] | [763, 724] |
p02573 | u748311048 | 2,000 | 1,048,576 | 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? | ["class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\nn,m=map(int, input().split())\nuf=UnionFind(n)\nfor _ in range(m):\n a,b=map(int, input().split())\n uf.union(a-1, b-1)\ncnt=0\n", "class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\nn,m=map(int, input().split())\nuf=UnionFind(n)\nfor _ in range(m):\n a,b=map(int, input().split())\n uf.union(a-1, b-1)\ncnt=0\nfor i in range(n):\n cnt=max(cnt, uf.size(i))\nprint(cnt)"] | ['Wrong Answer', 'Accepted'] | ['s579086587', 's010868711'] | [14400.0, 14476.0] | [576.0, 742.0] | [1275, 1333] |
p02573 | u760961723 | 2,000 | 1,048,576 | 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? | ["import sys\nimport math\nimport itertools\nimport collections\nfrom collections import deque\nfrom collections import defaultdict\n\nsys.setrecursionlimit(1000000)\nMOD = 10 ** 9 + 7\nMOD2 = 998244353\nINF = float('inf')\n#input = lambda: sys.stdin.readline().strip()\n\nNI = lambda: int(input())\nNMI = lambda: map(int, input().split())\nNLI = lambda: list(NMI())\nSI = lambda: input()\n\ndef main():\n \n N, M = NMI()\n AB = [NLI() for _ in range(M)]\n \n \n parents = [i for i in range(N+1)] \n \n \n def find_parent(x):\n if parents[x] == x:\n return parents[x]\n else:\n parents[x] = find_parent(parents[x])\n return parents[x]\n \n \n def unite_children(x,y):\n parent_x = find_parent(x)\n parent_y = find_parent(y)\n if parent_x == parent_y:\n return\n parents[x] = y\n\n \n \n for m in range(M):\n a = AB[m][0]\n b = AB[m][1]\n \n if a > b:\n a,b = b,a\n \n unite_children(a,b)\n\n \n for m in range(1,M+1):\n parents[m] = find_parent(m)\n\n del parents[0]\n pa = collections.Counter(parents)\n \n print(pa.most_common()[0][1])\n \n\n \n \n \nif __name__ == '__main__':\n main()", "import sys\nimport math\nimport itertools\nimport collections\nfrom collections import deque\nfrom collections import defaultdict\n \nsys.setrecursionlimit(1000000)\nMOD = 10 ** 9 + 7\nMOD2 = 998244353\nINF = float('inf')\ninput = lambda: sys.stdin.readline().strip()\n \nNI = lambda: int(input())\nNMI = lambda: map(int, input().split())\nNLI = lambda: list(NMI())\nSI = lambda: input()\n \nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n \n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n \n if x == y:\n return\n \n if self.parents[x] > self.parents[y]:\n x, y = y, x\n \n self.parents[x] += self.parents[y]\n self.parents[y] = x\n \n def size(self, x):\n return -self.parents[self.find(x)]\n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n \n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n \n def group_count(self):\n return len(self.roots())\n \n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n \n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n \ndef main():\n \n N, M = NMI()\n \n uf = UnionFind(N)\n \n for m in range(M):\n A,B = NMI()\n uf.union(A-1, B-1)\n \n ans = 0\n for n in range(N):\n ans = max(ans,uf.size(n))\n print(ans)\n \n \n\nif __name__ == '__main__':\n main()"] | ['Runtime Error', 'Accepted'] | ['s479698028', 's579533217'] | [254696.0, 14888.0] | [769.0, 568.0] | [1572, 1801] |
p02573 | u763550415 | 2,000 | 1,048,576 | 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? | ['def uf_find(x):\n z = x\n while z != p[z]:\n z = p[z]\n p[x] = z\n return z\n\ndef uf_unite(x,y):\n global rand\n x = uf_find(x)\n y = uf_find(y)\n if x != y:\n rand += 1\n if rand % 2 ==0:\n p[y] = x\n else:\n p[x] = y\n\nN, M = map(int, input().split())\np = list(range(N))\nrand = 0\n\nfor i in range(M):\n A, B = [int(j)-1 for j in input().split()]\n uf_unite(A,B)\n print(p)\n \nfor i in range(N):\n p[i] = uf_find(i)\nprint(p)\n\nq = [0]*N\nfor i in range(N):\n q[i] = p.count(i)\n \nprint(max(q))\n', 'import sys\nsys.setrecursionlimit(10**7)\n\ndef uf_find(x):\n if x == p[x]:\n return x\n else:\n p[x] = uf_find(p[x])\n return p[x]\n\ndef uf_unite(x,y):\n x = uf_find(x)\n y = uf_find(y)\n if x != y:\n if r[y]>r[x]:\n x,y = y,x\n if r[x]==r[y]:\n r[x]+= 1\n p[y] = x\n #print(r)\n\n\nN, M = map(int, input().split())\np = list(range(N))\nr = [0]*N\n\nfor i in range(M):\n A, B = [int(j)-1 for j in input().split()]\n uf_unite(A,B)\n print(p)\n \nfor i in range(N):\n p[i] = uf_find(i)\n\nq = [0]*N\nfor i in range(N):\n q[i] = p.count(i)\n \nprint(max(q))\n', 'def uf_find(x):\n while x != p[x]:\n x = p[x]\n print(x)\n return(x)\n\ndef uf_unite(x,y):\n x = uf_find(x)\n y = uf_find(y)\n if x == y:\n pass\n else:\n p[x] = y\n\nN, M = map(int, input().split())\np = list(range(N))\n\nfor i in range(M):\n A, B = [int(i)-1 for i in input().split()]\n uf_unite(A,B)\n #print(p)\n\nfor i in range(N):\n p[i] = uf_find(i)\nprint(p)\n\nq = [0]*N\nfor i in range(N):\n q[i] = p.count(i)\n \nprint(max(q))\n', 'def uf_find(x):\n if p[x] == -1:\n return x\n else:\n for i in range(5):\n x = p[x]\n if x == -1:\n return x\n return x\n\ndef uf_unite(x,y):\n x = uf_find(x)\n y = uf_find(y)\n if x == y and x != -1:\n pass\n else:\n p[x] = y\n\nN, M = map(int, input().split())\np = [-1]*N\n\nfor i in range(M):\n A, B = [int(i)-1 for i in input().split()]\n uf_unite(A,B)\n #print(p)\n\nfor i in range(N):\n p[i] = uf_find(i)\nprint(p)\n\nq = [0]*N\nfor i in range(N):\n q[i] = p.count(i)\n \nprint(max(q))\n ', 'N, M = map(int, input().split())\n\npar = list(range(N))\nrank = [1]*N\nsize = [1]*N\n\ndef find(x):\n if par[x] == x:\n return x\n else:\n return find(par[x])\n \ndef unite(x,y):\n x = find(x)\n y = find(y)\n \n if x == y:\n return\n if rank[x]<rank[y]:\n x,y = y,x\n else:\n par[y] = x\n size[x] += size[y]\n if rank[x]==rank[y]:\n rank[x]+=1\n \nfor i in range(M):\n a,b = [int(i)-1 for i in input().split()]\n unite(a,b)\n \nprint(max(size))', 'N, M = map(int, input().split())\n\npar = list(range(N))\nrank = [1]*N\nsize = [1]*N\n\ndef find(x):\n if par[x] == x:\n return x\n else:\n return find(par[x])\n \ndef unite(x,y):\n x = find(x)\n y = find(y)\n \n if x == y:\n return\n if rank[x]<rank[y]:\n x,y = y,x\n par[y] = x\n size[x] += size[y]\n if rank[x]==rank[y]:\n rank[x]+=1\n \nfor i in range(M):\n a,b = [int(i)-1 for i in input().split()]\n unite(a,b)\n \nprint(max(size))'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s438602924', 's631857125', 's740644796', 's781741503', 's957260762', 's478069442'] | [148516.0, 150064.0, 52768.0, 19680.0, 8992.0, 20024.0] | [2357.0, 2372.0, 2267.0, 2206.0, 28.0, 648.0] | [506, 562, 432, 505, 448, 440] |
p02573 | u794448346 | 2,000 | 1,048,576 | 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? | ['N,M = map(int,input().split())\nf = []\nfor i in range(M):\n A,B = map(int,input().split())\n a = {A,B}\n for i in f:\n if i & a != set():\n a = i | a\n f.remove(i)\n# print(f,a,i)\n f.append(a)\n\n#print(f)\nprint(len(max(f)))', 'N,M = map(int,input().split())\nf = [[] for i in range(N)]\nfor i in range(M):\n A,B = map(int,input().split())\n f[A-1].append(B-1)\n f[B-1].append(A-1)\nfrom collections import deque\nd = deque()\nx = [-1]*N\nfor i in range(N):\n if x[i] == -1:\n x[i] = i\n d.append(f[i])\n while len(d) > 0:\n z = d.popleft()\n for j in z:\n if x[j] == -1:\n x[j] = i\n d.append(f[j])\nimport collections\nans = collections.Counter(x)\nprint(ans.most_common()[0][1])'] | ['Runtime Error', 'Accepted'] | ['s582018629', 's391869220'] | [17652.0, 57376.0] | [2206.0, 781.0] | [266, 516] |
p02573 | u803865203 | 2,000 | 1,048,576 | 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? | ['from collections import Counter\n\nclass UnionFind:\n def __init__(self,num:int):\n self.r = [-1 for i in range(num)]\n def root(self,x:int):\n if(self.r[x] < 0):\n return x\n self.r[x] = self.root(self.r[x])\n return self.r[x]\n def unite(self,x:int,y:int):\n rx = self.root(x)\n ry = self.root(y)\n if(rx == ry):\n return False\n if(self.r[rx] > self.r[ry]):\n rx,ry = ry,rx\n self.r[rx] += self.r[ry]\n self.r[ry] = rx\n return True\n def size(self,x:int):\n return -self.r[self.root(x)]\n\nN,M = map(int,input().split())\ngroup = UnionFind(N)\nfor i in range(M):\n A,B = map(int,input().split())\n group.unite(A-1,B-1)\nans = 0\nfor i in range(N):\n ans = max(ans,group.size(i))\nprint(group.r)\nprint(ans)\n', 'from collections import Counter\n\nclass UnionFind:\n def __init__(self,num:int):\n self.r = [-1 for i in range(num)]\n def root(self,x:int):\n if(self.r[x] < 0):\n return x\n self.r[x] = self.root(self.r[x])\n return self.r[x]\n def unite(self,x:int,y:int):\n rx = self.root(x)\n ry = self.root(y)\n if(rx == ry):\n return False\n if(self.r[rx] > self.r[ry]):\n rx,ry = ry,rx\n self.r[rx] += self.r[ry]\n self.r[ry] = rx\n return True\n def size(self,x:int):\n return -self.r[self.root(x)]\n\nN,M = map(int,input().split())\ngroup = UnionFind(N)\nfor i in range(M):\n A,B = map(int,input().split())\n group.unite(A-1,B-1)\nans = 0\nfor i in range(N):\n ans = max(ans,group.size(i))\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s652213429', 's221903636'] | [17868.0, 15124.0] | [785.0, 758.0] | [817, 802] |
p02573 | u814986259 | 2,000 | 1,048,576 | 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? | ['import collections\n\n\nclass unionFind:\n parent = []\n\n def __init__(self, N):\n self.parent = [i for i in range(N)]\n\n def root(self, x):\n if self.parent[x] == x:\n return(x)\n else:\n self.parent[x] = self.root(self.parent[x])\n return(self.parent[x])\n\n def same(self, x, y):\n x, y = x-1, y-1\n return(self.root(x) == self.root(y))\n\n def unite(self, x, y):\n x, y = x-1, y-1\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n else:\n self.parent[x] = y\n return\n\n\nN, M = map(int, input().split())\nG = unionFind(N)\nfor i in range(M):\n a, b = map(int, input().split())\n G.unite(a, b)\n\nfor i in range(N):\n G.root(i)\n\nC = collections.Counter(G.parent).most_common()\n\nprint(1)\n# print(C[0][1])\n', 'import collections\n\n\nclass unionFind:\n parent = []\n\n def __init__(self, N):\n self.parent = [i for i in range(N)]\n\n def root(self, x):\n if self.parent[x] == x:\n return(x)\n else:\n self.parent[x] = self.root(self.parent[x])\n return(self.parent[x])\n\n def same(self, x, y):\n x, y = x-1, y-1\n return(self.root(x) == self.root(y))\n\n def unite(self, x, y):\n x, y = x-1, y-1\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n else:\n self.parent[x] = y\n return\n\n\nN, M = map(int, input().split())\nG = unionFind(N)\nfor i in range(M):\n a, b = map(int, input().split())\n G.unite(a, b)\nprint(1)\n\n\n# G.root(i)\n\n# C = collections.Counter(G.parent).most_common()\n\n# print(C[0][1])\n', 'import collections\n\n\nclass unionFind:\n parent = []\n\n def __init__(self, N):\n self.parent = [i for i in range(N)]\n\n def root(self, x):\n if self.parent[x] == x:\n return(x)\n else:\n self.parent[x] = self.root(self.parent[x])\n return(self.parent[x])\n\n def same(self, x, y):\n x, y = x-1, y-1\n return(self.root(x) == self.root(y))\n\n def unite(self, x, y):\n x, y = x-1, y-1\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n else:\n self.parent[x] = y\n return\n\n\nN, M = map(int, input().split())\nG = unionFind(N)\nfor i in range(M):\n a, b = map(int, input().split())\n G.unite(a, b)\n\nfor i in range(N):\n G.root(i)\nprint(1)\n# C = collections.Counter(G.parent).most_common()\n\n# print(C[0][1])\n', 'import collections\nimport sys\nsys.setrecursionlimit(10**6)\nN, M = map(int, input().split())\nAB = [tuple(map(int, input().split())) for i in range(M)]\n\n\nclass unionFind:\n parent = []\n\n def __init__(self, N):\n self.parent = [i for i in range(N)]\n\n def root(self, x):\n if self.parent[x] == x:\n return(x)\n else:\n self.parent[x] = self.root(self.parent[x])\n return(self.parent[x])\n\n def same(self, x, y):\n x, y = x-1, y-1\n return(self.root(x) == self.root(y))\n\n def unite(self, x, y):\n x, y = x-1, y-1\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n else:\n self.parent[x] = y\n return\n\n\nG = unionFind(N)\n\nfor a, b in AB:\n G.unite(a, b)\n\nfor i in range(N):\n G.root(i)\n\nC = collections.Counter(G.parent).most_common()\n\nprint(C[0][1])\n'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s123008981', 's296751625', 's934501686', 's844764610'] | [43076.0, 17276.0, 17936.0, 201860.0] | [855.0, 704.0, 842.0, 861.0] | [844, 850, 845, 892] |
p02573 | u818213347 | 2,000 | 1,048,576 | 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? | ['n,m = map(int,input().split())\nbranch = set(tuple(map(int,input().split())) for i in range(m))\nprint(branch)\nque = range(n)\nflag = -1\nfriend = [{0}]\n\nfor a,b in branch:\n for i in range(len(friend)):\n if (a in friend[i]) or (b in friend[i]):\n friend[i].add(a)\n friend[i].add(b)\n if flag >= 0:\n friend[flag] = friend[flag]|friend[i]\n friend.pop(i)\n break\n flag = i\n if flag == -1:\n friend.append({a,b})\n else: flag = -1\n print(friend)\n\nlen_friend = list(len(i) for i in friend)\nprint(max(len_friend))', 'n,m = map(int,input().split())\nbranch = set(tuple(map(int,input().split())) for i in range(m))\nprint(branch)\nque = range(n)\nflag = -1\nfriend = [{0}]\n\nfor a,b in branch:\n for i in range(len(friend)):\n if (a in friend[i]) or (b in friend[i]):\n friend[i].add(a)\n friend[i].add(b)\n if flag >= 0:\n friend[flag] = friend[flag]|friend[i]\n friend.pop(i)\n break\n flag = i\n if flag == -1:\n friend.append({a,b})\n else: flag = -1\n\nlen_friend = list(len(i) for i in friend)\nprint(max(len_friend))', 'n,m = map(int,input().split())\nbranch = list(tuple(map(int,input().split())) for i in range(m))\nque = range(n)\nflag = -1\nfriend = [{1}]\n\nfor a,b in branch:\n for i in range(len(friend)):\n if (a in friend[i]) or (b in friend[i]):\n friend[i].add(a)\n friend[i].add(b)\n if flag >= 0:\n friend[flag] = friend[flag]|friend[i]\n friend.pop(i)\n flag = i\n if flag == -1:\n friend.append({a,b})\n else: flag = -1\n\nprint(friend)\nlen_friend = list(len(i) for i in friend)\nprint(max(len_friend))', 'sys.setrecursionlimit(10000)\n\nclass Graph:\n def __init__(self,n,side):\n self.side = side\n self.neighbor = [set() for i in range(n+1)]\n self.visited = [False]*(n+1)\n self.group =[0]*n\n self.product()\n def product(self):\n for a,b in self.side:\n self.neighbor[a].add(b)\n self.neighbor[b].add(a)\n def dfs(self,x,a):\n self.group[a] += 1\n self.visited[x] = True\n for i in self.neighbor[x]:\n if self.visited[i]:continue\n self.dfs(i,a)\n def all_dfs(self):\n a = 0\n for i in range(1,n+1):\n if not self.visited[i]:\n self.dfs(i,a)\n a += 1\n\nn,m = map(int,input().split())\nside = list(tuple(map(int,input().split()))for i in range(m))\ngraph1 = Graph(n,side)\ngraph1.all_dfs()\nprint((graph1.group))', 'import sys\nsys.setrecursionlimit(10000000)\n\nclass Graph:\n def __init__(self,n,side):\n self.side = side\n self.neighbor = [set() for i in range(n+1)]\n self.visited = [False]*(n+1)\n self.group =[0]*n\n self.product()\n def product(self):\n for a,b in self.side:\n self.neighbor[a].add(b)\n self.neighbor[b].add(a)\n def dfs(self,x,a):\n self.group[a] += 1\n self.visited[x] = True\n for i in self.neighbor[x]:\n if self.visited[i]:continue\n self.dfs(i,a)\n def all_dfs(self):\n a = 0\n for i in range(1,n+1):\n if not self.visited[i]:\n self.dfs(i,a)\n a += 1\n\nn,m = map(int,input().split())\nside = list(tuple(map(int,input().split()))for i in range(m))\ngraph1 = Graph(n,side)\ngraph1.all_dfs()\nprint(max(graph1.group))\n'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s129495785', 's245785264', 's754837337', 's767443318', 's386135089'] | [174144.0, 50788.0, 59748.0, 9092.0, 266172.0] | [2370.0, 2210.0, 2058.0, 26.0, 1113.0] | [613, 595, 574, 856, 874] |
p02573 | u850390157 | 2,000 | 1,048,576 | 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? | ['from collections import defaultdict\n\nN, M = map(int, input().split())\nfriend = defaultdict(set)\nleader = []\nfor i in range(M):\n Ai, Bi = map(int, input().split())\n friend[Ai].add(Bi)\n friend[Bi].add(Ai)\nprint(friend)\nalready = {}\nanswer = 0\nfor i in range(1, N + 1):\n if i in already:\n continue\n if i not in friend:\n continue\n\n queue = []\n for f in friend[i]:\n already[f] = True\n queue.append(f)\n already[i] = True\n size = 0\n while len(queue) > size:\n item = queue[size]\n size += 1\n if item in friend:\n for f in friend[item]:\n if f not in already:\n already[f] = True\n queue.append(f)\n if size > answer:\n answer = size\nprint(answer + 1)', 'from collections import defaultdict\n\nN, M = map(int, input().split())\nfriend = defaultdict(set)\nleader = []\nfor i in range(M):\n Ai, Bi = map(int, input().split())\n friend[Ai].add(Bi)\n friend[Bi].add(Ai)\nalready = {}\nanswer = 0\nfor i in range(1, N + 1):\n if i in already:\n continue\n if i not in friend:\n continue\n\n queue = []\n for f in friend[i]:\n already[f] = True\n queue.append(f)\n already[i] = True\n size = 0\n while len(queue) > size:\n item = queue[size]\n size += 1\n if item in friend:\n for f in friend[item]:\n if f not in already:\n already[f] = True\n queue.append(f)\n if size > answer:\n answer = size\nprint(answer + 1)'] | ['Wrong Answer', 'Accepted'] | ['s652360776', 's766182206'] | [100424.0, 100492.0] | [1146.0, 1018.0] | [788, 774] |
p02573 | u866949333 | 2,000 | 1,048,576 | 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? | ["from collections import defaultdict\nfrom collections import deque\n\n\ndef main():\n N, M = map(int, input().split())\n A = [0] * M\n B = [0] * M\n\n for i in range(M):\n a, b = map(int, input().split())\n A[i] = a - 1\n B[i] = b - 1\n\n friends = defaultdict(set)\n\n for i in range(M):\n a, b = A[i], B[i]\n friends[a].add(b)\n friends[b].add(a)\n\n seen = [False] * N\n\n print(friends)\n\n def dfs(start):\n cnt = 0\n nodes = []\n\n todo = deque([start])\n while len(todo) > 0:\n v = todo.pop()\n cnt += 1\n nodes.append(v)\n\n for next_v in friends[v]:\n if seen[next_v]:\n continue\n else:\n todo.append(next_v)\n seen[next_v] = True\n\n return cnt, nodes\n\n trees = []\n counts = []\n for v in range(N):\n if seen[v]:\n continue\n else:\n seen[v] = True\n c, nodes = dfs(v)\n counts.append(c)\n trees.append(nodes)\n\n # print(counts)\n # print(trees)\n print(max(counts))\n\n\nif __name__ == '__main__':\n main()\n", "from collections import defaultdict\nfrom collections import deque\n\n\ndef main():\n N, M = map(int, input().split())\n A = [0] * M\n B = [0] * M\n\n for i in range(M):\n a, b = map(int, input().split())\n A[i] = a - 1\n B[i] = b - 1\n\n friends = defaultdict(set)\n\n for i in range(M):\n a, b = A[i], B[i]\n friends[a].add(b)\n friends[b].add(a)\n\n seen = [False] * N\n\n # print(friends)\n\n def dfs(start):\n cnt = 0\n nodes = []\n\n todo = deque([start])\n while len(todo) > 0:\n v = todo.pop()\n cnt += 1\n nodes.append(v)\n\n for next_v in friends[v]:\n if seen[next_v]:\n continue\n else:\n todo.append(next_v)\n seen[next_v] = True\n\n return cnt, nodes\n\n trees = []\n counts = []\n for v in range(N):\n if seen[v]:\n continue\n else:\n seen[v] = True\n c, nodes = dfs(v)\n counts.append(c)\n trees.append(nodes)\n\n # print(counts)\n # print(trees)\n print(max(counts))\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s803378113', 's359596510'] | [95880.0, 95868.0] | [1011.0, 901.0] | [1187, 1189] |
p02573 | u868055170 | 2,000 | 1,048,576 | 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? | ['class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n\nN, M=map(int,input().split())\nUF=UnionFind(N)\n\nfor _ in range(M):\n A,B=map(int,input().split())\n UF.union(A,B)\n\nans=0\n\nfor i in range(N):\n ans = max(ans, UF.size(i))\n\xa0\n print(ans)', 'class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n\nN, M=map(int,input().split())\nUF=UnionFind(N)\n\nfor _ in range(M):\n A,B=map(int,input().split())\n UF.union(A-1,B-1)\n\nans=0\n\nfor i in range(N):\n ans = max(ans, UF.size(i));\n\xa0\n print(ans)\n\n\n\n', 'class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n\nN, M=map(int,input().split())\nUF=UnionFind(N)\n\nfor _ in range(M):\n A,B=map(int,input().split())\n UF.union(A,B)\n\nans=0\n\nfor i in range(N):\n ans = max(ans, UF.size(i));\n\xa0\n print(ans)', 'class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n\nN, M=map(int,input().split())\nUF=UnionFind(N)\n\nfor _ in range(M):\n A,B=map(int,input().split())\n UF.union(A-1,B-1)\n\nans=0\n\nfor i in range(N):\n ans = max(ans, UF.size(i))\n\xa0\n print(ans)', 'class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n\nN, M = map(int, input().split())\nUF = UnionFind(N)\n\nfor _ in range(M):\n A, B = map(int, input().split())\n UF.union(A - 1, B - 1)\n\nans = 0\n\nfor i in range(N):\n ans = max(ans, UF.size(i))\n\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s007482431', 's488278900', 's528146112', 's850262727', 's974066977'] | [9048.0, 9064.0, 8928.0, 8944.0, 14348.0] | [27.0, 25.0, 27.0, 26.0, 756.0] | [615, 624, 610, 619, 816] |
p02573 | u872538555 | 2,000 | 1,048,576 | 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? | ['from collections import Counter\n\nclass UnionFind():\n def __init__(self, n):\n self.par = [i for i in range(n + 1)]\n self.rank = [0] * n\n \n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n \n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n else:\n self.par[y] = x\n \n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n \n\nN, M = map(int, input().split())\nUF = UnionFind(N)\nfor i in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n big = max(a, b)\n small = min(a, b)\n \n if UF.par[big] == big:\n UF.par[big] = small\n else:\n UF.union(big, small)\n \nfor i in range(N):\n _ = UF.find(i)\n\nprint(UF.par)\n\nc = Counter(UF.par)\nprint(max(c.values()))', 'from collections import Counter\n\nclass UnionFind():\n def __init__(self, n):\n self.par = [i for i in range(n)]\n self.rank = [0] * n\n \n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n \n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n else:\n self.par[y] = x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n \nn, m = map(int, input().split())\nuf = UnionFind(n)\nfor i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n uf.union(a, b)\n\nfor i in range(n):\n uf.find(i)\n\nc = Counter(uf.par)\nprint(max(c.values()))'] | ['Runtime Error', 'Accepted'] | ['s217486753', 's739735306'] | [36248.0, 33736.0] | [858.0, 820.0] | [1018, 843] |
p02573 | u875769753 | 2,000 | 1,048,576 | 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? | ['N,M = map(int,input().split())\nlsa = [{i} for i in range(N+1)]\nfor i in range(M):\n a,b = map(int,input().split())\n lsa[a] = lsa[a] | lsa[b]\n lsa[b] = lsa[a] | lsa[b]\nans = 0\nfor i in range(N+1):\n ans = max(ans,len(lsa[i]))\nprint(lsa)\nprint(ans)', 'from collections import deque\n\nn, m = map(int, input().split())\n\ngraph = [[] for _ in range(n+1)]\n\nfor i in range(m):\n a, b = map(int, input().split())\n graph[a].append(b)\n graph[b].append(a)\n\nlsloop = []\nused = [False for i in range(n+1)]\n\nfor j in range(1,n+1):\n if used[j]:\n continue \n ii = 1\n d = deque()\n d.append(j)\n used[j] = True\n while d:\n v = d.popleft()\n for i in graph[v]:\n if used[i]:\n continue\n ii += 1\n d.append(i)\n used[i] = True\n lsloop.append(ii)\nprint(max(lsloop))'] | ['Wrong Answer', 'Accepted'] | ['s569114137', 's540254947'] | [2865416.0, 45004.0] | [2295.0, 712.0] | [256, 600] |
p02573 | u894521144 | 2,000 | 1,048,576 | 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? | ["from collections import Counter\n\ndef main(N, M, C):\n lst = [n for n in range(N)]\n\n def get_root(x):\n if lst[x] == x:\n return x\n else:\n lst[x] = get_root(lst[x])\n return lst[x]\n\n def is_same(x, y):\n return get_root(x) == get_root(y)\n\n def unite(x, y):\n lst[x] = get_root(y)\n\n get_index = lambda x, y:(x-1, y-1)\n\n for c in C:\n indexes = get_index(*c)\n if not is_same(*indexes):\n unite(*indexes)\n print(max(Counter(lst).values()))\n\n\nif __name__ == '__main__':\n N, M = list(map(int, input().split()))\n C = set()\n for _ in range(M):\n C.add(tuple(map(int, input().split())))\n main(N, M, C)", "from collections import Counter\n\n\n\nimport sys\nsys.setrecursionlimit(10 ** 9)\n\nlst = [n for n in range(N)] \n\ndef get_root(x): \n if lst[x] == x: \n return x\n else: \n lst[x] = get_root(lst[x]) \n return lst[x]\n \n\ndef unite(x, y): \n root_x = get_root(x)\n root_y = get_root(y)\n if root_x != root_y: \n lst[root_x] = root_y\n\ndef main(N, M, C):\n {unite(*c) for c in C} \n print(max(Counter(map(get_root, lst)).values())) \n\n\nif __name__ == '__main__':\n N, M = list(map(int, input().split()))\n C = set()\n for _ in range(M):\n C.add(tuple(map(lambda x:int(x)-1, input().split()))) \n main(N, M, C)\n", "from collections import Counter\n\n\n\nimport sys\nsys.setrecursionlimit(10 ** 9)\n\ndef main(N, M, C):\n lst = [n for n in range(N)] \n\n def get_root(x): \n if lst[x] == x: \n return x\n else: \n lst[x] = get_root(lst[x]) \n return lst[x]\n \n\n def unite(x, y): \n root_x = get_root(x)\n root_y = get_root(y)\n if root_x != root_y: \n lst[root_x] = root_y\n \n {unite(*c) for c in C} \n print(max(Counter(map(get_root, lst)).values())) \n\n\nif __name__ == '__main__':\n N, M = list(map(int, input().split()))\n C = set()\n for _ in range(M):\n C.add(tuple(map(lambda x:int(x)-1, input().split()))) \n main(N, M, C)"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s211745499', 's772519999', 's592918919'] | [59528.0, 9412.0, 52524.0] | [762.0, 32.0, 855.0] | [709, 1401, 1464] |
p02573 | u896726004 | 2,000 | 1,048,576 | 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? | ["class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n \n \n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n \n if x == y:\n return\n \n if self.parents[x] > self.parents[y]:\n x, y = y, x\n \n self.parents[x] += self.parents[y]\n self.parents[y] = x\n \n \n def size(self, x):\n return -self.parents[self.find(x)]\n \n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n \n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n \n \n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n \n def group_count(self):\n return len(self.roots())\n \n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n \n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\n\nN, M = map(int, input().split())\n\nunion = UnionFind(N)\n\nfor _ in range(M):\n a, b = map(int, input().split())\n union.union(a-1, b-1)\n\nans = 0\n\nfor i in range(N):\n ans = max(union.size(i))\n\nprint(ans)", "class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n \n \n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n \n if x == y:\n return\n \n if self.parents[x] > self.parents[y]:\n x, y = y, x\n \n self.parents[x] += self.parents[y]\n self.parents[y] = x\n \n \n def size(self, x):\n return -self.parents[self.find(x)]\n \n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n \n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n \n \n \n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n \n \n def group_count(self):\n return len(self.roots())\n \n \n # exp. {0: [0, 1, 4], 2: [2, 3]}\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n \n \n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\n\nN, M = map(int, input().split())\n\nunion = UnionFind(N)\n\nfor _ in range(M):\n a, b = map(int, input().split())\n union.union(a-1, b-1)\n\nans = 0\nfor i in range(N):\n ans = max(ans, union.size(i))\n\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s370034908', 's991983290'] | [14564.0, 14588.0] | [589.0, 749.0] | [1635, 1859] |
p02573 | u906501980 | 2,000 | 1,048,576 | 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? | ['from numba import njit\n\n\nclass UnionFind:\n __slots__ = ["data"]\n \n def __init__(self, n=0):\n self.data = [-1]*(n+1)\n \n def root(self, x):\n if self.data[x] < 0:\n return x\n self.data[x] = self.root(self.data[x])\n return self.data[x]\n \n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x != y:\n if self.data[x] < self.data[y]:\n self.data[x] += self.data[y]\n self.data[y] = x\n else:\n self.data[y] += self.data[x]\n self.data[x] = y\n \n def same(self, x, y):\n return self.root(x) == self.root(y)\n \n def size(self, x):\n return -self.data[self.root(x)]\n\n@njit\ndef main():\n n, m = map(int, input().split())\n uf = UnionFind(n)\n for i in range(m):\n a, b = map(int, input().split())\n uf.unite(a, b)\n \n ans = 0\n \n for i in range(1, n+1):\n ans = max(ans, uf.size(i))\n \n print(ans)\n \n\n\nmain()\n', 'class UnionFind:\n __slots__ = ["data"]\n \n def __init__(self, n=0):\n self.data = [-1]*(n+1)\n \n def root(self, x):\n if self.data[x] < 0:\n return x\n self.data[x] = self.root(self.data[x])\n return self.data[x]\n \n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x != y:\n if self.data[x] < self.data[y]:\n self.data[x] += self.data[y]\n self.data[y] = x\n else:\n self.data[y] += self.data[x]\n self.data[x] = y\n \n def same(self, x, y):\n return self.root(x) == self.root(y)\n \n def size(self, x):\n return -self.data[self.root(x)]\n\n\ndef main():\n n, m = map(int, input().split())\n uf = UnionFind(n)\n for i in range(m):\n a, b = map(int, input().split())\n uf.unite(a, b)\n \n ans = 0\n \n for i in range(1, n+1):\n ans = max(ans, uf.size(i))\n \n print(ans)\n \n\nif __name__ == "__main__":\n main()'] | ['Runtime Error', 'Accepted'] | ['s345067006', 's373059729'] | [106508.0, 13612.0] | [476.0, 709.0] | [1043, 1038] |
p02573 | u909224749 | 2,000 | 1,048,576 | 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? | ['class UnionFindTree():\n def __init__(self, num_leaves):\n #self.num_leaves = num_leaves\n self.root = [i for i in range(num_leaves+1)]\n \n def find(self, leaf):\n if self.root[leaf] == leaf:\n return self.root[leaf]\n else:\n self.root[leaf] = self.find(self.root[leaf])\n return self.root[leaf]\n \n def union(self, leaf_a, leaf_b):\n \t# find roots\n root_a = self.find(leaf_a)\n root_b = self.find(leaf_b)\n if root_a != root_b:\n # then union roots\n self.root[leaf_b] = root_a\n \n \nN, M = map(int, input().split())\nuft = UnionFindTree(N)\nfor m in range(M):\n a, b = map(int, input().split())\n uft.union(a, b)\n \nmax_size = max([[uft.find(n) for n in range(N)].count(n) for n in range(N+1)])\nprint(max_size)', 'class UnionFindTree():\n def __init__(self, num_leaves):\n #self.num_leaves = num_leaves\n self.root = [i for i in range(num_leaves+1)]\n \n def find(self, leaf):\n if self.root[leaf] == leaf:\n return self.root[leaf]\n else:\n self.root[leaf] = self.find(self.root[leaf])\n return self.root[leaf]\n \n def union(self, leaf_a, leaf_b):\n \t# find roots\n root_a = self.find(leaf_a)\n root_b = self.find(leaf_b)\n if root_a != root_b:\n # then union roots\n self.root[leaf_b] = root_a\n \n \nN, M = map(int, input().split())\nuft = UnionFindTree(N)\nfor m in range(M):\n a, b = map(int, input().split())\n uft.union(a, b)\n \n\nfor n in range(N):\n uft.find(n)\n \nnum_group = len(set(uft.root))-1\nprint(num_group)', 'class UnionFindTree():\n def __init__(self, num_leaves):\n #self.num_leaves = num_leaves\n self.root = [i for i in range(num_leaves+1)]\n \n def find(self, leaf):\n if self.root[leaf] == leaf:\n return self.root[leaf]\n else:\n self.root[leaf] = self.find(self.root[leaf])\n return self.root[leaf]\n \n def union(self, leaf_a, leaf_b):\n \t# find roots\n root_a = self.find(leaf_a)\n root_b = self.find(leaf_b)\n if root_a != root_b:\n # then union roots\n self.root[leaf_b] = root_a\n \n \nN, M = map(int, input().split())\nuft = UnionFindTree(N)\nfor m in range(M):\n a, b = map(int, input().split())\n uft.union(a, b)\n \n\nfor n in range(N):\n uft.find(n)\n \nmax_size = [uft.root.count(n) for n in range(N)].max()\nprint(num_group)', 'class UnionFindTree():\n def __init__(self, n):\n self.parents = [-1] * n\n \n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n \n if x == y:\n return\n \n \n if self.parents[x] > self.parents[y]:\n x, y = y, x\n \n \n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\ndef main():\n N, M = map(int, input().split())\n uft = UnionFindTree(N)\n \n for m in range(M):\n a, b = map(lambda x: int(x)-1, input().split())\n uft.union(a, b)\n \n print(-min(uft.parents))\n \n \n \nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s360861592', 's558774999', 's938141707', 's193454352'] | [18412.0, 29228.0, 17068.0, 14352.0] | [2206.0, 661.0, 2206.0, 588.0] | [844, 850, 872, 921] |
p02573 | u938005055 | 2,000 | 1,048,576 | 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? | ['class UnionFind:\n def __init__(self, length):\n self.r = [-1] * length\n\n def root(self, x):\n if (self.r[x]) < 0:\n return x\n\n return self.r[x] - self.root(self.r[x])\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n\n if x == y:\n return False\n r = self.r\n\n if r[x] > r[y]:\n x, y = y, x\n\n r[x] += r[y]\n r[y] = x\n\n return True\n\n def size(self, x):\n return -self.r[self.root(x)]\n\n\nN, M = map(int, input().split())\n\n\nrelateions = UnionFind(N)\nfor _ in range(M):\n A, B = map(int, input().split())\n relateions.unite(A, B)\n\nmax_ = -1\nfor i in range(N):\n max_ = max(relateions.size(i), max_)\n\nprint(max_)\n', 'class UnionFind:\n def __init__(self, length):\n self.r = [-1] * length\n\n def root(self, x):\n rx = self.r[x]\n if (rx) < 0:\n return x\n\n return self.root(rx)\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n\n if x == y:\n return False\n r = self.r\n\n if r[x] > r[y]:\n x, y = y, x\n\n r[x] += r[y]\n r[y] = x\n\n return True\n\n def size(self, x):\n return -self.r[self.root(x)]\n\n def debug(self):\n print(self.r)\n\n\nN, M = map(int, input().split())\n\n\nrelations = UnionFind(N)\nfor _ in range(M):\n A, B = map(int, input().split())\n relations.unite(A-1, B-1)\n\nmax_ = -1\nfor i in range(N):\n max_ = max(relations.size(i), max_)\n\nprint(max_)\n'] | ['Runtime Error', 'Accepted'] | ['s322977872', 's543695459'] | [14516.0, 14308.0] | [500.0, 707.0] | [744, 786] |
p02573 | u941438707 | 2,000 | 1,048,576 | 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? | ['(n,m),*e=[[*map(int,i.split())]for i in open(0)]\nd=[[]for i in range(n+1)]\ndd=[[]for i in range(n+1)]\nfor i,j in e:\n d[i]+=[j]\n d[j]+=[i]\nfor i in range(n+1):\n for j in set(d[i]):\n dd[i]+=d[j]\nprint(max(len(set(dd[i]))for i in range(n+1)))', 'def find(x):\n if par[x]==x:\n return x\n else:\n par[x]=find(par[x])\n return par[x]\ndef unite(x,y):\n x=find(x)\n y=find(y)\n if x == y:\n return 0\n if x<y:x,y=y,x \n par[x]=y\nn,m=map(int,input().split())\npar=[i for i in range(n+1)]\nfor _ in range(m):\n i,j=map(int,input().split())\n unite(i,j)\nans=[0]*(n+1)\nfor i in range(n+1):\n find(i)\nfor i in par:\n ans[i]+=1\nprint(max(ans))'] | ['Wrong Answer', 'Accepted'] | ['s717378149', 's541165210'] | [2353160.0, 18504.0] | [2279.0, 615.0] | [255, 434] |
p02573 | u962330718 | 2,000 | 1,048,576 | 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? | ['N,M=map(int,input().split())\n\nP=[[0,0,0]]\nfor i in range(1,N+1):\n P.append([i,i,1])\n\nR=[]\nfor i in range(M):\n a,b=map(int,input().split())\n c=max(a,b)\n a=min(a,b)\n b=c\n R.append((a,b))\n\nR=sorted(list(set(R)))\n\nfor i in range(len(R)):\n \n x=0\n \n y=0\n \n cnt=0\n a=R[i][0]\n b=R[i][1]\n \n u=P[P[a][1]][1]\n v=P[P[b][1]][1]\n \n P[a][1]=u\n P[b][1]=v\n if P[a][1]==P[b][1]:\n continue\n else:\n x=min(P[a][1],P[b][1])\n y=max(P[a][1],P[b][1])\n \n \n if u!=x:\n P[u][1]=x\n if v!=x:\n P[v][1]=x\n\n cnt=P[y][2]\n P[a][1]=x\n P[b][1]=x\n P[x][2]+=cnt\n\n\nans=0\nfor i in range(1,N+1):\n x=P[i][1]\n P[i][2]=P[x][2]\n\nfor i in range(1,N+1):\n ans=max(ans,P[i][2])\n\nprint(R)\nprint(P)\nprint(ans)', 'def find(x):\n if parent[x]<0:\n return x\n else:\n parent[x]=find(parent[x])\n return parent[x]\n\ndef same(x,y):\n return find(x)==find(y)\n\ndef union(x,y):\n root_x=find(x)\n root_y=find(y)\n if root_x==root_y:\n return\n if parent[root_x]>parent[root_y]:\n root_x,root_y=root_y,root_x\n parent[root_x]+=parent[root_y]\n parent[root_y]=root_x\n\ndef members(n,x):\n root=find(x)\n return [i for i in range(n) if find(i)==root]\n\ndef get_size(x):\n return -parent[find(x)]\n\ndef get_root():\n return [i for i, root in enumerate(parent) if root<0]\n\nN,M=map(int,input().split())\nparent=[-1 for i in range(N)]\nfor i in range(M):\n a,b=map(int,input().split())\n a=a-1\n b=b-1\n union(a,b)\n\nans=0\nfor i in range(N):\n ans=max(ans,get_size(i))\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s325302598', 's986212759'] | [75864.0, 14832.0] | [1505.0, 679.0] | [1031, 810] |
p02573 | u964904181 | 2,000 | 1,048,576 | 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? | ['from copy import deepcopy\n\nn, m = map(int, input().split())\n\npairs = [0] * m\nfor i in range(m):\n pairs[i] = list(map(int, input().split()))\n\n\n# N = 5\n\n\nprint(pairs)\n\nclass UnionFind:\n def __init__(self, N):\n self.r = [-1] * N\n\n def root(self, x):\n if self.r[x] < 0:\n return x\n self.r[x] = self.root(self.r[x])\n return self.r[x]\n\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.r[x] > self.r[y]:\n x, y = y, x\n\n self.r[x] += self.r[y]\n self.r[y] = x\n return True\n\n def size(self, x):\n return -self.r[self.root(x)]\n\nuf = UnionFind(N)\nfor pair in pairs:\n a = pair[0] - 1\n b = pair[1] - 1\n uf.unite(a, b)\n\nans = 0\nfor i in range(N):\n ans = max(ans, uf.size(i))\n\nprint(ans)\n', 'from copy import deepcopy\n\nN, M = map(int, input().split())\n\npairs = [0] * M\nfor i in range(M):\n pairs[i] = list(map(int, input().split()))\n\n\n# N = 5\n\n\nprint(pairs)\n\nclass UnionFind:\n def __init__(self, N):\n self.r = [-1] * N\n\n def root(self, x):\n if self.r[x] < 0:\n return x\n self.r[x] = self.root(self.r[x])\n return self.r[x]\n\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.r[x] > self.r[y]:\n x, y = y, x\n\n self.r[x] += self.r[y]\n self.r[y] = x\n return True\n\n def size(self, x):\n return -self.r[self.root(x)]\n\nuf = UnionFind(N)\nfor pair in pairs:\n a = pair[0] - 1\n b = pair[1] - 1\n uf.unite(a, b)\n\nans = 0\nfor i in range(N):\n ans = max(ans, uf.size(i))\n\nprint(ans)\n', 'from copy import deepcopy\n\n# n, m = map(int, input().split())\n# \n\n\n\n\n\nN = 5\npairs = [[1,2], [3,4], [5,1]]\n\nprint(pairs)\n\nclass UnionFind:\n def __init__(self, N):\n self.r = [-1] * N\n\n def root(self, x):\n if self.r[x] < 0:\n return x\n self.r[x] = self.root(self.r[x])\n return self.r[x]\n\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.r[x] > self.r[y]:\n x, y = y, x\n\n self.r[x] += self.r[y]\n self.r[y] = x\n return True\n\n def size(self, x):\n return -self.r[self.root(x)]\n\nuf = UnionFind(N)\nfor pair in pairs:\n a = pair[0] - 1\n b = pair[1] - 1\n uf.unite(a, b)\n\nans = 0\nfor i in range(N):\n ans = max(ans, uf.size(i))\n\nprint(ans)\n', 'from copy import deepcopy\n\nN, M = map(int, input().split())\n\npairs = [0] * M\nfor i in range(M):\n pairs[i] = list(map(int, input().split()))\n\n\n# N = 5\n\n\n\nclass UnionFind:\n def __init__(self, N):\n self.r = [-1] * N\n\n def root(self, x):\n if self.r[x] < 0:\n return x\n self.r[x] = self.root(self.r[x])\n return self.r[x]\n\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.r[x] > self.r[y]:\n x, y = y, x\n\n self.r[x] += self.r[y]\n self.r[y] = x\n return True\n\n def size(self, x):\n return -self.r[self.root(x)]\n\nuf = UnionFind(N)\nfor pair in pairs:\n a = pair[0] - 1\n b = pair[1] - 1\n uf.unite(a, b)\n\nans = 0\nfor i in range(N):\n ans = max(ans, uf.size(i))\n\nprint(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s361596743', 's405062382', 's967867970', 's281154629'] | [52168.0, 52116.0, 9272.0, 50156.0] | [524.0, 939.0, 34.0, 855.0] | [891, 891, 896, 878] |
p02573 | u968404618 | 2,000 | 1,048,576 | 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? | ['# Union find\n\n# https://www.youtube.com/watch?time_continue=916&v=zxor0DdwoXA&feature=emb_logo\n# https://www.slideshare.net/chokudai/union-find-49066733\n\nimport sys\nsys.setrecursionlimit(10 ** 9)\n\nn, m = map(int, input().split())\nAB = [list(map(int, input().split())) for _ in range(m)]\n\nroot = [-1]*n\n\ndef find(x):\n if root[x] < 0:\n return x\n else:\n root[x] = find(root[x])\n return root[x]\n\ndef unite(x, y):\n gx = find(x)\n gy = find(y)\n \n if gx == gy:\n return\n \n if root[gx] > root[gy]:\n gx, gy = gy, gx\n \n root[gx] += root[gy]\n root[gy] = gx\n print(root)\n\ndef size(x):\n x = find(x)\n return -root[x]\n\nfor a, b in AB:\n a -= 1\n b -= 1\n unite(a, b)\n\nans = 0\nfor i in range(n):\n ans = max(ans, size(i))\nprint(ans)', 'import sys\nsys.setrecursionlimit(10**9)\n\nn, m = map(int, input().split())\nAB = [list(map(int, input().split())) for _ in range(m)]\n\nroot = [-1] * n\n\ndef find(x):\n if root[x] < 0:\n return x\n else:\n return find(root[x])\n\ndef unity(x, y):\n gx = find(x)\n gy = find(y)\n\n if gx == gy:\n return\n\n if root[gx] > root[gy]:\n gx, gy = gy, gx\n\n root[gx] += root[gy]\n root[gy] = gx\n\nfor a, b in AB:\n a -= 1\n b -= 1\n unity(a, b)\n\nprint(-min(root))'] | ['Runtime Error', 'Accepted'] | ['s884987492', 's947232689'] | [184292.0, 49884.0] | [2385.0, 631.0] | [864, 493] |
p02573 | u970082363 | 2,000 | 1,048,576 | 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? | ['n,m = (int(x) for x in input().split())\nfriendlist = [0]*n\nclasses = 1\nfor i in range(m):\n a,b = (int(x)-1 for x in input().split())\n if friendlist[a]!=0:\n friendlist[b] = friendlist[a]\n elif friendlist[b]!=0:\n friendlist[a] = friendlist[b]\n else:\n friendlist[a] = classes\n friendlist[b] = classes\n classes += 1\n\ncount = [0]*classes\nfor i in range(n):\n count[friendlist[i]] += 1\n\nprint(count)\nprint(max(count[1:]))\n', 'import os\n\nn,m = (int(x) for x in input().split())\n\n#Union Find\n\n\ndef find(x):\n if par[x] < 0:\n return x\n else:\n par[x] = find(par[x])\n return par[x]\n\ndef unite(x,y):\n x = find(x)\n y = find(y)\n\n if x == y:\n return False\n else:\n \n if par[x] > par[y]:\n x,y = y,x\n par[x] += par[y]\n par[y] = x\n return True\n\n\ndef same(x,y):\n return find(x) == find(y)\n\n\ndef size(x):\n return -par[find(x)]\n\n\n\npar = [-1]*n\n\nfor i in range(m):\n a,b = (int(x)-1 for x in input().split())\n unite(a,b)\n\nans = 0\nfor i in range(0,n):\n ans = max([ans,size(i)])\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s688425875', 's774184503'] | [12608.0, 14756.0] | [507.0, 685.0] | [465, 852] |
p02573 | u970267139 | 2,000 | 1,048,576 | 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? | ['class UnionFind():\n def __init__(self, n):\n self.par = [-1]*n\n\n def root(self, x):\n if self.par[x] < 0:\n return x\n return self.root(self.par[x])\n\n def unite(self, x, y):\n if x > y:\n x, y = y, x\n rx = self.root(x)\n ry = self.root(y)\n if rx != ry:\n self.par[rx] += self.par[ry]\n self.par[ry] = rx\n\n def size(self, x):\n return -self.par[self.root(x)]\n\n def same(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n return rx == ry\n\n def return_par(self):\n return self.par\n\nn, m = map(int, input().split())\nuf = UnionFind(n)\nfor i in m:\n a, b = map(int, input().split())\n uf.unite(a-1, b-1)\n\nans = 0\nfor i in range(n):\n ans = max(ans, uf.size(i))\nprint(ans)\n', 'import sys\nsys.setrecursionlimit(10**8)\n\nclass UnionFind():\n def __init__(self, n):\n self.par = [-1]*n\n\n def find(self, x):\n if self.par[x] < 0:\n return x\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def union(self, x, y):\n if x > y:\n x, y = y, x\n rx = self.find(x)\n ry = self.find(y)\n if rx != ry:\n self.par[rx] += self.par[ry]\n self.par[ry] = rx\n\n def size(self, x):\n return -self.par[self.find(x)]\n\n def same(self, x, y):\n rx = self.find(x)\n ry = self.find(y)\n return rx == ry\n\n def return_par(self):\n return self.par\n\nn, m = map(int, input().split())\nuf = UnionFind(n)\nfor i in range(m):\n a, b = map(int, input().split())\n uf.union(a-1, b-1)\n\nans = 0\nfor i in range(n):\n ans = max(ans, uf.size(i))\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s514857902', 's657554269'] | [10600.0, 59084.0] | [28.0, 841.0] | [808, 890] |
p02573 | u970348538 | 2,000 | 1,048,576 | 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? | ['def search(x, num):\n return num + 1\n\n(n,m),*d = [list(map(int, s.split())) for s in open(0)]\n\nedge = [set() for _ in range(n+1)]\nfor x in d:\n edge[x[0]].add(x[1])\n edge[x[1]].add(x[0])\n\nnodes = set(range(1,n+1))\nans = 1\nfor x in list(nodes):\n if x in nodes:\n nodes.remove(x)\n tmp = search(x, 0)\n ans = max(tmp, ans)\nprint(ans)', 'def search(x, num):\n# nodes.remove(x)\n# for y in edge[x]:\n# edge[y].discard(x)\n# for y in list(edge[x]):\n# print(x,y)\n# if y in nodes:\n\n return num + 1\n\n(n,m),*d = [list(map(int, s.split())) for s in open(0)]\n\nedge = [set() for _ in range(n+1)]\nfor x in d:\n edge[x[0]].add(x[1])\n edge[x[1]].add(x[0])\n\nnodes = set(range(1,n+1))\nans = 1\nfor x in list(nodes):\n if x in nodes:\n ans = max(ans, search(x, 0))\nprint(ans)', 'def search(x, num):\n nodes.remove(x)\n# for y in edge[x]:\n# edge[y].discard(x)\n# for y in list(edge[x]):\n# if y in nodes:\n\n return num + 1\n\n(n,m),*d = [list(map(int, s.split())) for s in open(0)]\n\nedge = [set() for _ in range(n+1)]\nfor x in d:\n edge[x[0]].add(x[1])\n edge[x[1]].add(x[0])\n\nnodes = set(range(1,n+1))\nans = 1\nfor x in list(nodes):\n if x in nodes:\n ans = max(ans, search(x, 0))\nprint(ans)', 'def search(x, num):\n for y in list(edge[x]):\n if y in nodes:\n nodes.remove(y)\n edge[y].discard(x)\n num = search(y, num)\n return num + 1\n\n(n,m),*d = [list(map(int, s.split())) for s in open(0)]\n\nedge = [set() for _ in range(n+1)]\nfor x in d:\n edge[x[0]].add(x[1])\n edge[x[1]].add(x[0])', 'def search(x, num):\n nodes.remove(x)\n for y in edge[x]:\n edge[y].discard(x)\n# for y in list(edge[x]):\n# if y in nodes:\n\n return num + 1\n\n(n,m),*d = [list(map(int, s.split())) for s in open(0)]\n\nedge = [set() for _ in range(n+1)]\nfor x in d:\n edge[x[0]].add(x[1])\n edge[x[1]].add(x[0])\n\nnodes = set(range(1,n+1))\nans = 1\nfor x in list(nodes):\n if x in nodes:\n ans = max(ans, search(x, 0))\nprint(ans)', 'import sys\nsys.setrecursionlimit(int(1e6))\n\ndef search(x, num):\n nodes.remove(x)\n# for y in edge[x]:\n for y in list(edge[x]):\n edge[y].remove(x)\n if y in nodes:\n num = search(y, num)\n return num + 1\n\n(n,m),*d = [list(map(int, s.split())) for s in open(0)]\n\nedge = [set() for _ in range(n+1)]\nfor x in d:\n edge[x[0]].add(x[1])\n edge[x[1]].add(x[0])\n\nnodes = set(range(1,n+1))\nans = 1\nfor x in list(nodes):\n if x in nodes:\n ans = max(ans, search(x, 0))\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s448131290', 's455522902', 's537152570', 's680268715', 's741837798', 's284657698'] | [111660.0, 111844.0, 111920.0, 94512.0, 111932.0, 291436.0] | [982.0, 846.0, 854.0, 733.0, 884.0, 1043.0] | [360, 504, 481, 337, 477, 516] |
p02573 | u977422582 | 2,000 | 1,048,576 | 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? | ['N,M=map(int,input().split())\npar=[i for i in range(N+1)]\nsize=[1 for i in range(N+1)]\ndef find(x):\n if x!=par[x]:\n par[x]=find(par[x])\n return par[x]\ndef union(x,y):\n if find(x)!=find(y):\n par[y] = par[x]\n size[x] += size[y]\nres=N\nfor i in range(M):\n s,e=map(int,input().split())\n union(s,e)\nc=0\nfor i in range(len(par)):\n if par[i]==i and size[i]!=1:\n\n c+=size[i]\nprint((c-1)//2+(c-1)%2)', 'N,M=map(int,input().split())\npar=[i for i in range(N+1)]\nsize=[1 for i in range(N+1)]\ndef find(x):\n if x!=par[x]:\n par[x]=find(par[x])\n return par[x]\ndef union(x,y):\n if find(x)!=find(y):\n par[y] = par[x]\n size[x] += size[y]\nres=N\nfor i in range(M):\n s,e=map(int,input().split())\n union(s,e)\nc=0\nfor i in range(len(par)):\n if par[i]==i and size[i]!=1:\n\n c+=size[i]\nprint(c-1)', 'N,M=map(int,input().split())\npar=[i for i in range(N+1)]\nsize=[1 for i in range(N+1)]\ndef find(x):\n if x!=par[x]:\n par[x]=find(par[x])\n return par[x]\ndef union(x,y):\n if find(x)!=find(y):\n x, y = par[x], par[y]\n par[y] = par[x]\n size[x] += size[y]\nres=N\nfor i in range(M):\n s,e=map(int,input().split())\n union(s,e)\nprint(max(size))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s671892228', 's736640259', 's449380117'] | [18528.0, 18496.0, 18484.0] | [627.0, 704.0, 655.0] | [434, 421, 374] |
p02573 | u991542950 | 2,000 | 1,048,576 | 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? | ['class UnionFind:\n def __init__(self, n):\n self.parent = [-1] * n\n self.rank = [-1] * n\n self.count = [-1] * n\n\n def get_root(self, i):\n while self.parent[i] != -1:\n i = self.parent[i]\n return i\n\n def is_same_tree(self, i, j):\n return self.get_root(i) == self.get_root(j)\n\n def merge(self, i, j):\n i = self.get_root(i)\n j = self.get_root(j)\n if i == j:\n return\n\n if self.rank[i] > self.rank[j]:\n self.parent[j] = i\n self.rank[i] = max(self.rank[i], self.rank[j] + 1)\n self.count[i] += self.count[j]\n else:\n self.parent[i] = j\n self.rank[j] = max(self.rank[j], self.rank[i] + 1)\n self.count[j] += self.count[i]\n\n\nn, m = map(int, input().split())\nuf = UnionFind(n)\nfor _ in range(m):\n a, b = [int(i) - 1 for i in input().split()]\n uf.merge(a, b)\nprint(max(uf.count))\n', 'class UnionFind:\n def __init__(self, n):\n self.parent = [-1] * n\n self.rank = [1] * n\n self.count = [1] * n\n\n def get_root(self, i):\n while self.parent[i] != -1:\n i = self.parent[i]\n return i\n\n def is_same_tree(self, i, j):\n return self.get_root(i) == self.get_root(j)\n\n def merge(self, i, j):\n i = self.get_root(i)\n j = self.get_root(j)\n if i == j:\n return\n\n if self.rank[i] > self.rank[j]:\n self.parent[j] = i\n self.rank[i] = max(self.rank[i], self.rank[j] + 1)\n self.count[i] += self.count[j]\n else:\n self.parent[i] = j\n self.rank[j] = max(self.rank[j], self.rank[i] + 1)\n self.count[j] += self.count[i]\n\n\nn, m = map(int, input().split())\nuf = UnionFind(n)\nfor _ in range(m):\n a, b = [int(i) - 1 for i in input().split()]\n uf.merge(a, b)\nprint(max(uf.count))\n'] | ['Wrong Answer', 'Accepted'] | ['s772203563', 's966843490'] | [16620.0, 16356.0] | [664.0, 671.0] | [843, 841] |
p02573 | u994935583 | 2,000 | 1,048,576 | 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? | ['import numpy as np\nN, M = map(int, input().split())\nA = np.zeros((M,2), dtype=int)\n\nfor i in range(M):\n Ai = input().split()\n A[i,0] = int(Ai[0])\n A[i,1] = int(Ai[1])\n\nAsort = np.sort(A, axis=0)\n\nGrp_lst = np.arange(1, N+1)\nfor i in range(M):\n Grp_lst[Asort[i,1] - 1] = Grp_lst[Asort[i,0] - 1]\n\ncount = np.zeros(N,dtype=int)\n\nfor i in range(N):\n count[Grp_lst[i]-1] += 1\n\nprint(max(count))', '\n\n\nfrom sys import setrecursionlimit, stdin\n \ndef find(parent, i):\n #print("f:" + str(i))\n #print(parent)\n t = parent[i]\n if t < 0:\n return i\n t = find(parent, t)\n parent[i] = t\n return t\n \ndef unite(parent, i, j):\n i = find(parent, i)\n #print("i:" + str(i) )\n j = find(parent, j)\n \n if i == j:\n return\n parent[j] += parent[i]\n parent[i] = j\n #print(parent)\n \nreadline = stdin.readline\nsetrecursionlimit(10 ** 6)\n\ndef resolve(): \n N, M = map(int, readline().split())\n parent = [-1] * N\n for _ in range(M):\n A, B = map(lambda x: int(x) - 1, readline().split())\n unite(parent, A, B)\n print(-min(parent))\n\nresolve()'] | ['Wrong Answer', 'Accepted'] | ['s478866628', 's122399741'] | [36064.0, 16776.0] | [889.0, 361.0] | [404, 797] |
p02574 | u023229441 | 2,000 | 1,048,576 | 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. | ["from subprocess import*\ncall(('pypy3','-c',))", 'import sys\nmod=10**9+7 ; inf=float("inf")\nfrom math import sqrt, ceil\nfrom collections import deque, Counter, defaultdict \ninput=lambda: sys.stdin.readline().strip()\nsys.setrecursionlimit(11451419)\nfrom decimal import ROUND_HALF_UP,Decimal \n \nfrom functools import lru_cache\nfrom bisect import bisect_left as bileft, bisect_right as biright\n\n\n\n\n\n\nn=int(input())\n\nA=list(map(int,input().split()))\nfrom math import sqrt\ndef eratosu(n):\n if not isinstance(n,int):\n raise TypeError("nがint型になってねえぞ")\n if n<2:\n raise ValueError(\'nが2よりちっちぇえぞ\')\n prime = []\n limit = sqrt(n)\n data = [i+1 for i in range(1, n)] #2,3,4,...,n\n while True:\n p = data[0]\n if limit <= p:\n return prime + data\n prime.append(p)\n data = [e for e in data if e % p != 0]\nPRIME=eratosu(10**6+10)\n@lru_cache(maxsize=10**10)\ndef bunkai(n):\n if n==1:return []\n ans=[]\n temp=n\n \n \n primelist= PRIME\n for i in primelist:\n if i>sqrt(n):break\n if temp % i ==0:\n ji=0\n while temp%i==0:\n ji+=1\n temp//=i\n ans.append(i)\n if ans==[]:return([n]) \n if temp!=1:\n ans.append(temp) \n return ans\n\nflag=1\nseen={i:0 for i in PRIME}\n\nfor i in A:\n for l in bunkai(i):\n now=l\n if now==1:continue\n if seen[now]!=0:\n flag=0\n seen[now]+=1\nif flag:\n print("pairwise coprime")\nelif max(seen.values())!=n:\n print("setwise coprime")\nelse:\n print("not coprime")\n\n\n', 'import numpy as np\nn=int(input())\nA=list(map(int,input().split()))\ncnt=[0]*(10**6+10)\nfor i in A:\n cnt[i]+=1\n\n\nif np.gcd.reduce(A) !=1:\n print("not coprime");exit()\nelif np.all([sum(cnt[i::i])<=1 for i in range(2,10**6+1)]):\n print("pairwise coprime")\nelse:\n print("setwise coprime")\n'] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s231339837', 's284451072', 's339042157'] | [261420.0, 133608.0, 150516.0] | [2206.0, 2210.0, 923.0] | [2216, 2120, 296] |
p02574 | u062691227 | 2,000 | 1,048,576 | 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. | ['import numpy as np\nN=int(input())\nA=list(map(int,input().split()))\n# cnt=[0]*(10**6+1)\ncnt=np.zeros(10**6+1, dtype=\'int\')\nfor a in A:cnt[a]+=1\n \nif np.gcd.reduce(A)!=1:\n print("not coprime")\nelif np.all([sum(cnt[i::i])<=1 for i in range(2,10**6+1)]):\n print("pairwise coprime")\nelse:\n print("setwise coprime")', "import numpy as np\nn = int(input())\naa = np.array(input().split(), dtype='int')\nma = np.max(aa)\n\ncnt = [0] * (ma+1)\n\nfor a in aa:\n cnt[a] += 1\n\nif np.gcd.reduce(aa) != 1:\n print('not coprime')\nelif np.all([sum(cnt[i::i]) <= 1 for i in range(2, ma)]):\n print('pairwise coprime')\nelse:\n print('setwise coprime')"] | ['Time Limit Exceeded', 'Accepted'] | ['s717352861', 's237241983'] | [150596.0, 150436.0] | [2208.0, 1016.0] | [312, 361] |
p02574 | u133936772 | 2,000 | 1,048,576 | 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. | ["M=10**6+1\nf=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))\nn,*l=map(int,open(0).read().split())\nfrom math import *\ng=l[0]\nfor x in l: g=gcd(g,x)\nif g>1: f(2)\nC=[0]*M\nfor x in l: C[x]=1\nfor i in range(2,M):\n if sum(C[j] for j in range(i,M,i))>1: f(1)\nf(0)", "M=10**6+1\nf=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))\nn=int(input())\nl=[*map(int,input().split())]\ng=0\nfrom math import *\nfor x in l:\n g=gcd(g,x)\nif g>1: f(2)\ndef sieve(x):\n p=[]\n s=[0]*x\n for i in range(2,x):\n if s[i]<1:\n p+=[i]\n for j in range(i,x,i): s[j]=i\n return s\ns=sieve(M)\nC=[0]*M\nfor x in l:\n t=set()\n while x>1:\n t.add(s[x])\n x//=s[x]\n for y in t:\n if C[y]: f(1)\n C[y]=1\nf(0)"] | ['Time Limit Exceeded', 'Accepted'] | ['s496715927', 's243927491'] | [126028.0, 127160.0] | [2051.0, 625.0] | [274, 443] |
p02574 | u157232135 | 2,000 | 1,048,576 | 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. | ['import math\ndef main():\n n=int(input())\n a=list(map(int,input().split()))\n ap=[set(prime_factorize(i)) for i in a]\n x=set()\n for i in ap:\n if len(x & i) > 0:\n break\n x |= i\n else:\n print("pairwise coprime")\n return\n x=a[0]\n for i in a:\n x = math.gcd(x, i)\n if x == 1:\n print("setwise coprime")\n return\n print("not coprime")\n\nif __name__ == "__main__":\n main()', 'from functools import lru_cache\n\ndef main():\n n=int(input())\n a=list(map(int,input().split()))\n x=set()\n y=a[0]\n pair=True\n for i in a:\n if pair:\n p=set(prime_factorize(i))\n if len(x&p)>0:\n pair=False\n x|=p\n y=math.gcd(y, i)\n if pair:\n print("pairwise coprime")\n elif y==1:\n print("setwise coprime")\n else:\n print("not coprime")\n\n\n@lru_cache(maxsize=None)\ndef primes(n:int) -> list:\n \n is_prime = [True] * (n + 1)\n is_prime[0] = False\n is_prime[1] = False\n for i in range(2, int(n**0.5) + 1):\n if not is_prime[i]:\n continue\n for j in range(i * 2, n + 1, i):\n is_prime[j] = False\n return [i for i in range(n + 1) if is_prime[i]]\n\n\n@lru_cache(maxsize=None)\ndef is_prime(n: int) -> bool:\n \n if n == 1:\n return False\n elif n == 2:\n return True\n elif n % 2 == 0:\n return False\n \n for i in range(3, int(n**0.5)+1, 2):\n if n % i == 0:\n return False\n return True\n\n\ndef prime_factorize(n: int) -> list:\n \n arr = []\n \n while n % 2 == 0:\n arr.append(2)\n n //= 2\n \n for f in primes(int(n**0.5)):\n while n % f == 0:\n arr.append(f)\n n //= f\n if n != 1:\n arr.append(n)\n return arr\n\nif __name__ == "__main__":\n main()', 'import math\ndef main():\n n=int(input())\n a=list(map(int,input().split()))\n ap=[set(prime_factorize(i)) for i in a]\n x=set()\n for i in ap:\n if len(x & i) > 0:\n break\n x |= i\n else:\n print("pairwise coprime")\n return\n x=a[0]\n for i in a:\n x = math.gcd(x, i)\n if x == 1:\n print("setwise coprime")\n return\n print("not coprime")\n\ndef prime_factorize(n: int) -> list:\n \n arr = []\n \n while n % 2 == 0:\n arr.append(2)\n n //= 2\n \n for f in primes(int(n**0.5)):\n while n % f == 0:\n arr.append(f)\n n //= f\n if n != 1:\n arr.append(n)\n return arr\n\nif __name__ == "__main__":\n main()', 'from functools import lru_cache\nimport math\n\ndef main():\n n=int(input())\n a=list(map(int,input().split()))\n x=set()\n y=a[0]\n pair=True\n for i in a:\n if pair:\n p=set(prime_factorize(i))\n if len(x&p)>0:\n pair=False\n x|=p\n y=math.gcd(y, i)\n if pair:\n print("pairwise coprime")\n elif y==1:\n print("setwise coprime")\n else:\n print("not coprime")\n\n\n@lru_cache(maxsize=None)\ndef primes(n:int) -> list:\n \n is_prime = [True] * (n + 1)\n is_prime[0] = False\n is_prime[1] = False\n for i in range(2, int(n**0.5) + 1):\n if not is_prime[i]:\n continue\n for j in range(i * 2, n + 1, i):\n is_prime[j] = False\n return [i for i in range(n + 1) if is_prime[i]]\n\n\n@lru_cache(maxsize=None)\ndef is_prime(n: int) -> bool:\n \n if n == 1:\n return False\n elif n == 2:\n return True\n elif n % 2 == 0:\n return False\n \n for i in range(3, int(n**0.5)+1, 2):\n if n % i == 0:\n return False\n return True\n\n\ndef prime_factorize(n: int) -> list:\n \n arr = []\n \n while n % 2 == 0:\n arr.append(2)\n n //= 2\n \n for f in primes(int(n**0.5)):\n while n % f == 0:\n arr.append(f)\n n //= f\n if n != 1:\n arr.append(n)\n return arr\n\nif __name__ == "__main__":\n main()'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s245735257', 's490212802', 's984219360', 's438182123'] | [132736.0, 127668.0, 126944.0, 128008.0] | [241.0, 236.0, 240.0, 713.0] | [452, 1832, 870, 1844] |
p02574 | u222668979 | 2,000 | 1,048,576 | 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. | ["from math import gcd\n\nn = int(input())\na = list(map(int, input().split()))\n\n\nans = 0\ncnt = [0] * (max(a) + 1)\nfor ai in a:\n ans = gcd(ans, ai)\n cnt[ai] += 1\n\nif ans != 1:\n print('not coprime')\nelif any(sum(cnt[i::i]) > 1 for i in range(max(a) + 1)):\n print('setwise coprime')\nelse:\n print('pairwise coprime')\n", "from math import gcd\n\nn = int(input())\na = list(map(int, input().split()))\n\n\nans = 0\ncnt = [0] * (max(a) + 1)\nfor ai in a:\n ans = gcd(ans, ai)\n cnt[ai] += 1\n\nif ans != 1:\n print('not coprime')\nelif any(sum(cnt[i::i]) > 1 for i in range(2, max(a) + 1)):\n print('setwise coprime')\nelse:\n print('pairwise coprime')\n"] | ['Runtime Error', 'Accepted'] | ['s213124389', 's746963259'] | [132732.0, 132708.0] | [501.0, 568.0] | [342, 345] |
p02574 | u223904637 | 2,000 | 1,048,576 | 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. | ["from math import gcd\nn=int(input())\nl=list(map(int,input().split()))\nmal=max(l)\ne=[i for i in range(mal+1)]\n\nx=2\nwhile x*x <= mal:\n if x == e[x]:\n for m in range(x, len(e), n):\n if e[m] == m:\n e[m] = x\n x+=1\n#print(e) \ns=set()\nf=1\nfor i in l:\n st = set()\n while i > 1:\n st.add(e[i])\n i//=e[i]\n if not s.isdisjoint(st):\n f=1\n break\n s |= st\n\nif f==0:\n print('pairwise coprime')\n exit()\np=l[0]\nfor i in range(1,n):\n p=gcd(p,l[i])\nif p==1:\n print('setwise coprime')\nelse:\n print('not coprime')", "from math import gcd\nn=int(input())\nl=list(map(int,input().split()))\nmal=max(l)\ne=[0 for i in range(mal+1)]\n\nimport numpy as np\ndef searchPrimeNum(N):\n ma = int(np.sqrt(N))\n searchList = [i for i in range(2,N+1)]\n primeNum = []\n while searchList[0] <= ma:\n primeNum.append(searchList[0])\n tmp = searchList[0]\n for i in searchList:\n if i%tmp==0:\n e[i]=tmp\n searchList = [i for i in searchList if i % tmp != 0]\n primeNum.extend(searchList)\n return primeNum\nsearchPrimeNum(mal)\n#print(e) \ns=set()\nf=1\nfor i in l:\n st = set()\n while i > 1:\n st.add(e[i])\n i//=e[i]\n if not s.isdisjoint(st):\n f=1\n break\n s |= st\n\nif f==0:\n print('pairwise coprime')\n exit()\np=l[0]\nfor i in range(1,n):\n p=gcd(p,l[i])\nif p==1:\n print('setwise coprime')\nelse:\n print('not coprime')", "from math import gcd\nn=int(input())\nl=list(map(int,input().split()))\nmal=max(l)\ne=[i for i in range(mal+1)]\n\nx=2\nwhile x*x <= mal:\n if x == e[x]:\n for m in range(x, len(e), x):\n if e[m] == m:\n e[m] = x\n x+=1\n#print(e) \ns=set()\nf=0\nfor i in l:\n st = set()\n while i > 1:\n st.add(e[i])\n i//=e[i]\n if not s.isdisjoint(st):\n f=1\n break\n s |= st\n\nif f==0:\n print('pairwise coprime')\n exit()\np=l[0]\nfor i in range(1,n):\n p=gcd(p,l[i])\nif p==1:\n print('setwise coprime')\nelse:\n print('not coprime')\n"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s061240923', 's379369892', 's078340897'] | [148032.0, 216316.0, 134580.0] | [1230.0, 2211.0, 768.0] | [563, 867, 564] |
p02574 | u229950162 | 2,000 | 1,048,576 | 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. | ['max_num = 10**6 + 1\nprime = [i for i in range(max_num)]\nr2_num = int(max_num**(1/2))+1\nfor i in range(2, r2_num):\n if prime[i] == i:\n for j in range(i**2, max_num, i):\n if prime[j] == j:\n prime[j] = i\ndef gcd(a, b): # a >= b\n if a%b == 0:\n return b\n else:\n return gcd(b, a%b)\n\nflg_pairwise = True\nflg_setwise = False\n\nn = int(input().rstrip())\na_ls = list(map(int, input().rstrip().split(" ")))\ngcd_a = 0\nprimes_a = []\ncount_prime = [0 for i in range(max_num)]\nfor a in a_ls:\n gcd_a = gcd(gcd_a, a)\n if gcd_a == 1:\n flg_setwise = True\n tmp_prime = []\n if flg_pairwise:\n while a > 1:\n p = prime[a]\n if tmp_prime == [] or tmp_prime[-1] != p:\n tmp_prime.append(p)\n a = a//p\n for tp in tmp_prime:\n for pa in primes_a:\n if pa == tp:\n flg_pairwise = False\n break\n if flg_pairwise:\n primes_a.append(tp)\n else:\n break\n if flg_setwise and not flg_pairwise:\n break\nif flg_pairwise:\n print("pairwise coprime")\nelif flg_setwise:\n print("setwise coprime")\nelse:\n print("not coprime")', 'max_num = 10**6 + 1\nprime = [i for i in range(max_num)]\nr2_num = int(max_num**(1/2))+1\nfor i in range(2, r2_num):\n if prime[i] == i:\n for j in range(i**2, max_num, i):\n if prime[j] == j:\n prime[j] = i\ndef gcd(a, b): # a >= b\n if a%b == 0:\n return b\n else:\n return gcd(b, a%b)\n\nflg_pairwise = True\nflg_setwise = False\n\nn = int(input().rstrip())\na_ls = list(map(int, input().rstrip().split(" ")))\ngcd_a = a_ls[0]\ncount_prime = [0 for i in range(max_num)]\nfor a in a_ls:\n gcd_a = gcd(gcd_a, a)\n if gcd_a == 1:\n flg_setwise = True\n tmp_prime = []\n while a > 1:\n p = prime[a]\n if tmp_prime == [] or tmp_prime[-1] != p:\n tmp_prime.append(p)\n a = a//p\n for tp in tmp_prime:\n if not count_prime[tp]:\n count_prime[tp] = 1\n else:\n flg_pairwise = False\n break\n if flg_setwise and not flg_pairwise:\n break\nif flg_pairwise:\n print("pairwise comprime")\nelif flg_setwise:\n print("setwise comprime")\nelse:\n print("not comprime")', 'max_num = 10**6 + 1\nprime = [i for i in range(max_num)]\nr2_num = int(max_num**(1/2))+1\nfor i in range(2, r2_num):\n if prime[i] == i:\n for j in range(i**2, max_num, i):\n if prime[j] == j:\n prime[j] = i\ndef gcd(a, b): # a >= b\n if a%b == 0:\n return b\n else:\n return gcd(b, a%b)\n\nflg_pairwise = True\nflg_setwise = False\n\nn = int(input().rstrip())\na_ls = list(map(int, input().rstrip().split(" ")))\ngcd_a = 0\nprimes_a = []\ncount_prime = [0 for i in range(max_num)]\nfor a in a_ls:\n gcd_a = gcd(gcd_a, a)\n if gcd_a == 1:\n flg_setwise = True\n tmp_prime = 0\n while a > 1:\n p = prime[a]\n pp = prime[p]\n if p == 0 or pp == 0:\n flg_pairwise = False\n break\n if tmp_prime != p:\n prime[tmp_prime] = 0\n tmp_prime = p\n a = a//p\n if flg_pairwise:\n prime[tmp_prime] = 0\n if flg_setwise and not flg_pairwise:\n break\nif flg_pairwise:\n print("pairwise coprime")\nelif flg_setwise:\n print("setwise coprime")\nelse:\n print("not coprime")'] | ['Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s607057872', 's876176681', 's604971046'] | [144144.0, 137008.0, 137064.0] | [2209.0, 2208.0, 1122.0] | [1092, 986, 989] |
p02574 | u240630407 | 2,000 | 1,048,576 | 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. | ['# import itertools\nimport math\nimport functools import reduce\n# import sys\n\n# import numpy as np\n# import heapq\n# from collections import deque\n\nN = int(input())\n# S = input()\n# n, *a = map(int, open(0))\n# N, M = map(int, input().split())\nA = list(map(int, input().split()))\n# B = list(map(int, input().split()))\n# tree = [[] for _ in range(N + 1)]\n# B_C = [list(map(int,input().split())) for _ in range(M)]\n# S = input()\n\n\n# all_cases = list(itertools.permutations(P))\n# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))\n# itertools.product((0,1), repeat=n)\n\n# A = np.array(A)\n# cum_A = np.cumsum(A)\n# cum_A = np.insert(cum_A, 0, 0)\n\n\n# for l in tree[s]:\n\n\n# dfs(tree, l[0])\n# dfs(tree, 1)\n\n\n# arr = []\n# temp = n\n\n# if temp%i==0:\n# cnt=0\n# while temp%i==0:\n# cnt+=1\n# temp //= i\n# arr.append([i, cnt])\n# if temp!=1:\n# arr.append([temp, 1])\n# if arr==[]:\n# arr.append([n, 1])\n# return arr\n\ndef gcd_list(numbers):\n return reduce(math.gcd, numbers)\n\nif gcd_list(A) > 1:\n print("not coprime")\n\n\nMAXN = 10**6+10\nsieve = [i for i in range(MAXN+1)]\np = 2\nwhile p*p <= MAXN:\n if sieve[p] == p:\n for q in range(2*p, MAXN+1, p):\n if sieve[q] == q:\n sieve[q] = p\n p += 1\n\nst = set()\nfor a in A:\n tmp = set()\n while a > 1:\n tmp.add(sieve[a])\n a //= sieve[a]\n for p in tmp:\n if p in st:\n print(\'setwise coprime\')\n exit()\n st.add(p)\nprint(\'pairwise coprime\')\n', '# import itertools\nimport math\nfrom functools import reduce\n# import sys\n\n# import numpy as np\n# import heapq\n# from collections import deque\n\nN = int(input())\n# S = input()\n# n, *a = map(int, open(0))\n# N, M = map(int, input().split())\nA = list(map(int, input().split()))\n# B = list(map(int, input().split()))\n# tree = [[] for _ in range(N + 1)]\n# B_C = [list(map(int,input().split())) for _ in range(M)]\n# S = input()\n\n\n# all_cases = list(itertools.permutations(P))\n# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))\n# itertools.product((0,1), repeat=n)\n\n# A = np.array(A)\n# cum_A = np.cumsum(A)\n# cum_A = np.insert(cum_A, 0, 0)\n\n\n# for l in tree[s]:\n\n\n# dfs(tree, l[0])\n# dfs(tree, 1)\n\n\n# arr = []\n# temp = n\n\n# if temp%i==0:\n# cnt=0\n# while temp%i==0:\n# cnt+=1\n# temp //= i\n# arr.append([i, cnt])\n# if temp!=1:\n# arr.append([temp, 1])\n# if arr==[]:\n# arr.append([n, 1])\n# return arr\n\ndef gcd_list(numbers):\n return reduce(math.gcd, numbers)\n\nif gcd_list(A) > 1:\n print("not coprime")\n exit()\n\n\nMAXN = 10**6+10\nsieve = [i for i in range(MAXN+1)]\np = 2\nwhile p*p <= MAXN:\n if sieve[p] == p:\n for q in range(2*p, MAXN+1, p):\n if sieve[q] == q:\n sieve[q] = p\n p += 1\n\nst = set()\nfor a in A:\n tmp = set()\n while a > 1:\n tmp.add(sieve[a])\n a //= sieve[a]\n for p in tmp:\n if p in st:\n print(\'setwise coprime\')\n exit()\n st.add(p)\nprint(\'pairwise coprime\')\n'] | ['Runtime Error', 'Accepted'] | ['s572191308', 's564017043'] | [8928.0, 127636.0] | [25.0, 757.0] | [1845, 1854] |
p02574 | u249218427 | 2,000 | 1,048,576 | 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. | ["N = int(input())\nM = 10**6 + 1\n\ncounts = [0 for _ in range(M)]\nfor a in map(int, input().split()):\n counts[a] += 1\n\nmax_count = 0\nfor i in range(2,M):\n count = 0\n for j in range(i,M,i):\n count += counts[j]\n max_count = max(max_count,count)\n\nif max_count == N:\n answer = 'not coprime'\nelif max_count >= 2:\n answer = 'setwise coprime'\nelse:\n answer = 'pairwise coprime'\n\nprint(answer)", "N = int(input())\nM = 10**6 + 1\n\ncounts = [0 for _ in range(M)]\nfor a in map(int, input().split()):\n counts[a] += 1\n\nmax_count = 0\nfor i in range(2,M):\n max_count = max(max_count,sum(counts[i::i]))\n\nif max_count == N:\n answer = 'not coprime'\nelif max_count >= 2:\n answer = 'setwise coprime'\nelse:\n answer = 'pairwise coprime'\n\nprint(answer)"] | ['Time Limit Exceeded', 'Accepted'] | ['s215358265', 's938576948'] | [101716.0, 101940.0] | [2207.0, 1058.0] | [392, 344] |
p02574 | u262869085 | 2,000 | 1,048,576 | 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. | ['def divplis(N):\n lis = [i for i in range(N+1)]\n for i in range(int(N**0.5+1),1,-1):\n if lis[i] == i:\n lis[i::i] = [i]*(N//i)\n return lis\n\ndivp = divplis(10**6+1)\nprint(divp[:10])\nprint(divp[-10:])\nprint(len(divp)-1)\nprint((len(divp)-1)/divp[-1])\nN = int(input())\nd = [0]*(10**6+1)\nA = [int(i) for i in input().split()]\n\n\ndef pfact(N):\n b = 0\n while N != 1:\n n = divp[N]\n if b != n:\n d[n] += 1\n b = n\n N = N // n\n return 0\n \nfor a in A:\n pfact(a)\nm = max(d)\nif m == 1:\n print("pairwise coprime")\nelif m == N:\n print("not coprime")\nelse:\n print("setwise coprime")\n', 'def divplis(N):\n lis = [i for i in range(N+1)]\n for i in range(int(N**0.5+1),1,-1):\n if lis[i] == i:\n lis[i::i] = [i]*(N//i)\n return lis\n\ndivp = divplis(10**6+1)\nN = int(input())\nd = [0]*(10**6+1)\nA = [int(i) for i in input().split()]\n\n\ndef pfact(N):\n b = 0\n while N != 1:\n n = divp[N]\n if b != n:\n d[n] += 1\n b = n\n N = N // n\n return 0\n \nfor a in A:\n pfact(a)\nm = max(d)\nif m < 1:\n print("pairwise coprime")\nelif m == N:\n print("not coprime")\nelse:\n print("setwise coprime")\n', 'def divplis(N):\n lis = [i for i in range(N+1)]\n for i in range(int(N**0.5+1),1,-1):\n if lis[i] == i:\n lis[i::i] = [i]*(N//i)\n return lis\n\ndivp = divplis(10**6+1)\nN = int(input())\nd = [0]*(10**6+1)\nA = [int(i) for i in input().split()]\n\n\ndef pfact(N):\n b = 0\n while N != 1:\n n = divp[N]\n if b != n:\n d[n] += 1\n b = n\n N = N // n\n return 0\n \nfor a in A:\n pfact(a)\nm = max(d)\nif m <= 1:\n print("pairwise coprime")\nelif m == N:\n print("not coprime")\nelse:\n print("setwise coprime")\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s112439650', 's141443925', 's591017225'] | [151260.0, 151536.0, 151316.0] | [1686.0, 1772.0, 1710.0] | [652, 567, 568] |
p02574 | u317423698 | 2,000 | 1,048,576 | 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. | ["import sys\nimport math\nimport functools\n\n\ndef resolve(in_):\n N = int(next(in_))\n A = tuple(map(int, next(in_).split()))\n\n max_a = max(A)\n temp = [0] * (max_a + 1)\n temp[1] = 1\n\n for i in range(2, max_a + 1):\n if temp[i]:\n continue\n\n j = i\n while j < max_a + 1:\n if not temp[j]:\n temp[j] = i\n j += i\n\n B = []\n for a in A:\n while a > 1:\n B.append(temp[a])\n a = a // temp[a]\n \n C = tuple(filter(lambda x: x > 1, B))\n D = frozenset(C)\n if len(C) == len(D):\n return 'pairwise coprime'\n\n if functools.reduce(math.gcd, A) == 1:\n return 'setwise coprime'\n\n return 'not coprime'\n \n\ndef main():\n answer = resolve(sys.stdin.buffer)\n print(answer)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\nimport math\nimport functools\n\ndef resolve(in_):\n N = int(next(in_))\n A = tuple(map(int, next(in_).split()))\n\n max_a = max(A)\n temp = [0] * (max_a + 1)\n temp[1] = 1\n\n for i in range(2, max_a + 1):\n if temp[i]:\n continue\n\n j = i\n while j < max_a + 1:\n if not temp[j]:\n temp[j] = i\n j += i\n\n B = set()\n for a in A:\n s = set()\n while a > 1:\n s.add(temp[a])\n a = a // temp[a]\n for v in s:\n if v in B:\n if functools.reduce(math.gcd, A) == 1:\n return 'setwise coprime'\n else:\n return 'not coprime'\n B.add(v)\n \n return 'pairwise coprime'\n \n\ndef main():\n answer = resolve(sys.stdin.buffer)\n print(answer)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s158645090', 's076464696'] | [211144.0, 110580.0] | [2213.0, 595.0] | [839, 888] |
p02574 | u323315992 | 2,000 | 1,048,576 | 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. | ['def eratosthenes2(n):\n lim=int(n**0.5)\n d=[i+1 for i in range(2,n,2)]\n D=[2]*(n+1)\n D[0]=D[1]=-1\n while True:\n p=d[0]\n if lim<p:\n for x in d:\n D[x]=x\n break\n D[p]=p\n d2=[]\n for x in d:\n if x%p!=0:\n d2.append(x)\n else:\n D[x]=p\n d=d2\n return D\n \nN=int(input())\nA=list(map(int,input().split()))\nmaxA=max(A)\nD=eratosthenes2(maxA)\nprint(D)', 'def eratosthenes2(n):\n D=[-1]*(n+1)\n D[0]=0\n D[1]=1\n for i in range(2, n+1):\n if D[i] == -1:\n D[i] = i\n for j in range(i*i, n+1, i):\n if D[j] == -1:\n D[j] = i\n return D\n\nN=int(input())\nA=list(map(int,input().split()))\nmaxA=max(A)\nD=eratosthenes2(maxA)\nprint(maxA)', "N=int(input())\nA=list(map(int,input().split()))\nmaxA=max(A)\ncount=[0]*(maxA+1)\nfor x in A:\n count[x]+=1\nmaxc=0\nfor i in range(2,maxA+1):\n maxc = max(maxc,sum(count[i::i]))\n\nif maxc==N:\n print('not coprime')\nelif maxc<=1:\n print('pairwise coprime')\nelse:\n print('setwise coprime')"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s346164406', 's529034061', 's757380045'] | [127348.0, 127508.0, 127272.0] | [1802.0, 447.0, 913.0] | [486, 341, 294] |
p02574 | u328811800 | 2,000 | 1,048,576 | 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. | ['import sys\n\ndef gcd(x, y):\n if x % y == 0:\n return y\n else:\n return gcd(y, x % y)\n\nN = int(input())\nA = list(map(int, input().split()))\n\ncount= [0] * (1000001)\nsetwise_gcd = A[0]\nfor i in range(0,N):\n count[A[i]]+= 1\n setwise_gcd = gcd(setwise_gcd, A[i])\n\n\nif setwise_gcd != 1:\n print("not coprime")\n sys.exit(0)\n\nfor i in range(2,1000001):\n divided_count = count[i]\n now_number = 2 * i\n while(now_number<1000001):\n divided_count+= count[now_number]\n now_number+= i\n if(divided_count >= 2):\n print("setwise coprime")\n exit(0)\nprint("pairwise coprime")\n', 'import numpy as np\n\nN = int(input())\nA = list(map(int, input().split()))\n\ncount=[0]*(1000001)\nfor a in A:count[a]+= 1\n\n\nif np.gcd.reduce(A)!=1:\n print("not coprime")\n\nelif np.all([sum(count[i::i])<=1 for i in range(2,10**6+1)]):\n print("pairwise coprime")\nelse:\n print("setwise coprime")\n'] | ['Time Limit Exceeded', 'Accepted'] | ['s186257254', 's376481673'] | [127368.0, 150544.0] | [2206.0, 951.0] | [816, 470] |
p02574 | u347640436 | 2,000 | 1,048,576 | 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. | ["from math import gcd\nfrom functools import reduce\n\ndef make_prime_table(n):\n sieve = list(range(n + 1))\n sieve[0] = -1\n sieve[1] = -1\n for i in range(4, n + 1, 2):\n sieve[i] = 2\n for i in range(3, int(n ** 0.5) + 1, 2):\n if sieve[i] != i:\n continue\n for j in range(i * i, n + 1, i * 2):\n if sieve[j] == j:\n sieve[j] = i\n return sieve\n\n\ndef prime_factorize(n):\n result = []\n while n != 1:\n p = prime_table[n]\n e = 0\n while n % p == 0:\n n //= p\n e += 1\n result.append((p, e))\n return result\n\n\ndef f():\n s = set()\n for i in range(N - 1, -1. -1):\n t = prime_factorize(A[i])\n for p, _ in t:\n if p in s:\n return False\n s.add(p)\n return True\n\n\nN, *A = map(int, open(0).read().split())\n\nprime_table = make_prime_table(10 ** 6)\nif f():\n print('pairwise coprime')\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\nelse:\n print('not coprime')\n", "from math import gcd\nfrom functools import reduce\n\nN, *A = map(int, open(0).read().split())\n\ndef f():\n t = [0] * (10 ** 6 + 1)\n for a in A:\n t[a] += 1\n\n c = 0\n for j in range(2, 10 ** 6 + 1, 2):\n c += t[j]\n if c > 1:\n return False\n\n for i in range(3, 10 ** 6 + 1, 2):\n c = 0\n for j in range(i, 10 ** 6 + 1, i):\n c += t[j]\n if c > 1:\n return False\n\n return True\n\nif f():\n print('pairwise coprime')\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\nelse:\n print('not coprime')\n"] | ['Runtime Error', 'Accepted'] | ['s637951150', 's666129521'] | [121952.0, 121816.0] | [453.0, 684.0] | [1038, 571] |
p02574 | u391725895 | 2,000 | 1,048,576 | 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. | ['def gcc(x, y):\n if x == 0:return y\n return gcc(y % x, x)\n\nN = int(input())\nA = list(map(int, input().split()))\n\ng = 0\n\nA.sort()\n\nfor item in A:\n g = gcc(g, item)\n\nif g != 1:\n print("not coprime")\n exit()\n\nprimes = []\n\nis_prime = [True] * 1100000\nprimes = []\n\nis_prime[0] = is_prime[1] = False\n\nfor i in range(2, 1100000):\n if not is_prime[i]:continue\n for j in range(i*i, 1100000, i):\n is_prime[j] = False\n primes.append[i]\n\nA_prime = [item for item in A if is_prime[item]]\nA_notprime = [item for item in A if not is_prime[item]]\n\nused = [False] * 1100000\n\nfor item in A_prime:\n used[item] = True\n\nfor a in A_notprime:\n for p in primes:\n if a == 1:break\n if a % p != 0:continue\n\n if used[p]:\n print("setwise coprime")\n \n exit()\n\n used[p] = True\n\n while a > p:\n a //= p\n\nprint("pairwise coprime")', 'def gcc(x, y):\n if x == 0:return y\n return gcc(y % x, x)\n\nN = int(input())\nA = list(map(int, input().split()))\n\ng = 0\n\nA.sort()\n\nfor item in A:\n g = gcc(g, item)\n\nif g != 1:\n print("not coprime")\n exit()\n\nprimes = []\nis_prime = [True] * 1100000\n\nis_prime[0] = is_prime[1] = False\n\nfor i in range(2, 1100000):\n if not is_prime[i]:continue\n for j in range(i*i, 1100000, i):\n is_prime[j] = False\n primes.append(i)\n\nA_prime = [item for item in A if is_prime[item]]\nA_notprime = [item for item in A if not is_prime[item]]\n\nused = [False] * 1100000\n\nfor item in A_prime:\n used[item] = True\n\nfor a in A_notprime:\n for p in primes:\n if a == 1:break\n if a % p != 0:continue\n\n if used[p]:\n print("setwise coprime")\n \n exit()\n\n used[p] = True\n\n while a % p == 0:\n a //= p\n\nprint("pairwise coprime")'] | ['Runtime Error', 'Accepted'] | ['s039071947', 's052657814'] | [127064.0, 127032.0] | [898.0, 1431.0] | [1022, 1014] |
p02574 | u397080265 | 2,000 | 1,048,576 | 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. | ['mod=10**9+7\nn=int(input())\na=list(map(int,input().split()))\na.sort()\ng=a[0]\nd=defaultdict(int)\nfor i in a:\n g=math.gcd(g,i)\n d[i]+=1\nif g>1:\n print("not coprime")\np=[0]*(a[-1]+1)\nch=0\nfor i in range (2,a[-1]+1):\n if p[i]==1:\n continue\n p[i]=1\n ans=0\n for j in range (i,a[-1]+1,i):\n ans+=d[j]\n if ans>1:\n ch=1\n break\nif ch==1:\n print("setwise coprime")\nelse:\n print("pairwise coprime")', 'import math\nn=int(input())\na=list(map(int,input().split()))\nm=max(a)+1\ng=a[0]\nd=dict()\nfor i in a:\n g=math.gcd(g,i)\n if i in d:\n d[i]+=1\n else:\n d[i]=1\nif g>1:\n print("not coprime")\nelse:\n p=[0]*(m)\n ch=0\n for i in range (2,m):\n if p[i]==1:\n continue\n p[i]=1\n ans=0\n for j in range (i,m,i):\n ans+=d[j]\n if ans>1:\n ch=1\n break\n if ch==1:\n print("setwise coprime")\n else:\n print("pairwise coprime")', 'mod=10**9+7\nn=int(input())\na=list(map(int,input().split()))\na.sort()\ng=a[0]\nfor i in a:\n g=math.gcd(g,i)\nd=dict()\nfor i in a:\n if i%2==0:\n if 2 in d:\n d[2]+=1\n else:\n d[2]=1\n while i%2==0:\n i//=2\n for j in range (3, int(math.sqrt(i))+1 ):\n if i%j==0:\n if j in d:\n d[j]+=1\n else:\n d[j]=1\n while i%j==0:\n i//=j\n if i>2:\n if i in d:\n d[i]+=1\n else:\n d[i]=1\nc=1\nfor i in d:\n c=max(c,d[i])\nif c==1:\n print("pairwise coprime")\nelif g==1:\n print("setwise coprime")\nelse:\n print("not coprime")', 'import math\nmod=10**9+7\nn=int(input())\na=list(map(int,input().split()))\nm=max(a)+1\ng=a[0]\nd=dict()\nfor i in a:\n g=math.gcd(g,i)\n if i in d:\n d[i]+=1\n else:\n d[i]=1\nif g>1:\n print("not coprime")\nelse:\n p=[0]*(m)\n ch=0\n for i in range (2,m):\n if p[i]==1:\n continue\n p[i]=1\n ans=0\n for j in range (i,m,i):\n if j in d:\n ans+=d[j]\n if ans>1:\n ch=1\n break\n if ch==1:\n print("setwise coprime")\n else:\n print("pairwise coprime")'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s272317811', 's291199803', 's731577932', 's203279173'] | [126432.0, 132636.0, 126488.0, 134332.0] | [562.0, 744.0, 564.0, 1711.0] | [442, 530, 676, 569] |
p02574 | u408325839 | 2,000 | 1,048,576 | 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. | ["import numpy as np\nfrom numba import njit\ndef main():\n N = int(input())\n nlist = np.array(list(map(int, input().split())))\n\n def gdc(x, y):\n b = max(x, y)\n s = min(x, y)\n r = b % s\n if r == 0:\n return s\n else:\n return gdc(s, r)\n\n scp = False\n pcp = False\n\n sgdc = nlist[0]\n for n in nlist:\n sgdc = gdc(sgdc, n)\n if sgdc == 1:\n scp = True\n\n if not scp:\n print('not coprime')\n exit()\n\n pcheckl = np.full((10**6+1), 0)\n for n in nlist:\n pcheckl[n] = 1\n\n pcp = np.all([sum(pcheckl[i::i]) <= 1 for i in range(2, 10**6+1)])\n\n if pcp:\n print('pairwise coprime')\n elif scp:\n print('setwise coprime')\n\nif __name__ == '__main__':\n main()", "import numpy as np\nfrom numba import njit\ndef main():\n N = int(input())\n nlist = list(map(int, input().split()))\n\n def gdc(x, y):\n b = max(x, y)\n s = min(x, y)\n r = b % s\n if r == 0:\n return s\n else:\n return gdc(s, r)\n\n scp = False\n pcp = False\n\n sgdc = nlist[0]\n for n in nlist:\n sgdc = gdc(sgdc, n)\n if sgdc == 1:\n scp = True\n break\n\n if not scp:\n print('not coprime')\n exit()\n\n pcheckl = [0] * (10**6+1)\n for n in nlist:\n pcheckl[n] = 1\n\n pcp = all([sum(pcheckl[i::i]) <= 1 for i in range(2, 10**6+1)])\n\n if pcp:\n print('pairwise coprime')\n elif scp:\n print('setwise coprime')\n\nif __name__ == '__main__':\n main()"] | ['Time Limit Exceeded', 'Accepted'] | ['s560327357', 's860237200'] | [208796.0, 208632.0] | [2208.0, 1045.0] | [786, 785] |
p02574 | u413165887 | 2,000 | 1,048,576 | 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. | ["n = int(input())\na = list(map(int, input().split()))\n\nfrom math import gcd\n\nr = a[0]\nfor i in a[1:]:\n r = gcd(r, i)\n\nc = [0 for _i in range(10**6+1)]\nh = True\nfor i in a:\n num = i\n for j in range(2, int(num**.5)+1):\n if num%j == 0:\n c[j] += 1\n if c[j] >= 2:\n h = False\n break\n else:\n num //= j\n if num == i:\n c[num] += 1\n if c[num] >= 2:\n h = False\n break \nif h == True:\n print('pairwise cprime')\nelif r == 1:\n print('setwise coprime')\nelse:\n print('no coprime')", "from math import gcd\n\nn = int(input())\na = list(map(int, input().split()))\n\nchecker = [0 for _i in range(10**6+1)]\nfor i in a:\n checker[i] += 1\n\nif all(sum(checker[i::i])<2 for i in range(2,10**6+1)):\n print('pairwise coprime')\nelse:\n r = a[0]\n for i in a:\n r = gcd(r, i)\n if r == 1:\n print('setwise coprime')\n else:\n print('not coprime')"] | ['Wrong Answer', 'Accepted'] | ['s060417644', 's164370392'] | [127464.0, 132728.0] | [1217.0, 626.0] | [624, 377] |
p02574 | u414050834 | 2,000 | 1,048,576 | 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. | ["import math\nfrom functools import reduce\nk=10**6+1\ndef judge(n,a):\n c=[0]**k\n for x in a:\n c[x]=+1\n t=any(sum(c[i::i])>1 for i in range(2,k))\n t+=reduce(gcd,a)>1\n return ['pairwise','setwise','not'][t]+' coprime'\nn=int(input())\na=list(map(int,input().split()))\nprint(judge(n,a))", "from math import gcd\nfrom functools import reduce\nk=10**6+1\ndef judge(n,a):\n c=[0]*k\n for x in a:\n c[x]+=1 \n t=any(sum(c[i::i])>1 for i in range(2,k)) \n t+=reduce(gcd,a)>1 \n return ['pairwise','setwise','not'][t]+' coprime' \nn=int(input())\na=list(map(int,input().split()))\nprint(judge(n,a))\n"] | ['Runtime Error', 'Accepted'] | ['s316024098', 's928939056'] | [133008.0, 133172.0] | [250.0, 627.0] | [286, 614] |
p02574 | u423624748 | 2,000 | 1,048,576 | 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. | ['#include<bits/stdc++.h>\n\ntemplate<uint32_t N = 10\'000\'000>\nstruct Sieve_of_Eratosthenes{\n using u32 = uint32_t;\n std::vector<u32> factor;\n Sieve_of_Eratosthenes(){\n factor.resize(N+1);\n for(u32 p=2;p<=N;++p){\n if(factor[p])continue;\n factor[p] = p;\n for(u32 x=p+p;x<=N;x+=p){\n if(factor[x])continue;\n factor[x] = p;\n }\n }\n }\n std::vector<u32> prime_factor(u32 x){\n std::vector<u32> pf;\n while(factor[x]){\n pf.push_back(factor[x]);\n while(factor[x]==pf.back())x/=factor[x];\n }\n return pf;\n }\n};\n\nsigned main(){\n using namespace std;\n cin.tie(0);\n ios::sync_with_stdio(false);\n\n int n;\n cin>>n;\n vector<int> a(n);\n for(auto& ai:a)cin>>ai;\n\n constexpr int a_max = 1e6;\n Sieve_of_Eratosthenes ushi;\n\n map<int,int> mp;\n bool pairwise_coprime = true;\n bool setwise_coprime = accumulate(begin(a),end(a),0,[](auto a,auto b){return gcd(a,b);}) == 1;\n\n for(auto const& ai:a){\n for(auto const& p:ushi.prime_factor(ai)){\n if(mp.count(p)){\n pairwise_coprime = false;\n goto loopend;\n }\n mp[p]++;\n }\n }\nloopend:\n\n if(pairwise_coprime){\n cout<<"pairwise coprime"<<endl;\n }\n else if(setwise_coprime){\n cout<<"setwise coprime"<<endl;\n }\n else{\n cout<<"not coprime"<<endl;\n }\n\n\n}', "from math import gcd\nmax_a = int(2e6)\nfactor = [0]*max_a\nfor p in range(2,max_a):\n if factor[p]:\n continue\n factor[p] = p\n for x in range(p+p,max_a,p):\n if factor[x]:\n continue\n factor[x] = p\n\ndef prime_fac(ai):\n while factor[ai]:\n yield factor[ai]\n x = factor[ai]\n while x == factor[ai]:\n ai = int(ai/factor[ai])\n\nn = int(input())\na = list(map(int,input().split()))\n\ncnt = [0]*max_a\nloop_end = False\ng = 0\npairwise_coprime = True\nsetwise_coprime = True\n\nfor ai in a:\n for p in prime_fac(ai):\n if cnt[p]:\n pairwise_coprime = False\n loop_end = True\n cnt[p] = 1\n if loop_end:\n break\n if loop_end:\n break\n\nfor ai in a:\n g = gcd(g,ai)\nsetwise_coprime = g==1\n\nif pairwise_coprime:\n print('pairwise coprime')\nelif setwise_coprime:\n print('setwise coprime')\nelse:\n print('not coprime')"] | ['Runtime Error', 'Accepted'] | ['s136342203', 's711645435'] | [9012.0, 147088.0] | [29.0, 1245.0] | [1295, 843] |
p02574 | u437215432 | 2,000 | 1,048,576 | 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. | ["def GCD(m, n):\n while n != 0:\n m, n = n, m % n\n return m\n\ndef f(a):\n n = len(a)\n pairwise_coprime = True\n for i in range(n - 1):\n for j in range(i + 1, n):\n if GCD(a[i], a[j]) != 1:\n pairwise_coprime = False\n break\n if pairwise_coprime == False:\n break\n gcd = a[0]\n for i in range(1, n):\n gcd = GCD(gcd, a[i])\n if pairwise_coprime == False and gcd == 1:\n return 'setwise coprime'\n elif pairwise_coprime:\n return 'pairwise coprime'\n else:\n return 'not coprime'\n\nn = int(input())\na = list(map(int, input().split()))\n", "def GCD(m, n):\n while n != 0:\n m, n = n, m % n\n return m\n\ndef gcd_all(a):\n n = len(a)\n gcd = a[0]\n for i in range(1, n):\n gcd = GCD(gcd, a[i])\n return gcd\n\ndef f(a):\n mx = 10**6\n p = set([])\n sieve = [i for i in range(mx + 1)]\n for i in range(2, int(mx**0.5 + 1)):\n for j in range(2 * i, mx + 1, i):\n if sieve[j] > i:\n sieve[j] = i\n pairwise_coprime = True\n for i in a:\n p2 = set([])\n while i > 1:\n p2.add(sieve[i])\n i //= sieve[i]\n for j in p2:\n if j in p:\n pairwise_coprime = False\n break\n p.add(j)\n if pairwise_coprime == False:\n break\n gcd = gcd_all(a)\n if pairwise_coprime == False and gcd == 1:\n return 'setwise coprime'\n elif pairwise_coprime:\n return 'pairwise coprime'\n else:\n return 'not coprime'\n\nn = int(input())\na = list(map(int, input().split()))\nprint(f(a))\n"] | ['Wrong Answer', 'Accepted'] | ['s083322313', 's004647831'] | [127156.0, 127300.0] | [244.0, 902.0] | [645, 1002] |
p02574 | u475402977 | 2,000 | 1,048,576 | 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. | ["def gcd(x, y):\n if y == 0:\n return x\n else:\n return gcd(y, x % y)\n\ndef factorization(n):\n arr = []\n temp = n\n for i in range(2, int(-(-n**0.5//1))+1):\n if temp%i==0:\n cnt=0\n while temp%i==0:\n cnt+=1\n temp //= i\n arr.append(i)\n\n if temp!=1:\n arr.append(temp)\n\n return arr\n\nN=int(input())\nA=list(map(int, input().split()))\np=1\nA=sorted(A)\nnum1=A.count(1)\nB=list(set(A))\nif len(B)<len(A)-num1+1:\n p=0\nS=set(factorization(B[0]))\nT=set(factorization(B[0]))\nflg=0\nfor i in range(1,len(B)):\n prime=set(factorization(B[i])\n if T&prime!=set():\n flg=1\n S=S&prime\n T=T|prime #print(S,T)\nif S!=1:\n print('not coprime')\nelif flg==1 or p=0:\n print('setwise coprime')\nelse:\n print('pairwise coprime')\n", "from math import gcd\nfrom functools import reduce\n\ndef make_prime_table(n):\n sieve = list(range(n + 1))\n sieve[0] = -1\n sieve[1] = -1\n for i in range(4, n + 1, 2):\n sieve[i] = 2\n for i in range(3, int(n ** 0.5) + 1, 2):\n if sieve[i] != i:\n continue\n for j in range(i * i, n + 1, i * 2):\n if sieve[j] == j:\n sieve[j] = i\n return sieve\n\n\ndef prime_factorize(n):\n result = []\n while n != 1:\n p = prime_table[n]\n e = 0\n while n % p == 0:\n n //= p\n e += 1\n result.append((p, e)) \n return result\n\n\ndef f():\n s = set()\n for i in range(N):\n t = prime_factorize(A[i])\n for p, _ in t:\n if p in s:\n return False\n s.add(p)\n return True\n\n\nN=int(input())\nA=list(map(int, input().split()))\n\nprime_table = make_prime_table(10 ** 6)\nif f():\n print('pairwise coprime')\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\nelse:\n print('not coprime')\n"] | ['Runtime Error', 'Accepted'] | ['s113660434', 's166425838'] | [9000.0, 127712.0] | [27.0, 531.0] | [832, 1076] |
p02574 | u512212329 | 2,000 | 1,048,576 | 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. | ["from math import gcd\nfrom functools import reduce\nfrom collections import defaultdict\n\n\ndef facs(n):\n \n yield 2\n for x in range(3, n, 2):\n yield x\n\n\ndef main():\n input() # N\n array = [int(x) for x in input().split()]\n MAX_A = 10 ** 6 + 1\n histogram = defaultdict(int)\n for x in array:\n histogram[x] += 1\n\n for potential_prime in facs(MAX_A):\n count = sum(\n histogram[divider]\n for divider in range(potential_prime, MAX_A, potential_prime))\n if count > 1:\n break\n else:\n return 'pairwise coprime'\n\n gcd_total = reduce(gcd, array)\n if gcd_total == 1:\n return 'setwise coprime'\n else:\n return 'not coprime'\n\n\nif __name__ == '__main__':\n print(main())\n", "from math import gcd\nfrom functools import reduce\n\n\ndef facs(n):\n \n yield 2\n for x in range(3, n, 2):\n yield x\n\n\ndef main():\n input() # N\n array = [int(x) for x in input().split()]\n MAX_A = 10 ** 6 + 1\n histogram = [0] * MAX_A\n for x in array:\n histogram[x] += 1\n\n for divider in facs(MAX_A):\n count = sum(histogram[divider::divider])\n if count > 1:\n break\n else:\n return 'pairwise coprime'\n\n gcd_total = reduce(gcd, array)\n if gcd_total == 1:\n return 'setwise coprime'\n else:\n return 'not coprime'\n\n\nif __name__ == '__main__':\n print(main())\n"] | ['Time Limit Exceeded', 'Accepted'] | ['s726199932', 's988135092'] | [133320.0, 133152.0] | [2144.0, 431.0] | [833, 706] |
p02574 | u522293645 | 2,000 | 1,048,576 | 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. | ["from math import gcd \n# --------------------------------------------------------------\n\n\n\n# prs = []\n# is_prime = [True] * (n + 1)\n# is_prime[0] = False\n# is_prime[1] = False\n\n# if not is_prime[i]:\n# continue\n# for j in range(i*2, n+1, i):\n# is_prime[j] = False\n\n# if is_prime[i]:\n# prs.append(i)\n# return prs\n\nn = int(input())\nlis = list(map(int,input().split()))\nA = 10**6\nnlis = [0]*A\nflg_pairwise = True\n\nfor i in range(n):\n nlis[lis[i]-1] += 1\n\nfor i in range(1,A):\n cnt = 0\n for j in range(i-1,A,i):\n cnt += nlis[j]\n if cnt > 1:\n flg_pairwise = False\n break\n\nif flg_pairwise:\n print('pairwise coprime')\nelse:\n for i in range(n-1):\n if i==0:\n tmp = gcd(lis[i],lis[i+1])\n else:\n tmp = gcd(tmp,lis[i+1])\n\n if tmp==1:\n print('setwise coprime')\n else:\n print('not coprime')", "from math import gcd \n# --------------------------------------------------------------\n\n\n\n# prs = []\n# is_prime = [True] * (n + 1)\n# is_prime[0] = False\n# is_prime[1] = False\n\n# if not is_prime[i]:\n# continue\n# for j in range(i*2, n+1, i):\n# is_prime[j] = False\n\n# if is_prime[i]:\n# prs.append(i)\n# return prs\n\nn = int(input())\nlis = list(map(int,input().split()))\nA = 10**6\nnlis = [0]*A\nflg_pairwise = True\n\nfor i in range(n):\n nlis[lis[i]-1] += 1\n\nfor i in range(A):\n cnt = 0\n for j in range(i-1,A,i):\n cnt += nlis[j]\n if cnt > 1:\n flg_pairwise = False\n break\n\nif flg_pairwise:\n print('pairwise coprime')\nelse:\n for i in range(n-1):\n if i==0:\n tmp = gcd(lis[i],lis[i+1])\n else:\n tmp = gcd(tmp,lis[i+1])\n\n if tmp==1:\n print('setwise coprime')\n else:\n print('not coprime')", "from fractions import gcd \n# from fractions import Fraction\n# from math import gcd # <Python3.5\n# --------------------------------------------------------------\n\nn = int(input())\nlis = map(int,input().split())\n\nnow = 0\ntotal = 0\n\nflg1 = 0\nflg2 = 0\n\nfor i in range(n-1):\n if i>0:\n total = gcd(now,i+1)\n now = gcd(i,i+1)\n \n if now != 1:\n flg1 = 1\n if total==1:\n flg2 = 1\n\nif flg1==1:\n print('pairwise coprime')\nelif flg2==1:\n print('setwise coprime')\nelse:\n print('not coprime')", "from math import gcd \n# --------------------------------------------------------------\n\n\ndef primes(n):\n prs = []\n is_prime = [True] * (n + 1)\n is_prime[0] = False\n is_prime[1] = False\n for i in range(2, int(n**0.5)+1):\n if not is_prime[i]:\n continue\n for j in range(i*2, n+1, i):\n is_prime[j] = False\n for i in range(len(is_prime)):\n if is_prime[i]:\n prs.append(i)\n return prs\n\nn = int(input())\nlis = list(map(int,input().split()))\nsoin = [0]*(10**6)\ncnt = 0\nans = 'pairwise coprime'\n\nfor i in range(n):\n soin[lis[i]] += 1\n\nfor i in primes(10**6):\n for j in range(1,10**6):\n if i*j >= 10**6:\n break\n cnt += soin[i*j]\n if cnt > 1:\n ans = 'not coprime'\n break\n\nfor i in range(n-1):\n if i==0:\n tmp = gcd(lis[i],lis[i+1])\n else:\n tmp = gcd(tmp,lis[i+1])\n\nif tmp==1:\n ans = 'setwise coprime'\n\nprint(ans)", "from math import gcd \n# --------------------------------------------------------------\n\n\ndef primes(n):\n prs = []\n is_prime = [True] * (n + 1)\n is_prime[0] = False\n is_prime[1] = False\n for i in range(2, int(n**0.5)+1):\n if not is_prime[i]:\n continue\n for j in range(i*2, n+1, i):\n is_prime[j] = False\n for i in range(len(is_prime)):\n if is_prime[i]:\n prs.append(i)\n return prs\n\nn = int(input())\nlis = list(map(int,input().split()))\nA = 10**6\nnlis = [0]*A\nflg_pairwise = True\n\nfor i in range(n):\n nlis[lis[i]-1] += 1\n\nfor i in primes(A):\n cnt = 0\n for j in range(i-1,A,i):\n cnt += nlis[j]\n if cnt > 1:\n flg_pairwise = False\n break\n\nif flg_pairwise:\n print('pairwise coprime')\nelse:\n for i in range(n-1):\n if i==0:\n tmp = gcd(lis[i],lis[i+1])\n else:\n tmp = gcd(tmp,lis[i+1])\n\n if tmp==1:\n print('setwise coprime')\n else:\n print('not coprime')"] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s229926340', 's235732113', 's915672683', 's956907481', 's679482077'] | [132624.0, 132628.0, 90916.0, 134644.0, 132024.0] | [730.0, 420.0, 1959.0, 1189.0, 864.0] | [1097, 1095, 579, 1013, 1068] |
p02574 | u523087093 | 2,000 | 1,048,576 | 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. | ["import math\nL = 10**6 + 1\n\nN = int(input())\nA = list(map(int, input().split()))\nmemo = [0] * L\nflag = 0 \n\nfor a in A:\n memo[a] = 1\n\nfor i in range(2, L):\n if sum(memo[i::i]) > 1:\n flag = 1:\n break\n\ng = 0\nfor i in range(N):\n g = math.gcd(g, A[i])\n\nif flag == 0:\n answer = 'pairwise coprime'\nelif flag == 1 and g == 1:\n answer = 'setwise coprime'\nelse:\n answer = 'not coprime'\n\nprint(answer)", "import math\nL = 10**6 + 1\n\nN = int(input())\nA = list(map(int, input().split()))\nmemo = [0] * L\nflag = 0 \n\nfor a in A:\n memo[a] += 1\n\nfor i in range(2, L):\n if sum(memo[i::i]) > 1:\n flag = 1\n break\n\ng = 0\nfor i in range(N):\n g = math.gcd(g, A[i])\n\nif flag == 0:\n answer = 'pairwise coprime'\nelif flag == 1 and g == 1:\n answer = 'setwise coprime'\nelse:\n answer = 'not coprime'\n\nprint(answer)"] | ['Runtime Error', 'Accepted'] | ['s309126061', 's702629402'] | [9044.0, 127624.0] | [24.0, 862.0] | [443, 443] |
p02574 | u546338822 | 2,000 | 1,048,576 | 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. | ['def main():\n import math\n n = int(input())\n a = sorted(list(map(int,input().split())))\n g=a[0]\n for i in range(1,n):\n g = math.gcd(g,a[i])\n if g > 1:\n print(\'not coprime\')\n return\n d = [1 for i in range(a[-1])]\n for i in range(2,a[-1]):\n if d[i-1] == 1:\n for j in range(1,a[-1]//i+1):\n if d[i*j-1] == 1:\n d[i*j-1] = i\n prm = [0 for i in range(a[-1])]\n for i in range(n):\n p = []\n while a[i] != 1:\n p.append(d[a[i]-1])\n a[i] = a[i] // d[a[i]-1]\n p = set(p)\n for p_ in p:\n prm[p_-1] += 1\n for i in range(1,len(prm)):\n if prm[i]>1:\n print(\'setwise coprime\')\n return\n print(\'pairwise coprime\')\n\nif __name__ == "__main__":\n main()\n', 'def main():\n import math\n n = int(input())\n a = sorted(list(map(int,input().split())))\n g=a[0]\n for i in range(1,n):\n g = math.gcd(g,a[i])\n if g > 1:\n print(\'not coprime\')\n return\n d = [1 for i in range(a[-1])]\n for i in range(2,a[-1]):\n if d[i-1] == 1:\n for j in range(1,a[-1]//i+1):\n if d[i*j-1] == 1:\n d[i*j-1] = i\n cnt = [0 for i in range(a[-1]+1)]\n flg = 0\n for i in range(n):\n cnt[d[a[i]-1]] += 1\n if cnt[d[a[i]-1]] != 0:\n flg = 1\n break\n if flg == 1:\n print(\'setwise coprime\')\n return\n print(\'pairwise coprime\')\n\nif __name__ == "__main__":\n main()\n', 'def main():\n import math\n n = int(input())\n a = sorted(list(map(int,input().split())))\n g=a[0]\n for i in range(1,n):\n g = math.gcd(g,a[i])\n if g > 1:\n print(\'not coprime\')\n return\n d = [1 for i in range(a[-1])]\n for i in range(2,a[-1]+1):\n if d[i-1] == 1:\n for j in range(1,a[-1]//i+1):\n if d[i*j-1] == 1:\n d[i*j-1] = i\n prm = {}\n for i in range(n):\n p = []\n while a[i] != 1:\n p.append(d[a[i]-1])\n a[i] = a[i] // d[a[i]-1]\n p = set(p)\n for p_ in p:\n if prm.get(p_)==None:\n prm[p_] = 1\n else:\n print(\'setwise coprime\')\n return\n print(\'pairwise coprime\')\n\nif __name__ == "__main__":\n main()\n'] | ['Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s752440617', 's964161869', 's088071184'] | [126840.0, 134508.0, 126940.0] | [2208.0, 1095.0, 1122.0] | [828, 720, 815] |
p02574 | u547608423 | 2,000 | 1,048,576 | 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. | ['import math\n\nN = int(input())\nA = list(map(int, input().split()))\n\ninf = int(1e6+5)\nC = [0]*inf\n\nfor a in A:\n C[a] += 1\n\npa = True\nse = True\nfor i in range(2, inf):\n cnt = 0\n for j in range(i, inf, i):\n cnt += C[j]\n if cnt > 1:\n pa = False\n if cnt == N:\n se = False\n \nif pa:\n print("pairwise coprime")\nelif se:\n print("setwise coprime")\nelse:\n print("not coprime")\n', 'import math\n\nN = int(input())\nA = list(map(int, input().split()))\n\ninf = int(1e6+5)\nC = [0]*inf\n\nfor a in A:\n C[a] += 1\n\npa = True\nse = True\nfor i in range(2, inf):\n cnt = 0\n cnt += sum(C[i::i])\n if cnt > 1:\n pa = False\n if cnt == N:\n se = False\n \nif pa:\n print("pairwise coprime")\nelif se:\n print("setwise coprime")\nelse:\n print("not coprime")\n'] | ['Time Limit Exceeded', 'Accepted'] | ['s665956323', 's187067671'] | [132816.0, 132612.0] | [2208.0, 860.0] | [417, 390] |
p02574 | u564589929 | 2,000 | 1,048,576 | 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. | ["import sys\nsys.setrecursionlimit(10 ** 9)\n# input = sys.stdin.readline ####\ndef int1(x): return int(x) - 1\ndef II(): return int(input())\ndef MI(): return map(int, input().split())\ndef MI1(): return map(int1, input().split())\ndef LI(): return list(map(int, input().split()))\ndef LI1(): return list(map(int1, input().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef MS(): return input().split()\ndef LS(): return list(input())\ndef LLS(rows_number): return [LS() for _ in range(rows_number)]\ndef printlist(lst, k=' '): print(k.join(list(map(str, lst))))\nINF = float('inf')\n# from math import ceil, floor, log2\nfrom collections import deque, defaultdict\n# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations\n# from heapq import heapify, heappop, heappush\n# import numpy as np # cumsum\n\n\nfrom math import gcd\n\ndef solve():\n N = II()\n A = LI()\n \n mx = 1000003\n D = [1] * mx\n for i in range(2, mx):\n if D[i] != 1:\n continue\n for j in range(i, mx, i):\n if D[j] == 1:\n D[j] = i\n # print(D)\n # print(D[4], D[6], D[35])\n\n g = A[0]\n dct = defaultdict(int)\n flag = True\n for a in A:\n g = gcd(g, a)\n # print(a, D[a])\n if D[a] != 1:\n if dct[D[a]] > 0:\n flag = False\n dct[D[a]] += 1\n # print(dct, flag, g)\n flag = False\n if g == 1:\n if flag:\n print('pairwise coprime')\n else:\n print('setwise coprime')\n else:\n print('not coprime')\n\n\nif __name__ == '__main__':\n solve()\n\n", "import sys\nsys.setrecursionlimit(10 ** 9)\n# input = sys.stdin.readline ####\ndef int1(x): return int(x) - 1\ndef II(): return int(input())\ndef MI(): return map(int, input().split())\ndef MI1(): return map(int1, input().split())\ndef LI(): return list(map(int, input().split()))\ndef LI1(): return list(map(int1, input().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef MS(): return input().split()\ndef LS(): return list(input())\ndef LLS(rows_number): return [LS() for _ in range(rows_number)]\ndef printlist(lst, k=' '): print(k.join(list(map(str, lst))))\nINF = float('inf')\n# from math import ceil, floor, log2\nfrom collections import deque, defaultdict\n# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations\n# from heapq import heapify, heappop, heappush\n# import numpy as np # cumsum\n\n\nfrom math import gcd\n\ndef solve():\n N = II()\n A = LI()\n \n mx = 1000003\n D = [1] * mx\n for i in range(2, len(D)):\n # if D[i] != 1:\n # continue\n for j in range(i, len(D), i):\n if D[j] == 1:\n D[j] = i\n # print(D[mx-3])\n # print(D[4], D[6], D[35])\n\n g = A[0]\n \n \n C = [0] * mx\n for a in A:\n g = gcd(g, a)\n # print(a, D[a])\n # if D[a] != 1:\n \n \n # dct[D[a]] += 1\n d = D[a]\n C[d] += 1\n # print(dct, flag, g)\n \n if all(C[i] <= 1 for i in range(2, len(C))):\n flag = True\n else:\n flag = False\n\n if g == 1:\n if flag:\n print('pairwise coprime')\n else:\n print('setwise coprime')\n else:\n print('not coprime')\n\n\nif __name__ == '__main__':\n solve()\n\n", "import sys\nsys.setrecursionlimit(10 ** 9)\n# input = sys.stdin.readline ####\ndef int1(x): return int(x) - 1\ndef II(): return int(input())\ndef MI(): return map(int, input().split())\ndef MI1(): return map(int1, input().split())\ndef LI(): return list(map(int, input().split()))\ndef LI1(): return list(map(int1, input().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef MS(): return input().split()\ndef LS(): return list(input())\ndef LLS(rows_number): return [LS() for _ in range(rows_number)]\ndef printlist(lst, k=' '): print(k.join(list(map(str, lst))))\nINF = float('inf')\n# from math import ceil, floor, log2\nfrom collections import deque, defaultdict\n# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations\n# from heapq import heapify, heappop, heappush\n# import numpy as np # cumsum\n\n\nfrom math import gcd\n\ndef solve():\n N = II()\n A = LI()\n \n mx = 1000003\n D = [1] * mx\n for i in range(2, len(D)):\n if D[i] != 1:\n continue\n for j in range(i, len(D), i):\n if D[j] == 1:\n D[j] = i\n\n \n # d = D[x]\n \n # while x != d:\n # x = x // d\n # d = D[x]\n \n \n \n\n g = A[0]\n dct = defaultdict(int)\n flag = True\n for a in A:\n g = gcd(g, a)\n # print(a, D[a])\n # if D[a] != 1:\n \n \n # dct[D[a]] += 1\n \n d = D[a]\n p = a\n \n while p != d:\n p = p // d\n d = D[p]\n\n if p != 1:\n dct[p] += 1\n if dct[p] > 1:\n flag = False\n\n if g == 1:\n if flag:\n print('pairwise coprime')\n else:\n print('setwise coprime')\n else:\n print('not coprime')\n\n\nif __name__ == '__main__':\n solve()\n\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s499231420', 's551536208', 's799840454'] | [127584.0, 127772.0, 127868.0] | [776.0, 1372.0, 1345.0] | [1704, 1889, 2140] |
p02574 | u585963734 | 2,000 | 1,048,576 | 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. | ["from math import gcd\n\nN=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)\nD=[0]*(c+1)\ndiv=[0]*(c+1)\nP=[]\n\nfor i in range(2,c+1):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>c or j>D[i] :\n break\n D[i*j]=j\nf=0\nfor i in A:\n if c>1:\n c=gcd(c,i)\n if i==1:\n continue\n temp=i\n print(temp,D[temp])\n if temp==D[temp]:\n div[temp]+=1\n\n# f=1\n# continue\n while temp!=D[temp]:\n div[D[temp]]+=1\n if div[temp]>=2:\n f=1\n temp=temp//D[temp]\n# if c==1 and f==1:\n# break\n\nif max(div)<=1:\n print('pairwise coprime')\n\nelif c==1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "from functools import reduce\nfrom math import gcd\n\nN=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)+1\nD=[0]*c\ndiv=[0]*c\nP=[]\n\nfor i in range(2,c):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>=c or j>D[i] :\n break\n D[i*j]=j\ng=c\nf=0\nfor i in A:\n if i==1:\n continue\n temp=i\n if temp==D[temp]:\n if div[D[temp]]>=1:\n f=1\n break\n div[D[temp]]+=1\n continue\n while temp!=D[temp]:\n if div[D[temp]]>=1:\n f=1\n break\n div[D[temp]]+=1\n temp=temp//D[temp]\n if div[temp]>=1:\n f=1\n break\n\n div[temp]+=1\n\n if f==1:\n break\n\n\nif f==0:\n print('pairwise coprime')\n\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "from functools import reduce\nfrom math import gcd\n\nN=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)+1\nD=[0]*c\ndiv=[0]*c\nP=[]\n\nfor i in range(2,c):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>=c or j>D[i] :\n break\n D[i*j]=j\n\nfor i in A:\n if i==1:\n continue\n temp=i\n pt=[]\n while temp!=1:\n if temp not in pt:\n div[D[temp]]+=1\n pt.append(D[temp])\n temp=temp//D[temp]\n\nprint(div)\n\nif max(div)==1:\n print('pairwise coprime')\n\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "from functools import reduce\nfrom math import gcd\n\nN=int(input())\nA=list(map(int, input().split()))\nc=10**6+1\nC=[0]*c\nf=1\nfor i in A:\n C[i]+=1\n\nfor i in range(2,c):\n cnt=0\n for j in range(i,c,i):\n cnt+=C[j]\n if cnt>1:\n f=0\n\n\nif f==1:\n print('pairwise coprime')\n\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "from functools import reduce\nfrom math import gcd\n\nN=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)+1\nD=[0]*c\ndiv=[0]*c\nP=[]\n\nfor i in range(2,c):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>=c or j>D[i] :\n break\n D[i*j]=j\ng=c\nf=0\nfor i in A:\n if i==1:\n continue\n temp=i\n if temp==D[temp]:\n if div[D[temp]]==1:\n f=1\n break\n div[D[temp]]+=1\n continue\n while temp!=D[temp]:\n if div[D[temp]]==1:\n f=1\n break\n div[D[temp]]+=1\n temp=temp//D[temp]\n if div[D[temp]]==1:\n f=1\n break\n if f==1:\n break\n\nif f==0:\n print('pairwise coprime')\n\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "from functools import reduce\nfrom math import gcd\n\nN=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)+1\nD=[0]*c\ndiv=[0]*c\nP=[]\n\nfor i in range(2,c):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>=c or j>D[i] :\n break\n D[i*j]=j\ng=c\nf=0\nfor i in A:\n if i==1:\n continue\n temp=i\n if temp==D[temp]:\n if div[D[temp]]==1:\n f=1\n break\n div[D[temp]]+=1\n continue\n while temp!=D[temp]:\n if div[D[temp]]==1:\n f=1\n break\n div[D[temp]]+=1\n temp=temp//D[temp]\n if div[temp]==1:\n f=1\n break\n if f==1:\n break\n div[temp]+=1\n\nif f==0:\n print('pairwise coprime')\n\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "from functools import reduce\nfrom math import gcd\n\nN=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)+1\nD=[0]*c\ndiv=[0]*c\nP=[]\n\nfor i in range(2,c):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>=c or j>D[i] :\n break\n D[i*j]=j\ng=c\nf=0\nfor i in A:\n if i==1:\n continue\n temp=i\n if temp==D[temp]:\n if div[D[temp]]==1:\n f=1\n break\n div[D[temp]]+=1\n continue\n while temp!=D[temp]:\n if div[D[temp]]==1:\n f=1\n break\n div[D[temp]]+=1\n temp=temp//D[temp]\n if f==1:\n break\n print(temp)\n if temp!=D[temp] and temp in P:\n div[temp]+=1\n\nprint(div)\n\nif f==0:\n print('pairwise coprime')\n\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "from functools import reduce\nfrom math import gcd\nimport sys\nsys.setrecursionlimit(10**8)\nglobal f\n\n\ndef chk(a):\n global f\n if a==D[a]:\n if div[D[a]]>=1:\n f=1\n return \n div[D[a]]+=1\n return\n while a!=D[a]:\n if div[D[a]]>=1:\n f=1\n return\n div[D[a]]+=1\n chk(a//D[a])\n if a!=D[a] and a in P:\n if div[a]>=1:\n f=1\n return\n div[a]+=1\n\n\nN=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)+1\nD=[0]*c\ndiv=[0]*c\nP=[]\n\nfor i in range(2,c):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>=c or j>D[i] :\n break\n D[i*j]=j\ng=c\nf=0\nfor i in A:\n if i==1:\n continue\n chk(i)\n if f==1:\n break\n\n\n\nif f==0:\n print('pairwise coprime')\n\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "N=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)\nD=[0]*(c+1)\ndiv=[0]*(c+1)\nP=[]\n\nfor i in range(2,c+1):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>c and i>D[j]:\n break\n D[i*j]=j\n\nfor i in A:\n c=gcd(c,i)\n if i==1:\n continue\n temp=i\n if temp==D[temp]:\n div[temp]+=1\n continue\n while temp!=D[temp]:\n div[D[temp]]+=1\n temp=temp//D[temp]\n\nif max(div)<=1:\n print('pairwise coprime')\n\nelif c==1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "from functools import reduce\nfrom math import gcd\n\nN=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)+1\nD=[0]*c\ndiv=[0]*c\nP=[]\n\nfor i in range(2,c):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>=c or j>D[i] :\n break\n D[i*j]=j\ng=c\nf=0\nfor i in A:\n if i==1:\n continue\n temp=i\n if temp==D[temp]:\n if div[D[temp]]>=1:\n f=1\n break\n div[D[temp]]+=1\n continue\n while temp!=D[temp]:\n if div[D[temp]]>=1:\n f=1\n break\n div[D[temp]]+=1\n temp=temp//D[temp]\n if temp in P:\n div[temp]+=1\n \n if f==1:\n break\n\nprint(div)\n\nif f==0:\n print('pairwise coprime')\n\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "from functools import reduce\nfrom math import gcd\n\nN=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)+1\nD=[0]*c\ndiv=[0]*c\nP=[]\n\nfor i in range(2,c):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>=c or j>D[i] :\n break\n D[i*j]=j\n\nfor i in A:\n if i==1:\n continue\n temp=i\n while temp!=1:\n div[D[temp]]+=1\n temp2=D[temp]\n while temp%temp2==0 and temp>=temp2:\n print(temp)\n temp=temp//temp2\n\n\nif max(div)<=1:\n print('pairwise coprime')\n\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\n\nelse:\n print('not coprime')", "from functools import reduce\nfrom math import gcd\n\nN=int(input())\nA=list(map(int, input().split()))\n\nc=max(A)+1\nD=[0]*c\ndiv=[0]*c\nP=[]\n\nfor i in range(2,c):\n if D[i]==0:\n P.append(i)\n D[i]=i\n for j in P:\n if i*j>=c or j>D[i] :\n break\n D[i*j]=j\nf=0\nfor i in A:\n if i==1:\n continue\n temp=i\n while temp!=1:\n if div[D[temp]]==1:\n f=1\n break\n div[D[temp]]+=1\n temp2=D[temp]\n while temp%temp2==0 and temp>=temp2:\n temp=temp//temp2\n if f==1:\n break\n \nif f==0:\n print('pairwise coprime')\n\nelif reduce(gcd, A) == 1:\n print('setwise coprime')\n\nelse:\n print('not coprime')"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Time Limit Exceeded', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s034195640', 's187293528', 's218381912', 's306596581', 's385922707', 's520156210', 's577570275', 's630453702', 's797206024', 's831035037', 's975763738', 's104241688'] | [134788.0, 128032.0, 127840.0, 133024.0, 128136.0, 128192.0, 127832.0, 127980.0, 127220.0, 128116.0, 127800.0, 127640.0] | [2215.0, 808.0, 2207.0, 2156.0, 728.0, 805.0, 900.0, 843.0, 929.0, 821.0, 2224.0, 751.0] | [757, 834, 627, 377, 825, 831, 852, 919, 568, 827, 641, 709] |
Subsets and Splits