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 |
|---|---|---|---|---|---|---|---|---|---|---|
p02762 | u324197506 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import deque\n\nn, m, k = map(int, input().split())\n\nfriends = [[0] * n for _ in range(n)]\n\nblocks = [[0] * n for _ in range(n)]\n\nfor i in range(m):\n a, b = map(int, input().split())\n friends[a-1][b-1] = 1\n friends[b-1][a-1] = 1\n\nfor i in range(k):\n c, d = map(int, input().split())\n blocks[c-1][d-1] = 1\n blocks[d-1][c-1] = 1\n\nfor i in range(n):\n q = deque()\n q.append(i)\n cnt = [-1] * n\n cnt[i] = 0\n total = 0\n while q:\n k = q.popleft()\n for j in range(n):\n if friends[k][j] and cnt[j] == -1:\n q.append(j)\n cnt[j] = cnt[k] + 1\n if cnt[j] > 1 and not blocks[i][j]:\n total += 1\n print(total)', 'from collections import deque\n\nn, m, k = map(int, input().split())\n\n\nfriends = [set() for _ in range(n)]\nblocks = [set() for _ in range(n)]\n\nfor i in range(m):\n a, b = map(int, input().split())\n friends[a-1].add(b-1)\n friends[b-1].add(a-1)\n\nfor i in range(k):\n c, d = map(int, input().split())\n blocks[c-1].add(d-1)\n blocks[d-1].add(c-1)\n\nq = deque()\nans = [0] * n\nvisited = [0] * n\n\nfor i in range(n):\n if visited[i]:\n continue\n \n group = {i}\n visited[i] = 1\n q.append(i)\n while q:\n k = q.popleft()\n for j in friends[k]:\n if not visited[j]:\n q.append(j)\n group.add(j)\n visited[j] = 1\n \n \n for l in group:\n ans[l] = len(group) - len(blocks[l] & group) - len(friends[l] & group) - 1\nprint(*ans)\n#print(*ans,sep="\\n")'] | ['Time Limit Exceeded', 'Accepted'] | ['s344430017', 's412167359'] | [2088940.0, 80692.0] | [2247.0, 1097.0] | [734, 942] |
p02762 | u327532412 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['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\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\n\nfriend =[[] for _ in range(N)]\nblock = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a, b = a-1, b-1\n uf.union(a, b)\n friend[a].append(b)\n friend[b].append(a)\n\nfor i in range(k):\n c, d = map(int, input().split())\n c, d = c-1, d-1\n if uf.same(c, d):\n block[c].append(d)\n block[d].append(c)\nans = [0] * N\nfor i in range(N):\n ans[i] = uf.size(i) - len(friend[i]) - len(block[i]) - 1\nprint(*ans)\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\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\n\nfriend =[[] for _ in range(N)]\nblock = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a, b = a-1, b-1\n uf.union(a, b)\n friend[a].append(b)\n friend[b].append(a)\n\nfor _ in range(K):\n c, d = map(int, input().split())\n c, d = c-1, d-1\n if uf.same(c, d):\n block[c].append(d)\n block[d].append(c)\nans = [0] * N\nfor i in range(N):\n ans[i] = uf.size(i) - len(friend[i]) - len(block[i]) - 1\nprint(*ans)'] | ['Runtime Error', 'Accepted'] | ['s033532664', 's978360560'] | [29872.0, 46864.0] | [668.0, 1422.0] | [1558, 1557] |
p02762 | u346812984 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['class UnionFind:\n def __init__(self, n_nodes):\n self.parent = [i for i in range(n_nodes)]\n self.rank = [0] * n_nodes\n self.size = [1] * n_nodes\n\n def find(self, x):\n if x == self.parent[x]:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[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.rank[x] > self.rank[y]:\n self.parent[y] = x\n self.size[x] += self.size[y]\n else:\n self.parent[x] = y\n self.size[y] += self.size[x]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n def check(self, x, y):\n return self.find(x) == self.find(y)\n\n def get_size(self, x):\n return self.size[self.find(x)]\n\n\nN, M, K = map(int, input().split())\ntree = UnionFind(N)\nexclusion = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n tree.unite(a, b)\n exclusion[a].append(b)\n exclusion[b].append(a)\n\nfor _ in range(K):\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n if not tree.check(c, d):\n continue\n exclusion[c].append(d)\n exclusion[d].append(c)\n\nfor i in range(N):\n \n n = tree.get_size(i) - 1\n ans = n - len(exclusion[i])\n print(ans, end=" ")\n', 'import sys\n\nsys.setrecursionlimit(10 ** 6)\nINF = float("inf")\nMOD = 10 ** 9 + 7\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\nclass UnionFind:\n def __init__(self, n_nodes):\n self.n_nodes = n_nodes\n\n \n \n self.parents = [-1] * n_nodes\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 \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\n def get_size(self, x):\n return -self.parents[self.find(x)]\n\n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n\n def get_members(self, x):\n parent = self.find(x)\n return [i for i in range(self.n_nodes) if self.find(i) == parent]\n\n def get_parent_list(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def get_n_groups(self):\n return len(self.get_parent_list())\n\n def get_members_dict(self):\n return {par: self.get_members(par) for par in self.get_parent_list()}\n\n\ndef main():\n N, M, K = map(int, input().split())\n tree = UnionFind(N)\n\n friends = [[] for _ in range(N)]\n for _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n tree.unite(a, b)\n friends[a].append(b)\n friends[b].append(a)\n\n ng = [[] for _ in range(N)]\n for _ in range(K):\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n ng[c].append(d)\n ng[d].append(c)\n\n ans = []\n for i in range(N):\n n_ng = 0\n for j in ng[i]:\n if tree.is_same(i, j):\n n_ng += 1\n\n n_member = tree.get_size(i)\n n_friends = len(friends[i])\n \n ans.append(n_member - n_friends - n_ng - 1)\n\n print(*ans, sep=" ")\n\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s855633051', 's429758103'] | [33584.0, 46848.0] | [1582.0, 1072.0] | [1461, 2446] |
p02762 | u347184682 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n,m,k=[int(x) for x in input().rstrip().split()]\nl=[[] for i in range(n)]\nfor i in range(m):\n a,b=[int(x) for x in input().rstrip().split()]\n l[a-1].append(b-1)\n l[b-1].append(a-1)\n\ndone=[0 for i in range(n)]\nans=[0 for i in range(n)]\n\ndef bfs(i):\n cnt=0\n moment=str(i)\n que=[i]\n done[i]=1\n while(que):\n now=que.pop(0)\n cnt+=1\n for j in l[now]:\n if done[j]!=1:\n done[j]=1\n moment+=str(j)\n que.append(j)\n\n for j in moment:\n if ans[int(j)]==0:\n ans[int(j)]=cnt\n\nfor i in range(n):\n if ans[i]==0:\n bfs(i)\n\nfor i in range(n):\n ans[i] -= (len(l[i])+1)\n\nfor i in range(k):\n c,d=[int(x) for x in input().rstrip().split()]\n if ans[c-1]==ans[d-1]:\n if ans[c-1]!=0:\n ans[c-1]-=1\n \n if ans[d-1]!=0: \n ans[d-1]-=1\n\nprint(*ans)', 'from collections import deque\nn , m , k = map(int,input().split())\ntomo = [set() for i in range(n+1)]\nto = [0 for i in range(n+1)]\nbro = [set() for i in range(n+1)]\nfor i in range(m):\n a , b = map(int,input().split())\n tomo[a].add(b)\n tomo[b].add(a)\n to[a] += 1\n to[b] += 1\nfor i in range(k):\n c , d = map(int,input().split())\n bro[c].add(d)\n bro[d].add(c)\n\nvisit = [True for i in range(n+1)]\nkurasuta = []\nfor i in range(1,n+1):\n if visit[i]:\n kar = {i}\n d = deque()\n d.append(i)\n cou = 1\n visit[i] = False\n while d:\n now = d.popleft()\n for j in tomo[now]:\n if visit[j]:\n visit[j] = False\n kar.add(j)\n d.append(j)\n cou += 1\n kurasuta.append([kar,cou])\n else:\n continue\nans = [0 for i in range(n)]\n\nfor i in range(len(kurasuta)):\n for j in kurasuta[i][0]:\n ans[j-1] = kurasuta[i][1] - to[j] - 1 - len(kurasuta[i][0] & bro[j])\n\nprint(*ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s773694712', 's097101238'] | [25712.0, 112828.0] | [2105.0, 1297.0] | [797, 1048] |
p02762 | u354126779 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n,m,k=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)\nC=[]\nD=[]\nfor i in range(k):\n c,d=map(int,input().split())\n C.append(c)\n D.append(d)\nunion=[]\nfor i in range(n):\n br=0\n for j in range(len(union)):\n if i+1 in set(union[j]):\n br=1\n break\n if br==1:\n continue\n fri=[i+1]\n mark=[0]\n while 0 in set(mark):\n for s in range(len(fri)):\n if mark[s]==0:\n for t in range(m):\n if A[t]==fri[s] and B[t] not in set(fri):\n fri.append(B[t])\n mark.append(0)\n if B[t]==fri[s] and A[t] not in set(fri):\n fri.append(A[t])\n mark.append(0)\n mark[s]=1\n union.append(fri)\ncounter=[]\nfor i in range(n):\n counter.append(0)\n\nfor i in range(m):\n counter[A[i]-1]+=1\n counter[B[i]-1]+=1\nfor i in range(k):\n for j in range(len(union)):\n if C[i] in union[j] and D[i] in union[j]:\n counter[C[i]-1]+=1\n counter[D[i]-1]+=1\n break\n\nfor i in range(n):\n for j in range(len(union)):\n if i+1 in union[j]:\n print(len(union[j])-counter[i]-1,end=" ")\n break', 'import sys\n\nsys.setrecursionlimit(10**7)\n\ndef dfs(x):\n if seen[x-1]==0:\n uni[cnt].append(x)\n seen[x-1]=1\n for i in fri[x-1]:\n dfs(i)\n \n\nn,m,k=map(int,input().split())\n\nfri=[[] for i in range(n)]\nblk=[[] for i in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n fri[a-1].append(b)\n fri[b-1].append(a)\n\nfor i in range(k):\n c,d=map(int,input().split())\n blk[c-1].append(d)\n blk[d-1].append(c)\n\n\nseen=[0 for i in range(n)]\n\nuni=[]\ncnt=0\nfor i in range(1,n+1):\n if seen[i-1]==0:\n uni.append([])\n dfs(i)\n cnt+=1\n\nseq=[0 for i in range(n)]\n\nprint(*seq)\n', 'n,m,k=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)\nC=[]\nD=[]\nfor i in range(k):\n c,d=map(int,input().split())\n C.append(c)\n D.append(d)\nunion=[]\nfor i in range(n):\n br=0\n for j in range(len(union)):\n if i+1 in set(union[j]):\n br=1\n break\n if br==1:\n continue\n fri=[i+1]\n mark=[0]\n while 0 in set(mark):\n for s in range(len(fri)):\n if mark[s]==0:\n for t in range(m):\n if A[t]==fri[s] and B[t] not in set(fri):\n fri.append(B[t])\n mark.append(0)\n if B[t]==fri[s] and A[t] not in set(fri):\n fri.append(A[t])\n mark.append(0)\n mark[s]=1\n union.append(fri)\nunionsize=[]\nfor i in range(len(union)):\n unionsize.append(len(union[i]))\ncounter=[]\nfor i in range(n):\n counter.append(0)\n\nfor i in range(m):\n counter[A[i]-1]+=1\n counter[B[i]-1]+=1\nfor i in range(k):\n for j in range(len(union)):\n if C[i] in union[j] and D[i] in union[j]:\n counter[C[i]-1]+=1\n counter[D[i]-1]+=1\n break\n\nfor i in range(n):\n for j in range(len(union)):\n if i+1 in union[j]:\n print(unionsize[j]-counter[i]-1,end=" ")\n break', 'import sys\n\nsys.setrecursionlimit(10**7)\n\ndef dfs(x):\n if seen[x-1]==0:\n uni[cnt].add(x)\n seen[x-1]=1\n for i in fri[x-1]:\n dfs(i)\n \n\nn,m,k=map(int,input().split())\n\nfri=[[] for i in range(n)]\nblk=[set() for i in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n fri[a-1].append(b)\n fri[b-1].append(a)\n\nfor i in range(k):\n c,d=map(int,input().split())\n blk[c-1].add(d)\n blk[d-1].add(c)\n\n\nseen=[0 for i in range(n)]\n\nuni=[]\ncnt=0\nfor i in range(1,n+1):\n if seen[i-1]==0:\n uni.append(set())\n dfs(i)\n cnt+=1\n\nseq=[0 for i in range(n)]\n\nprint(*seq)', 'import sys\n\nsys.setrecursionlimit(10**7)\n\ndef dfs(x):\n if seen[x-1]==0:\n uni[cnt].append(x)\n seen[x-1]=1\n for i in fri[x-1]:\n dfs(i)\n \n\nn,m,k=map(int,input().split())\n\nfri=[[] for i in range(n)]\nblk=[[] for i in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n fri[a-1].append(b)\n fri[b-1].append(a)\n\nfor i in range(k):\n c,d=map(int,input().split())\n blk[c-1].append(d)\n blk[d-1].append(c)\n\n\nseen=[0 for i in range(n)]\n\nuni=[]\ncnt=0\nfor i in range(1,n+1):\n if seen[i-1]==0:\n uni.append([])\n dfs(i)\n cnt+=1\n\nseq=[0 for i in range(n)]\n\nfor unii in uni:\n for j in unii:\n cj=len(unii)-len(fri[j-1])-len(set(unii)&set(blk[j-1])-1\n seq[j-1]=cj\n\nprint(*seq)', 'n,m,k=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)\nC=[]\nD=[]\nfor i in range(k):\n c,d=map(int,input().split())\n C.append(c)\n D.append(d)\nseq=[]\nfor i in range(n):\n fri=[i+1]\n mark=[0]\n while 0 in set(mark):\n for s in range(len(fri)):\n if mark[s]==0:\n for t in range(m):\n if A[t]==fri[s] and B[t] not in set(fri):\n fri.append(B[t])\n mark.append(0)\n if B[t]==fri[s] and A[t] not in set(fri):\n fri.append(A[t])\n mark.append(0)\n mark[s]=1\n fri.remove(i+1)\n for t in range(m):\n if A[t]==i+1:\n fri.remove(B[t])\n if B[t]==i+1:\n fri.remove(A[t])\n for s in range(k):\n if C[s]==i+1 and D[s] in set(fri):\n fri.remove(D[s])\n for s in range(k):\n if D[s]==i+1 and C[s] in set(fri):\n fri.remove(C[s])\n seq.append(len(fri))\nfor i in range(n):\n print(seq[i],end=" ")', 'import sys\n\nsys.setrecursionlimit(10**7)\n\ndef dfs(x):\n if seen[x-1]==0:\n uni[cnt].add(x)\n seen[x-1]=1\n for i in fri[x-1]:\n dfs(i)\n \n\nn,m,k=map(int,input().split())\n\nfri=[[] for i in range(n)]\nblk=[set() for i in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n fri[a-1].append(b)\n fri[b-1].append(a)\n\nfor i in range(k):\n c,d=map(int,input().split())\n blk[c-1].add(d)\n blk[d-1].add(c)\n\n\nseen=[0 for i in range(n)]\n\nuni=[]\ncnt=0\nfor i in range(1,n+1):\n if seen[i-1]==0:\n uni.append(set())\n dfs(i)\n cnt+=1\n\nseq=[0 for i in range(n)]\n\nfor unii in uni:\n for j in unii:\n cj=len(unii)-len(fri[j-1])-len(unii&blk[j-1])-1\n seq[j-1]=cj\n\nprint(*seq)'] | ['Time Limit Exceeded', 'Wrong Answer', 'Time Limit Exceeded', 'Wrong Answer', 'Runtime Error', 'Time Limit Exceeded', 'Accepted'] | ['s123604661', 's437070457', 's622541751', 's764137813', 's962731540', 's969359831', 's423552668'] | [19716.0, 63148.0, 19748.0, 83748.0, 3064.0, 19636.0, 83724.0] | [2105.0, 990.0, 2105.0, 1095.0, 17.0, 2105.0, 1162.0] | [1318, 638, 1394, 634, 759, 1108, 747] |
p02762 | u357949405 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import deque\nimport sys\ndef input(): return sys.stdin.readline().strip()\n\nDEBUG = False\n\nN, M, K = map(int, input().split())\n\nfriend_matrix = [[0] * N for _ in range(N)]\nblock_matrix = [[0] * N for _ in range(N)]\n\nnum_frineds = [0] * N\nnum_blocks = [0] * N\n\nfor _ in range(M):\n A, B = map(int, input().split())\n friend_matrix[A-1][B-1] = 1\n friend_matrix[B-1][A-1] = 1\n num_frineds[A-1] += 1\n num_frineds[B-1] += 1\n\nfor _ in range(K):\n C, D = map(int, input().split())\n block_matrix[C-1][D-1] = 1\n block_matrix[D-1][C-1] = 1\n\nif DEBUG:\n # print("friend_matrix: {}".format(friend_matrix))\n print("friend_matrix:")\n for row in friend_matrix:\n print(row)\n # print("block_matrix: {}".format(block_matrix))\n print("block_matrix:")\n for row in block_matrix:\n print(row)\n print("enter!!")\n\ncount = 0\nlabels = [-1] * N\ngraph_sizes = []\nfor n in range(N):\n size = 0\n if labels[n-1] == -1:\n queue = deque([n])\n while queue:\n node = queue.popleft()\n if labels[node-1] == -1:\n labels[node-1] = count\n size += 1\n else:\n continue\n for i in range(N):\n if labels[i-1] == -1 and friend_matrix[node-1][i-1] == 1:\n queue.append(i)\n count += 1\n graph_sizes.append(size)\nprint(num_blocks)\nif DEBUG:\n print("labels: {}".format(labels))\n print("graph_sizes: {}".format(graph_sizes))\n\nfrind_candidate = [0] * N\nfor n in range(N):\n # num_block = sum(block_matrix[n])\n num_block = 0\n for i in range(N):\n if block_matrix[n][i] == 1 and labels[n] == labels[i]:\n num_block += 1\n # num_frined = sum(friend_matrix[n])\n num_frined = num_frineds[n]\n if not DEBUG:\n print("node: {}, num_frined: {}, num_block: {}".format(n+1, num_frined, num_block))\n frind_candidate[n] = graph_sizes[labels[n]] - num_frined - num_block - 1\nfrind_candidate = list(map(str, frind_candidate))\nprint(" ".join(frind_candidate))\n', 'from collections import deque\nimport sys\nimport time\ndef input(): return sys.stdin.readline().strip()\n\nDEBUG = False\n\nN, M, K = map(int, input().split())\n\nfriend_matrix = [[0] * N for _ in range(N)]\nblock_matrix = [[0] * N for _ in range(N)]\n\nnum_connected_friends = [0] * N\nnum_connected_blocks = [0] * N\n\nfor _ in range(M):\n A, B = map(int, input().split())\n friend_matrix[A-1][B-1] = 1\n friend_matrix[B-1][A-1] = 1\n num_connected_friends[A-1] += 1\n num_connected_friends[B-1] += 1\n\nfor _ in range(K):\n C, D = map(int, input().split())\n block_matrix[C-1][D-1] = 1\n block_matrix[D-1][C-1] = 1\n\nif DEBUG:\n # print("friend_matrix: {}".format(friend_matrix))\n print("friend_matrix:")\n for row in friend_matrix:\n print(row)\n # print("block_matrix: {}".format(block_matrix))\n print("block_matrix:")\n for row in block_matrix:\n print(row)\n print("enter!!")\n\ncount = 0\nlabels = [-1] * N\ngraph_sizes = []\ntotal_iteration = 0\nfor n in range(N):\n if DEBUG:\n print("root_node: {}, count: {}".format(n+1, count))\n if labels[n-1] == -1:\n queue = deque([n+1])\n labels[n] = count\n size = 0\n while queue:\n total_iteration += 1\n if DEBUG:\n print("queue:{}".format(queue))\n node = queue.popleft()\n size += 1\n if DEBUG:\n print("node:{}".format(node))\n for i in range(N):\n if labels[i] == -1 and friend_matrix[node-1][i] == 1:\n labels[i] = count\n queue.append(i+1)\n if labels[node-1] == labels[i]:\n num_connected_blocks[node-1] += block_matrix[node-1][i]\n if DEBUG:\n print("labels: {}".format(labels))\n # time.sleep(0.2)\n count += 1\n graph_sizes.append(size)\nif DEBUG:\n print("total_iteration: {}".format(total_iteration))\n print("labels: {}".format(labels))\n print("graph_sizes: {}".format(graph_sizes))\n print("num_connected_friends: {}".format(num_connected_friends))\n print("num_connected_blocks: {}".format(num_connected_blocks))\n\nfrind_candidate = [0] * N\nfor n in range(N):\n # num_block = sum(block_matrix[n])\n # num_block = 0\n \n # if block_matrix[n][i] == 1 and labels[n] == labels[i]:\n # num_block += 1\n num_block = num_connected_blocks[n]\n # num_frined = sum(friend_matrix[n])\n num_frined = num_connected_friends[n]\n if DEBUG:\n print("node: {}, num_frined: {}, num_block: {}".format(n+1, num_frined, num_block))\n frind_candidate[n] = graph_sizes[labels[n]] - num_frined - num_block - 1\nfrind_candidate = list(map(str, frind_candidate))\n# print(" ".join(frind_candidate))\nprint(*frind_candidate)\n', 'from collections import deque\nimport sys\nimport time\ndef input(): return sys.stdin.readline().strip()\n\nDEBUG = False\n\nN, M, K = map(int, input().split())\n\nfriend_relations = [[] for _ in range(N+1)]\nblock_relations = [[] for _ in range(N+1)]\n\nnum_connected_friends = [0] * (N+1)\nnum_connected_blocks = [0] * (N+1)\n\nfor _ in range(M):\n A, B = map(int, input().split())\n friend_relations[A].append(B)\n friend_relations[B].append(A)\n\nfor _ in range(K):\n C, D = map(int, input().split())\n block_relations[C].append(D)\n block_relations[D].append(C)\n\nif DEBUG:\n print("friend_relations:")\n for i, row in enumerate(friend_relations):\n print("node: {}, relation: {}".format(i, row))\n print("block_matrix:")\n for i, row in enumerate(block_relations):\n print("node: {}, relation: {}".format(i, row))\n\ncount = 0\nlabels = [-1] * (N+1)\ngraph_sizes = []\ntotal_iteration = 0\nfor n in range(1, N+1):\n if DEBUG:\n print("root_node: {}, count: {}".format(n, count))\n if labels[n] == -1:\n queue = deque([n])\n labels[n] = count\n size = 0\n while queue:\n if DEBUG:\n print("queue:{}".format(queue))\n node = queue.popleft()\n size += 1\n if DEBUG:\n print("node:{}".format(node))\n for next_node in friend_relations[node]:\n total_iteration += 1\n if labels[next_node] == -1:\n labels[next_node] = count\n queue.append(next_node)\n if DEBUG:\n print("labels: {}".format(labels))\n # time.sleep(0.2)\n count += 1\n graph_sizes.append(size)\nif DEBUG:\n print("total_iteration: {}".format(total_iteration))\n print("labels: {}".format(labels))\n print("graph_sizes: {}".format(graph_sizes))\n\nfriend_candidate = [0] * (N+1)\nfor n in range(1, N+1):\n num_block = sum([1 for i in block_relations[n] if labels[n] == labels[i]])\n num_frined = len(friend_relations[n])\n if DEBUG:\n print("node: {}, num_frined: {}, num_block: {}".format(n+1, num_frined, num_block))\n friend_candidate[n] = graph_sizes[labels[n]] - num_frined - num_block - 1\n\nprint(*friend_candidate)\n', 'from collections import deque\nimport sys\nimport time\ndef input(): return sys.stdin.readline().strip()\n\nDEBUG = False\n\nN, M, K = map(int, input().split())\n\nfriend_relations = [[] for _ in range(N+1)]\nblock_relations = [[] for _ in range(N+1)]\n\nnum_connected_friends = [0] * (N+1)\nnum_connected_blocks = [0] * (N+1)\n\nfor _ in range(M):\n A, B = map(int, input().split())\n friend_relations[A].append(B)\n friend_relations[B].append(A)\n\nfor _ in range(K):\n C, D = map(int, input().split())\n block_relations[C].append(D)\n block_relations[D].append(C)\n\nif DEBUG:\n print("friend_relations:")\n for i, row in enumerate(friend_relations):\n print("node: {}, relation: {}".format(i, row))\n print("block_matrix:")\n for i, row in enumerate(block_relations):\n print("node: {}, relation: {}".format(i, row))\n\ncount = 0\nlabels = [-1] * (N+1)\ngraph_sizes = []\ntotal_iteration = 0\nfor n in range(1, N+1):\n if DEBUG:\n print("root_node: {}, count: {}".format(n, count))\n if labels[n] == -1:\n queue = deque([n])\n labels[n] = count\n size = 0\n while queue:\n if DEBUG:\n print("queue:{}".format(queue))\n node = queue.popleft()\n size += 1\n if DEBUG:\n print("node:{}".format(node))\n for next_node in friend_relations[node]:\n total_iteration += 1\n if labels[next_node] == -1:\n labels[next_node] = count\n queue.append(next_node)\n if DEBUG:\n print("labels: {}".format(labels))\n # time.sleep(0.2)\n count += 1\n graph_sizes.append(size)\nif DEBUG:\n print("total_iteration: {}".format(total_iteration))\n print("labels: {}".format(labels))\n print("graph_sizes: {}".format(graph_sizes))\n\nfriend_candidate = [0] * (N+1)\nfor n in range(1, N+1):\n num_block = sum([1 for i in block_relations[n] if labels[n] == labels[i]])\n num_frined = len(friend_relations[n])\n if DEBUG:\n print("node: {}, num_frined: {}, num_block: {}".format(n+1, num_frined, num_block))\n friend_candidate[n] = graph_sizes[labels[n]] - num_frined - num_block - 1\n\nprint(*friend_candidate[1:])\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s223331512', 's355232616', 's372272358', 's805999268'] | [2087148.0, 2064744.0, 48736.0, 48700.0] | [2247.0, 2261.0, 804.0, 873.0] | [2058, 2803, 2232, 2236] |
p02762 | u366963613 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["class UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n+1)]\n self.rank = [0] * (n+1)\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 union(self, x, y):\n x = self.find(x)\n y = self.find(y)\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_check(self, x, y):\n return self.find(x) == self.find(y)\n\n\nn, m, k = list(map(int, input().split()))\na = [0]*(m+1)\nb = [0]*(m+1)\nc = [0]*(k+1)\nd = [0]*(k+1)\nunion_find = UnionFind(n)\nnum_friends = [-1]*(n+1)\nfor i in range(m):\n a[i], b[i] = map(int, input().split())\n num_friends[a[i]] += 1\n num_friends[b[i]] += 1\n union_find.union(a[i], b[i])\nfor i in range(k):\n c[i], d[i] = map(int, input().split())\n\n\n\n\n# frinds_mat[a[i]-1, b[i]-1] = 1\n# frinds_mat[b[i]-1, a[i]-1] = 1\n\nnum_suggest_friend = num_friends\nfor i in range(1, n+1):\n # num_suggest_friend[i] -= num_friends[i]\n for j in range(1, n+1):\n if (union_find.same_check(i, j)):\n num_suggest_friend[i] += 1\n# print(*num_suggest_friend[1:], sep=' ')\n\n\n\n # print(*num_suggest_friend[1:], sep=' ')\nfor c_, d_ in zip(c, d):\n if union_find.same_check(c_, d_):\n num_suggest_friend[c_] -= 1\n num_suggest_friend[d_] -= 1\n\nprint(*num_suggest_friend[1:], sep=' ')\n", "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n+1))\n self.rank = [0] * (n+1)\n self.size = [1]*(n+1)\n\n \n def find(self, x):\n if self.parent[x] == x:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[x]\n\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n else:\n if self.size[x] < self.size[y]:\n self.parent[x] = y\n self.size[y] += self.size[x]\n else:\n self.parent[y] = x\n self.size[x] += self.size[y]\n\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n def cnt(self, x):\n \n return self.size[self.find(x)]\n\n\nn, m, k = list(map(int, input().split()))\n\nunion_find = UnionFind(n)\nnum_friends = [0]*(n+1)\nnum_block = [0]*(n+1)\nfor i in range(m):\n a, b = map(int, input().split())\n num_friends[a] += 1\n num_friends[b] += 1\n union_find.union(a, b)\n# cd = [[_c, _d] for (_c, _d) in map(int, input().split())]\nfor i in range(k):\n # c[i], d[i] = map(int, input().split())\n c, d = map(int, input().split())\n if union_find.same_check(c, d):\n num_block[c] += 1\n num_block[d] += 1\n\n\nnum_suggest_friend = [0]*(n+1) \n\nfor i in range(1, n+1):\n num_suggest_friend[i] = union_find.cnt(i) - \\\n num_friends[i] - num_block[i] - 1\n\nprint(*num_suggest_friend[1:], sep=' ')\n"] | ['Wrong Answer', 'Accepted'] | ['s949891257', 's141640406'] | [24420.0, 16560.0] | [2108.0, 1121.0] | [1808, 1653] |
p02762 | u368796742 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import deque\n\nn,m,k = map(int,input().split())\nans = [[0]*n for i in range(n)]\n\nfre = [[] for i in range(n)]\nblo = [[] for i in range(n)]\nfor i in range(m):\n a,b = map(int,input().split())\n fre[a-1].append(b-1)\n fre[b-1].append(a-1)\nfor i in range(k):\n a,b = map(int,input().split())\n blo[a-1].append(b-1)\n blo[b-1].append(a-1)\n\ngroup = [-1]*n\ndef check():\n \n count = 1\n for i in range(n):\n if group[i] == -1:\n dfs(i,count)\n count += 1\n return group\n\ndef dfs(i,count):\n q = deque([])\n q.append(i)\n while q:\n bef = q.pop()\n\n for nex in fre[bef]:\n if group[nex] == -1:\n group[nex] = count\n q.append(nex)\n \ncheck()\nfor i in range(n):\n if group[i] == -1:\n print(0,end=" ")\n else:\n num = group.count(group[i])\n num -= len(fre[i])\n for j in blo[i]:\n if group[j] == group[i]:\n num -= 1\n print(num-1,end=" ")\n\n\n\n\n', 'class Unionfind:\n\n def __init__(self,n):\n self.uf = [-1]*n\n\n def find(self,x):\n if self.uf[x] < 0:\n return x\n else:\n self.uf[x] = self.find(self.uf[x])\n return self.uf[x]\n\n def same(self,x,y):\n return self.find(x) == self.find(y)\n\n def union(self,x,y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return False\n if self.uf[x] > self.uf[y]:\n x,y = y,x\n self.uf[x] += self.uf[y]\n self.uf[y] = x\n return True\n\n def size(self,x):\n x = self.find(x)\n return -self.uf[x]\n\nn,m,k = map(int,input().split())\nun = Unionfind(n)\nfre = [1]*n\nfor i in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n un.union(a,b)\n fre[a] += 1\n\nans = [un.size(i)-fre[i] for i in range(n)]\n\nfor i in range(k):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n if un.same(a,b):\n ans[a] -= 1\n ans[b] -= 1\nprint(*ans)\n ', 'class Unionfind:\n\n def __init__(self,n):\n self.uf = [-1]*n\n\n def find(self,x):\n if self.uf[x] < 0:\n return x\n else:\n self.uf[x] = self.find(self.uf[x])\n return self.uf[x]\n\n def same(self,x,y):\n return self.find(x) == self.find(y)\n\n def union(self,x,y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return False\n if self.uf[x] > self.uf[y]:\n x,y = y,x\n self.uf[x] += self.uf[y]\n self.uf[y] = x\n return True\n\n def size(self,x):\n x = self.find(x)\n return -self.uf[x]\n\nn,m,k = map(int,input().split())\nun = Unionfind(n)\nfre = [1]*n\nfor i in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n un.union(a,b)\n fre[a] += 1\n fre[b] += 1\n\nans = [un.size(i)-fre[i] for i in range(n)]\n\nfor i in range(k):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n if un.same(a,b):\n ans[a] -= 1\n ans[b] -= 1\nprint(*ans)\n '] | ['Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s274540827', 's552377203', 's172061530'] | [2086508.0, 14108.0, 14128.0] | [2249.0, 1118.0, 1118.0] | [1015, 1002, 1018] |
p02762 | u387774811 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["import sys\ninput = sys.stdin.readline\nif 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 def same(self, x, y):\n return self.find(x) == self.find(y)\n\nN,M,K = map(int,input().split())\nuf = UnionFind(N)\nlst=[0]*(N)\nans=[0]*(N)\nfor i in range(M):\n A,B=map(int,input().split())\n uf.union(A-1,B-1)\n lst[A-1]+=1\n lst[B-1]+=1\nfor i in range(K):\n A,B=map(int,input().split())\n if uf.same(A-1,B-1):\n lst[A-1]+=1\n lst[B-1]+=1\nfor i in range(N):\n ans[i]=uf.size(i)-lst[i]-1\nL=[str(a) for a in ans]\nL=' '.join(L)\nprint(L)\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 def same(self, x, y):\n return self.find(x) == self.find(y)\nimport sys\ninput = sys.stdin.readline\nN,M,K = map(int,input().split())\nuf = UnionFind(N)\nlst=[0]*(N)\nfor i in range(M):\n A,B=map(int,input().split())\n uf.union(A-1,B-1)\n lst[A-1]-=1\n lst[B-1]-=1\nfor i in range(K):\n A,B=map(int,input().split())\n if uf.same(A-1,B-1):\n lst[A-1]-=1\n lst[B-1]-=1\nlst=[lst[i]+uf.size(i)-1 for i in range(N)]\nL=[str(a) for a in lst]\nL=' '.join(L)\nprint(L)\n"] | ['Runtime Error', 'Accepted'] | ['s879160371', 's050135398'] | [2940.0, 17820.0] | [17.0, 735.0] | [841, 930] |
p02762 | u413165887 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n, m, k = map(int , input().split())\ndif = set([i for i in range(1, n+1)])\nm_list = [[] for _ in range(n+1)]\nuni = [i for i in range(n+1)]\nab = sorted([list(map(int, input().split())) for _ in range(m)])\ncd = [list(map(int, input().split())) for _ in range(k)]\nfor i in range(m):\n a, b = ab[i]\n m_list[a].append(b)\n m_list[b].append(a)\n a, b = sorted([a, b])\n for j in range(1, n+1):\n if uni[j] == uni[b]:\n uni[j] = uni[a]\n uni[b] = uni[a]\n\nk_list = [[] for _ in range(n+1)]\nfor i in range(k):\n a, b = cd[i]\n k_list[a].append(b)\n k_list[b].append(a)\n\n\nresult = [0 for i in range(n+1)]\nfor i in range(1, n+1):\n r = dif - set(m_list[i])\n r = r - set(k_list[i])\n r = r - set([i])\n\n\n for j in list(r):\n print(j, uni[j], uni[i])\n if uni[j] == uni[i]:\n result[i] += 1\n\nprint(*result[1:])', '\nn, m, k = map(int, input().split())\nab = [list(map(int, input().split())) for _ in range(m)]\ncd = [list(map(int, input().split())) for _ in range(k)]\ncon = [1 for _ in range(n+1)]\nuni = [-1 for i in range(n+1)]\nrank = [0 for _ in range(n+1)]\n\ndef root(num, pea):\n if pea[num] < 0:\n return num\n else:\n pea[num] = root(pea[num], pea)\n return pea[num]\n\nfor i in range(m):\n a, b = ab[i]\n con[a] += 1\n con[b] += 1\n root_a = root(a, uni)\n root_b = root(b, uni)\n if root_a!=root_b:\n if rank[root_a] < rank[root_b]:\n uni[root_b] += uni[root_a]\n uni[root_a] = root_b\n else:\n uni[root_a] += uni[root_b]\n uni[root_b] = root_a\n if rank[root_a] == rank[root_b]:\n rank[root_a] += 1\n\n\nfor i in range(k):\n c, d = cd[i]\n if root(c, uni) == root(d, uni):\n con[c] += 1\n con[d] += 1\n\nresult = []\nfor i in range(1, n+1):\n root_i = root(i, uni)\n result.append(-uni[root_i]-con[i])\nprint(*result)\n'] | ['Wrong Answer', 'Accepted'] | ['s012011253', 's414391946'] | [70160.0, 60504.0] | [2108.0, 1053.0] | [863, 1030] |
p02762 | u414920281 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\nsys.setrecursionlimit(1000000000)\nn,m,k=map(int,input().split())\nstock=[set() for i in range(n)]\nter=[0]*n\nans=[0]*n\nfor i in range(m):\n a,b=map(int,input().split())\n stock[a-1].append(b-1)\n stock[b-1].append(a-1)\n ans[a-1]-=1\n ans[b-1]-=1\ndef dfs(j,k):\n size[k]+=1\n for next_j in stock[j]:\n if ter[next_j]==0:\n ter[next_j]=k\n dfs(next_j,k)\ntotal=0\nsize=[0]*(n+1)\nfor i in range(n):\n if ter[i]==0:\n total+=1\n ter[i]=total\n dfs(i,total)\n\nfor i in range(n):\n ans[i]+=size[ter[i]]-1\nfor i in range(k):\n c, d = map(int, input().split())\n if ter[c-1]==ter[d-1]:\n ans[c-1]-=1\n ans[d-1]-=1\nfor i in range(n-1):\n print(ans[i],end=" ")\nprint(ans[n-1])', 'import sys\nsys.setrecursionlimit(1000000)\nn,m,k=map(int,input().split())\nstock=[set() for i in range(n)]\nter=[0]*n\nans=[0]*n\nfor i in range(m):\n a,b=map(int,input().split())\n stock[a-1].append(b-1)\n stock[b-1].append(a-1)\n ans[a-1]-=1\n ans[b-1]-=1\ndef dfs(j,k):\n size[k]+=1\n for next_j in stock[j]:\n if ter[next_j]==0:\n ter[next_j]=k\n dfs(next_j,k)\ntotal=0\nsize=[0]*(n+1)\nfor i in range(n):\n if ter[i]==0:\n total+=1\n ter[i]=total\n dfs(i,total)\n\nfor i in range(n):\n ans[i]+=size[ter[i]]-1\nfor i in range(k):\n c, d = map(int, input().split())\n if ter[c-1]==ter[d-1]:\n ans[c-1]-=1\n ans[d-1]-=1\nfor i in range(n-1):\n print(ans[i],end=" ")\nprint(ans[n-1])\n', 'n,m,k=map(int,input().split())\nstock=[set() for i in range(n)]\nter=[0]*n\nans=[0]*n\nfor i in range(m):\n a,b=map(int,input().split())\n stock[a-1].append(b-1)\n stock[b-1].append(a-1)\n ans[a-1]-=1\n ans[b-1]-=1\ndef dfs(j,k):\n size[k]+=1\n for next_j in stock[j]:\n if ter[next_j]==0:\n ter[next_j]=k\n dfs(next_j,k)\ntotal=0\nsize=[0]*(n+1)\nfor i in range(n):\n if ter[i]==0:\n total+=1\n ter[i]=total\n dfs(i,total)\n\nfor i in range(n):\n ans[i]+=size[ter[i]]-1\nfor i in range(k):\n c, d = map(int, input().split())\n if ter[c-1]==ter[d-1]:\n ans[c-1]-=1\n ans[d-1]-=1\nfor i in range(n-1):\n print(ans[i],end=" ")\nprint(ans[n-1])', 'import sys\nsys.setrecursionlimit(1000000)\nn,m,k=map(int,input().split())\nstock=[[] for i in range(n)]\nter=[0]*n\nans=[0]*n\nfor i in range(m):\n a,b=map(int,input().split())\n stock[a-1].append(b-1)\n stock[b-1].append(a-1)\n ans[a-1]-=1\n ans[b-1]-=1\ndef dfs(j,k):\n size[k]+=1\n for next_j in stock[j]:\n if ter[next_j]==0:\n ter[next_j]=k\n dfs(next_j,k)\ntotal=0\nsize=[0]*(n+1)\nfor i in range(n):\n if ter[i]==0:\n total+=1\n ter[i]=total\n dfs(i,total)\n\nfor i in range(n):\n ans[i]+=size[ter[i]]-1\nfor i in range(k):\n c, d = map(int, input().split())\n if ter[c-1]==ter[d-1]:\n ans[c-1]-=1\n ans[d-1]-=1\nfor i in range(n-1):\n print(ans[i],end=" ")\nprint(ans[n-1])\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s077012906', 's503976930', 's574535494', 's699109809'] | [33736.0, 33660.0, 33740.0, 49588.0] | [227.0, 231.0, 234.0, 646.0] | [753, 751, 708, 748] |
p02762 | u426764965 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["import sys\nsys.setrecursionlimit(200100)\ndef abc157_d():\n N, M, K = map(int, input().split())\n fr = [set() for _ in range(N)]\n for _ in range(M):\n a, b = map(int, input().split())\n a, b = a-1, b-1\n fr[a].add(b)\n fr[b].add(a)\n bl = [set() for _ in range(N)]\n for _ in range(K):\n c, d = map(int, input().split())\n c, d = c-1, d-1\n bl[c].add(d)\n bl[d].add(c)\n\n def dfs(nd, lb):\n nonlocal label, gr\n label[nd] = lb\n gr[lb].add(nd)\n for ch in fr[nd]:\n if label[ch] != -1: continue\n dfs(ch, lb)\n\n label = [-1] * N\n lb = 0\n gr = []\n for i in range(N):\n if label[i] != -1: continue\n gr.append(set())\n dfs(i, lb)\n lb += 1\n\n return\n\n ans = [0] * N\n for i in range(N):\n cand = gr[label[i]] - fr[i] - bl[i]\n ans[i] = len(cand) - 1\n print(*ans, sep=' ')\n\nabc157_d()", "import sys\nsys.setrecursionlimit(200100)\n\ndef abc157_d():\n N, M, K = map(int, input().split())\n fr = [set() for _ in range(N)]\n for _ in range(M):\n a, b = map(int, input().split())\n a, b = a-1, b-1\n fr[a].add(b)\n fr[b].add(a)\n bl = []\n for _ in range(K):\n c, d = map(int, input().split())\n c, d = c-1, d-1\n bl.append((c,d))\n\n def dfs(nd, lb):\n nonlocal label, gr\n label[nd] = lb\n gr[lb] += 1\n for ch in fr[nd]:\n if label[ch] != -1: continue\n dfs(ch, lb)\n\n ans = [0] * N\n label = [-1] * N\n lb = 0\n gr = []\n for i in range(N):\n if label[i] != -1:\n ans[i] = gr[label[i]]\n continue\n gr.append(0)\n dfs(i, lb)\n ans[i] = gr[label[i]]\n lb += 1\n\n for c, d in bl:\n if label[c] == label[d]:\n ans[c] -= 1\n ans[d] -= 1\n\n for i in range(N):\n ans[i] -= len(fr[i]) + 1\n\n print(*ans, sep=' ')\n\nabc157_d()"] | ['Wrong Answer', 'Accepted'] | ['s405534139', 's930495897'] | [103224.0, 77076.0] | [1017.0, 983.0] | [942, 1021] |
p02762 | u432251613 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['def main():\n \n class UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n)]\n self.rank = [0] * n\n self.size = [1] * 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 union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n \n def getSize(self, x):\n return self.size[self.find(x)]\n\n N,M,K = map(int, input().split())\n \n \n uftree = UnionFind(N)\n count = [0] * N\n for i in range(M):\n A,B = map(lambda x:x-1, map(int, input().split()))\n uftree.union(A,B)\n count[A] += 1\n count[B] += 1\n for i in range(K):\n C,D = map(lambda x:x-1, map(int, input().split()))\n if uftree.same_check(C,D):\n count[C] += 1\n count[D] += 1\n ans = [0] * N\n for i in range(N):\n print(uftree.getSize(i))\n print(count[i])\n ans[i] = uftree.getSize(i) - 1 - count[i] \n print(*ans)\n\nmain()\n', '\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n)]\n self.rank = [0] * n\n self.size = [1] * 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 union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n \n def getSize(self, x):\n return self.size[self.find(x)]\n\ndef main():\n N,M,K = map(int, input().split())\n \n \n uftree = UnionFind(N)\n count = [0] * N\n for i in range(M):\n A,B = map(lambda x:x-1, map(int, input().split()))\n uftree.union(A,B)\n count[A] += 1\n count[B] += 1\n for i in range(K):\n C,D = map(lambda x:x-1, map(int, input().split()))\n if uftree.same_check(C,D):\n count[C] += 1\n count[D] += 1\n ans = [""] * N\n for i in range(N):\n print(uftree.getSize(i))\n print(count[i])\n ans[i] = str(uftree.getSize(i) - 1 - count[i]) \n print(" ".join(ans))\n\nmain()\n', '\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n)]\n self.rank = [0] * n\n self.size = [1] * 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 union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n \n def getSize(self, x):\n return self.size[self.find(x)]\n\ndef main():\n N,M,K = map(int, input().split())\n \n \n uftree = UnionFind(N)\n count = [0] * N\n for i in range(M):\n A,B = map(lambda x:x-1, map(int, input().split()))\n uftree.union(A,B)\n count[A] += 1\n count[B] += 1\n for i in range(K):\n C,D = map(lambda x:x-1, map(int, input().split()))\n if uftree.same_check(C,D):\n count[C] += 1\n count[D] += 1\n ans = [0] * N\n for i in range(N):\n print(uftree.getSize(i))\n print(count[i])\n ans[i] = uftree.getSize(i) - 1 - count[i] \n print(*ans)\n\nmain()\n', '\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n)]\n self.rank = [0] * n\n self.size = [1] * 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 union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n \n def getSize(self, x):\n return self.size[self.find(x)]\n\ndef main():\n N,M,K = map(int, input().split())\n \n \n uftree = UnionFind(N)\n count = [0] * N\n for i in range(M):\n A,B = map(lambda x:x-1, map(int, input().split()))\n uftree.union(A,B)\n count[A] += 1\n count[B] += 1\n for i in range(K):\n C,D = map(lambda x:x-1, map(int, input().split()))\n if uftree.same_check(C,D):\n count[C] += 1\n count[D] += 1\n ans = [""] * N\n for i in range(N):\n print(uftree.getSize(i))\n print(count[i])\n ans[i] = str(uftree.getSize(i) - 1 - count[i]) \n print(*ans, sep=" ")\n\nmain()\n', '\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n)]\n self.rank = [0] * n\n self.size = [1] * 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 union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n \n def getSize(self, x):\n return self.size[self.find(x)]\n\nN,M,K = map(int, input().split())\n\n\nuftree = UnionFind(N)\ncount = [0] * N\nfor i in range(M):\n A,B = map(lambda x:x-1, map(int, input().split()))\n uftree.union(A,B)\n count[A] += 1\n count[B] += 1\nfor i in range(K):\n C,D = map(lambda x:x-1, map(int, input().split()))\n if uftree.same_check(C,D):\n count[C] += 1\n count[D] += 1\nans = [0] * N\nfor i in range(N):\n print(uftree.getSize(i))\n print(count[i])\n ans[i] = uftree.getSize(i) - 1 - count[i] \n\nprint(*ans)\n', '\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n)]\n self.rank = [0] * n\n self.size = [1] * 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 union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n \n def getSize(self, x):\n return self.size[self.find(x)]\n\ndef main():\n N,M,K = map(int, input().split())\n \n \n uftree = UnionFind(N)\n count = [0] * N\n for i in range(M):\n A,B = map(lambda x:x-1, map(int, input().split()))\n uftree.union(A,B)\n count[A] += 1\n count[B] += 1\n for i in range(K):\n C,D = map(lambda x:x-1, map(int, input().split()))\n if uftree.same_check(C,D):\n count[C] += 1\n count[D] += 1\n ans = [""] * N\n for i in range(N):\n print(uftree.getSize(i))\n print(count[i])\n ans[i] = str(uftree.getSize(i) - 1 - count[i]) \n print(*ans)\n\nmain()\n', '\nclass UnionFind():\n def __init__(self, n):\n \n self.par = [i for i in range(n)]\n self.rank = [0] * n\n self.size = [1] * 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 union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n \n def getSize(self, x):\n return self.size[self.find(x)]\n\ndef main():\n N,M,K = map(int, input().split())\n \n \n uftree = UnionFind(N)\n count = [0] * N\n for i in range(M):\n A,B = map(lambda x:x-1, map(int, input().split()))\n uftree.union(A,B)\n count[A] += 1\n count[B] += 1\n for i in range(K):\n C,D = map(lambda x:x-1, map(int, input().split()))\n if uftree.same_check(C,D):\n count[C] += 1\n count[D] += 1\n ans = [0] * N\n for i in range(N):\n ans[i] = uftree.getSize(i) - 1 - count[i] \n print(*ans)\n\nmain()\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s036443027', 's090690555', 's163958033', 's634987142', 's711238942', 's837221161', 's910299939'] | [16612.0, 18584.0, 16616.0, 19052.0, 16616.0, 19056.0, 15696.0] | [1403.0, 1372.0, 1390.0, 1396.0, 1532.0, 1470.0, 1224.0] | [1896, 1775, 1760, 1775, 1657, 1766, 1705] |
p02762 | u451012573 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["import sys\nN, M, K = map(int, input().split())\nsys.setrecursionlimit(N + 1)\n\nF, B = {}, {}\nfor i in range(N):\n F[i] = set()\n B[i] = set()\n\nfor _ in range(M):\n x, y = map(int, input().split())\n F[x - 1].add(y - 1)\n F[y - 1].add(x - 1)\n\nfor _ in range(K):\n x, y = map(int, input().split())\n B[x - 1].add(y - 1)\n B[y - 1].add(x - 1)\n\n\ndef dfs(v, visited):\n\n visited.add(v)\n\n for n in F[v]:\n if n in visited:\n continue\n dfs(n, visited)\n\n\nfor i in range(N):\n\n C = set()\n dfs(i, C)\n C = C - {i}\n C = C - B[i]\n C = C - F[i]\n\n print(len(C), end='')\n if i != N - 1:\n print(' ', end='')\n\nprint('')\n", "class UnionFind:\n def __init__(self, n):\n self.par = list(range(n)) \n self.siz = [1] * n\n\n def root(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.root(self.par[x])\n return self.par[x]\n\n def same(self, x, y):\n return self.root(x) == self.root(y)\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n if self.siz[x] > self.siz[y]: \n x, y = y, x\n self.siz[y] += self.siz[x]\n self.par[x] = y\n\n def tree_size(self, x):\n return self.siz[self.root(x)]\n\n\nN, M, K = map(int, input().split())\nF = UnionFind(N)\nn_friend = [0] * N\n\nB = {}\nfor i in range(N):\n B[i] = set()\nfor _ in range(M):\n p, q = map(int, input().split())\n n_friend[p - 1] += 1\n n_friend[q - 1] += 1\n F.unite(p - 1, q - 1)\nfor _ in range(K):\n p, q = map(int, input().split())\n B[p - 1].add(q - 1)\n B[q - 1].add(p - 1)\n\n\n# calc friend candidate\ni, blocked = 0, 0\nfor b in B[0]:\n if F.same(i, b):\n blocked += 1\nprint(F.tree_size(i) - 1 - n_friend[i] - blocked, end='')\nfor i in range(1, N):\n print(' ', end='')\n blocked = 0\n for b in B[i]:\n if F.same(i, b):\n blocked += 1\n print(F.tree_size(i) - 1 - n_friend[i] - blocked, end='')\nprint('')\n"] | ['Time Limit Exceeded', 'Accepted'] | ['s903057994', 's589182666'] | [105028.0, 53600.0] | [2109.0, 1650.0] | [671, 1485] |
p02762 | u455408345 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['nmk=input("").split(" ")\nn=int(nmk[0])\nm=int(nmk[1])\nk=int(nmk[2])\nlistin=[-1]*n\nlistf=[]\nlistb=[]\nfor i in range(n):\n listf+=[[]]\n listb+=[[]]\nfor i in range(m):\n ab=input("").split(" ")\n a=int(ab[0])-1\n b=int(ab[1])-1\n listf[a]+=[b]\n listf[b]+=[a]\nfor i in range(k):\n ab=input("").split(" ")\n a=int(ab[0])-1\n b=int(ab[1])-1\n listb[a]+=[b]\n listb[b]+=[a]\ns=-1\nlistff=[]\n\nfor i in range(n):\n if(listin[i]==-1):\n s+=1\n listin[i]=s\n listff+=[[i]]\n cnt=0\n \n while(len(listff[s])>cnt):\n for ii in listf[listff[s][cnt]]:\n if(listin[ii]==-1):\n listin[ii]=s\n listff[s]+=[ii]\n \n cnt+=1\nlistans=[]\n\nfor i in range(n):\n \n listans+=[str(len(set(listff[listin[i]]))-1-len(listf[i]))]\nprint(" ".join(listans))\n\n \n\n\n\n \n \n', 'import numpy as np\nfrom scipy.sparse.csgraph import connected_components\nfrom scipy.sparse import csr_matrix\n\nimport sys\nsys.setrecursionlimit(10**9)\nn,m,k=[int(i) for i in input().split()]\nfrends_num=[0 for i in range(n)]\ndef make_frends(m,n):\n data=[1 for i in range(m)]\n\n row=[]\n col=[]\n for k in range(m):\n i,j=[int(l) for l in input().split()]\n new_i=min(i,j)-1\n new_j=max(i,j)-1\n row.append(new_i)\n col.append(new_j)\n frends_num[new_i]+=1\n frends_num[new_j]+=1\n frend_sparce_matrix=csr_matrix((data, (row, col)),shape=(n,n))\n return frend_sparce_matrix\n\n\nfrends=make_frends(m,n)\nl,labels=connected_components(frends)\nlabels\nlabels=list(labels)\n\nclass Group:\n def __init__(self,labels):\n self.labels=labels\n self.group_num=[0 for i in range(l)]\n for i in labels:\n self.group_num[i]+=1\n def get_group_num(self,i):\n return self.group_num[self.labels[i]]\n\ngroup=Group(labels)\n\n\ndef get_frend_num(i):\n return frends_num[i]\n\n\ndef make_block(k,n):\n block_num=[0 for i in range(n)]\n for p in range(k):\n i,j =[int(l)-1 for l in input().split()]\n new_i=min(i,j)\n new_j=max(i,j)\n if labels[new_i]==labels[new_j]:\n block_num[i]+=1\n block_num[j]+=1\n return block_num\n\nblock=make_block(k,n)\n\ndef get_block_num(i):\n return block[i]\n\nans=[]\nfor i in range(n):\n ans.append(str(group.get_group_num(i)-1-get_frend_num(i)-get_block_num(i)))\nprint(" ".join(ans))\n'] | ['Wrong Answer', 'Accepted'] | ['s241886933', 's834222967'] | [63612.0, 53288.0] | [2207.0, 735.0] | [897, 1528] |
p02762 | u455629561 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import defaultdict\n\nn, m, k = map(int, input().split())\nfriend = defaultdict(list)\nblock = defaultdict(list)\nfor i in range(m):\n a, b = map(int, input().split())\n if a > b:\n a, b = b, a\n friend[a].append(b)\nfor i in range(k):\n a, b = map(int, input().split())\n if a > b:\n a, b = b, a\n block[a].append(b)\nres = [0] * n\nfor i in range(1, n + 1):\n if len(friend[i]) == n - 1 or len(friend[i]) == 0:\n continue\n for j in friend[i]:\n for k in friend[k]:\n if k not in friend[i] and k not in block[i]:\n res[i - 1] += 1\nfor i in range(n):\n print(res[i], sep = " ")', 'from collections import defaultdict\n\nn, m, k = map(int, input().split())\nfriend = defaultdict(list)\nblock = defaultdict(list)\nfor i in range(m):\n a, b = map(int, input().split())\n if a > b:\n a, b = b, a\n friend[a].append(b)\nfor i in range(k):\n a, b = map(int, input().split())\n if a > b:\n a, b = b, a\n block[a].append(b)\nres = [0] * n\nfor i in range(1, n + 1):\n if len(friend[i]) == n - 1 or len(friend[i]) == 0:\n continue\n for j in friend[i]:\n for k in friend[j]:\n if k not in friend[i] and k not in block[i]:\n res[i - 1] += 1\n res[k-1] += 1\nfor i in range(n):\n print(res[i],end = " ")', 'from collections import defaultdict\nn, m, k = map(int, input().split())\nfriend = defaultdict(set)\nblock = defaultdict(set)\nfor i in range(m):\n a, b = map(int, input().split())\n friend[a].add(b)\n friend[b].add(a)\nfor i in range(k):\n a, b = map(int, input().split())\n block[a].add(b)\n block[b].add(a)\nres = [0] * n\nfor i in range(1, n + 1):\n if len(friend[i]) == n - 1 or len(friend[i]) == 0:\n continue\n queue = list(friend[i])\n while queue:\n j = queue.pop(0)\n for k in friend[j]:\n if k != i and k not in friend[i] and k not in block[i]:\n res[i-1] += 1\n friend[i].add(k)\n queue.append(k)\n if i not in friend[k]:\n res[k-1] += 1\n friend[k].add(i)\nfor i in range(n):\n print(res[i], end=" ")', 'from collections import deque\nn, m, k = map(int, input().split())\nfriend = [set() for _ in range(n + 1)]\nblock = [set() for _ in range(n + 1)]\nfor i in range(m):\n a, b = map(int, input().split())\n friend[a].add(b)\n friend[b].add(a)\nfor i in range(k):\n a, b = map(int, input().split())\n block[a].add(b)\n block[b].add(a)\nstack = deque()\nans = [0]*(n+1)\nvisited = [0]*(n+1)\nfor i in range(1, n+1):\n if visited[i]:\n continue\n link = {i}\n visited[i] = 1\n stack.append(i)\n while stack:\n n = stack.pop()\n for j in friend[n]:\n if visited[j] == 0:\n stack.append(j)\n visited[j] = 1\n link.add(j)\n for i in link:\n ans[i] = len(link) - len(link & friend[i]) - len(link & block[i]) -1\nprint(*ans[1:])'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s347885543', 's389435440', 's675479087', 's747177171'] | [42228.0, 41776.0, 84448.0, 80700.0] | [942.0, 2105.0, 2108.0, 1133.0] | [653, 682, 845, 806] |
p02762 | u459419927 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from sys import stdin\nimport sys\nsys.setrecursionlimit(20000)\nN,M,K=list(map(int,input().split()))\nfriend_list=[set() for _ in range(N+1)]\nblock_list=[set() for _ in range(N+1)]\ndef friend_tansaku(i,j):\n color.add(j)\n for friend in friend_list[j]:\n if friend not in color:\n if friend not in block_list[i] and friend not in candidate and friend not in friend_list[i]:\n candidate.add(friend)\n count[0]+=1\n friend_tansaku(i,i)\n\n\n\n\nfor _ in range(M):\n a,b= list(map(int, input().split()))\n friend_list[a].add(b)\n friend_list[b].add(a)\nfor _ in range(K):\n a, b = list(map(int, input().split()))\n block_list[a].add(b)\n block_list[b].add(a)\nfor i in range(1,N+1):\n count=[0]\n color =set()\n candidate=set()\n friend_tansaku(i,i)\n if i==N:print(count[0])\n else:print(count[0],end=" ")', 'from sys import stdin\nimport sys\nsys.setrecursionlimit(2000)\nN,M,K=list(map(int,input().split()))\nfriend_list=[set() for _ in range(N+1)]\nblock_list=[set() for _ in range(N+1)]\ndef friend_tansaku(i,j):\n color.add(j)\n for friend in friend_list[j]:\n if friend not in color:\n # if friend not in block_list[i] and friend not in candidate and friend not in friend_list[i]:\n # candidate.add(friend)\n # count[0]+=1\n friend_tansaku(i,friend)\n\n\n\n\nfor _ in range(M):\n a,b= list(map(int, input().split()))\n friend_list[a].add(b)\n friend_list[b].add(a)\nfor _ in range(K):\n a, b = list(map(int, input().split()))\n block_list[a].add(b)\n block_list[b].add(a)\nfor i in range(1,N+1):\n count=[0]\n color =set()\n candidate=set()\n friend_tansaku(i,i)\n if i==N:print(count[0])\n else:print(count[0],end=" ")', 'from sys import stdin\nN,M,K=list(map(int,input().split()))\nfriend_list=[set() for _ in range(N+1)]\nblock_list=[set() for _ in range(N+1)]\ndef friend_tansaku(i,j):\n color.add(j)\n for friend in friend_list[j]:\n if friend not in color:\n if friend not in block_list[i] and friend not in candidate and friend not in friend_list[i]:\n candidate.add(friend)\n count[0]+=1\n friend_tansaku(i,friend)\n\n\n\n\nfor _ in range(M):\n a,b= list(map(int, input().split()))\n friend_list[a].add(b)\n friend_list[b].add(a)\nfor _ in range(K):\n a, b = list(map(int, input().split()))\n block_list[a].add(b)\n block_list[b].add(a)\nfor i in range(1,N+1):\n count=[0]\n color =set()\n candidate=set()\n # friend_tansaku(i,i)\n if i==N:print(count[0])\n else:print(count[0],end=" ")', 'from sys import stdin\nN,M,K=list(map(int,input().split()))\nfriend_list=[set() for _ in range(N+1)]\nblock_list=[set() for _ in range(N+1)]\ndef friend_tansaku(i,j):\n color.add(j)\n for friend in friend_list[j]:\n # if friend not in color:\n # if friend not in block_list[i] and friend not in candidate and friend not in friend_list[i]:\n # candidate.add(friend)\n # count[0]+=1\n friend_tansaku(i,friend)\n\n\n\n\nfor _ in range(M):\n a,b= list(map(int, input().split()))\n friend_list[a].add(b)\n friend_list[b].add(a)\nfor _ in range(K):\n a, b = list(map(int, input().split()))\n block_list[a].add(b)\n block_list[b].add(a)\nfor i in range(1,N+1):\n count=[0]\n color =set()\n candidate=set()\n friend_tansaku(i,i)\n if i==N:print(count[0])\n else:print(count[0],end=" ")', 'from sys import stdin\nN,M,K=list(map(int,input().split()))\nfriend_list=[set() for _ in range(N+1)]\nblock_list=[set() for _ in range(N+1)]\ndef friend_tansaku(i,j):\n color.add(j)\n for friend in friend_list[j]:\n if friend not in color:\n # if friend not in block_list[i] and friend not in candidate and friend not in friend_list[i]:\n candidate.add(friend)\n count[0]+=1\n friend_tansaku(i,friend)\n\n\n\n\nfor _ in range(M):\n a,b= list(map(int, input().split()))\n friend_list[a].add(b)\n friend_list[b].add(a)\nfor _ in range(K):\n a, b = list(map(int, input().split()))\n block_list[a].add(b)\n block_list[b].add(a)\nfor i in range(1,N+1):\n count=[0]\n color =set()\n candidate=set()\n friend_tansaku(i,i)\n if i==N:print(count[0])\n else:print(count[0],end=" ")', 'from sys import stdin\nN,M,K=list(map(int,input().split()))\nfriend_list=[set() for _ in range(N+1)]\nblock_list=[set() for _ in range(N+1)]\ndef friend_tansaku(i,j):\n color.add(j)\n for friend in friend_list[j]:\n if friend not in color:\n # if friend not in block_list[i] and friend not in candidate and friend not in friend_list[i]:\n # candidate.add(friend)\n # count[0]+=1\n friend_tansaku(i,friend)\n\n\n\n\nfor _ in range(M):\n a,b= list(map(int, input().split()))\n friend_list[a].add(b)\n friend_list[b].add(a)\nfor _ in range(K):\n a, b = list(map(int, input().split()))\n block_list[a].add(b)\n block_list[b].add(a)\nfor i in range(1,N+1):\n count=[0]\n color =set()\n candidate=set()\n friend_tansaku(i,i)\n if i==N:print(count[0])\n else:print(count[0],end=" ")', 'from sys import stdin\nimport sys\nsys.setrecursionlimit(2000)\nN,M,K=list(map(int,input().split()))\nfriend_list=[set() for _ in range(N+1)]\nblock_list=[set() for _ in range(N+1)]\ndef friend_tansaku(i,j):\n color.add(j)\n for friend in friend_list[j]:\n if friend not in color:\n if friend not in block_list[i] and friend not in candidate and friend not in friend_list[i]:\n candidate.add(friend)\n count[0]+=1\n # friend_tansaku(i,friend)\n\n\n\n\nfor _ in range(M):\n a,b= list(map(int, input().split()))\n friend_list[a].add(b)\n friend_list[b].add(a)\nfor _ in range(K):\n a, b = list(map(int, input().split()))\n block_list[a].add(b)\n block_list[b].add(a)\nfor i in range(1,N+1):\n count=[0]\n color =set()\n candidate=set()\n friend_tansaku(i,i)\n if i==N:print(count[0])\n else:print(count[0],end=" ")', 'from sys import stdin\nimport sys\nimport copy\nsys.setrecursionlimit(200000)\nN,M,K=list(map(int,input().split()))\ncounter=[[None,None] for i in range(N+1)]\nfriend_list=[set() for _ in range(N+1)]\nblock_list=[set() for _ in range(N+1)]\ndef friend_tansaku(i,j):\n color.add(j)\n cnt[0]+=1\n for friend in friend_list[j]:\n if friend not in color :\n friend_tansaku(i,friend)\n\n\n\n\n\nfor _ in range(M):\n a,b= list(map(int, input().split()))\n friend_list[a].add(b)\n friend_list[b].add(a)\nfor _ in range(K):\n a, b = list(map(int, input().split()))\n block_list[a].add(b)\n block_list[b].add(a)\nfor i in range(1,N+1):\n cnt=[0]\n color =set()\n if counter[i][0] is None:\n friend_tansaku(i,i)\n cnt=cnt[0]\n for aa in color:\n counter[aa]=[color,cnt]\n color,cnt =counter[i][0],counter[i][1]\n for k in block_list[i]:\n if k not in color:\n cnt+=1\n\n count=cnt-(len(friend_list[i])+len(block_list[i]))-1\n if i==N:print(count)\n else:print(count,end=" ")'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s176273373', 's306017574', 's380405074', 's492044614', 's623224641', 's844767720', 's912697138', 's595933557'] | [90804.0, 74000.0, 73644.0, 73680.0, 80444.0, 75552.0, 73616.0, 109812.0] | [1081.0, 2108.0, 1102.0, 1054.0, 2108.0, 2108.0, 1300.0, 1605.0] | [872, 882, 839, 845, 831, 843, 878, 1038] |
p02762 | u459798349 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n,m,k=map(int,input().split())\n\nL=[[] for i in range(1+n)]\nN=[]\nNcnt=[0 for i in range(1+n)]\nC=[0 for i in range(1+n)]\n\nfor inp in range(m):\n a,b=map(int,input().split())\n L[a].append(b)\n L[b].append(a)\n\nfor inp in range(k):\n a,b=map(int,input().split())\n N.append((a,b))\n\ndef tansa(x,gone,color):\n C[x]=color\n for nex in L[x]:\n if nex in gone:\n continue\n else:\n tansa(nex,gone+[nex],color)\n\nnow=1\nfor i in range(1,n):\n if C[i]==0:\n tansa(i,[i],now)\n now+=1\n\nCC=sorted(C)\n\ncnt=0\nccres=[]\nfor i in range(now):\n ccres.append(CC.index(i))\nccres.append(n+1)\ndic={i:ccres[i+1]-ccres[i] for i in range(1,now)}\n\n#print(C)\n#print(dic)\n\nfor i in range(k):\n if C[N[i][1]] == C[N[i][0]]:\n Ncnt[N[i][1]]+=1\n Ncnt[N[i][0]]+=1\n\nfor i in range(1,n):\n print(dic[C[i]]-len(L[i])-Ncnt[i]-1,end=" ")\ni=n\nprint(dic[C[i]]-len(L[i])-Ncnt[i]-1,end="")', 'n,m,k=map(int,input().split())\nBAD=[0 for i in range(n+1)]\n\nE=[]\nfor inp in range(m):\n a,b=map(int,input().split())\n E.append((a,b))\n BAD[a]-=1\n BAD[b]-=1\n\nB=[] \nfor inp in range(k):\n a,b=map(int,input().split())\n B.append((a,b))\n \nuf=[i for i in range(n+1)]\ndef uf_find(x,uf=uf):\n while uf[x]!=x:\n x=uf[x]\n return x \n\n\nres=[]\n\nfor ele in E:\n if uf_find(ele[0]) == uf_find(ele[1]):\n continue\n else:\n res.append((ele[0],ele[1])) #write result\n \n if uf_find(ele[0])>uf_find(ele[1]):\n uf[uf_find(ele[0])]=uf_find(ele[1])\n else:\n uf[uf_find(ele[1])]=uf_find(ele[0])\n\nSCO=[0 for i in range(n+1)]\nfor i in range(1,n+1):\n SCO[uf_find(i)]+=1\n\n\nfor bl in B:\n if uf_find(bl[0])==uf_find(bl[1]):\n BAD[bl[0]]-=1\n BAD[bl[1]]-=1\n\nANS=[str(SCO[uf_find(i)] + BAD[i] -1) for i in range(1,n+1)]\nprint(" ".join(ANS))\n \n'] | ['Runtime Error', 'Accepted'] | ['s449526501', 's280442001'] | [40628.0, 55640.0] | [2106.0, 883.0] | [925, 930] |
p02762 | u475503988 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["import sys\ninput = sys.stdin.buffer.readline\n\nclass UnionFind():\n \n def __init__(self, n):\n self.n = n\n self.parent = [-1]*(n+1) \n self.rank = [0]*(n+1) \n\n def root(self, x):\n \n if self.parent[x] < 0: \n return x\n else:\n self.parent[x] = self.root(self.parent[x]) \n return self.parent[x]\n \n def unite(self, x, y):\n \n x = self.root(x)\n y = self.root(y)\n if x == y:\n return 0\n elif self.rank[x] > self.rank[y]:\n self.parent[y] = x\n else:\n self.parent[x] = y\n if self.rank[x] == self.rank[y]:\n self.rank[y] += 1\n\n def isSame(self, x, y):\n \n return self.root(x) == self.root(y) or x==y\n\nN, M, K = map(int, input().split())\nfriend = [[0]*N for _ in range(N)]\nblock = [[0]*N for _ in range(N)]\nuf = UnionFind(N)\nfor i in range(M):\n A, B = map(int, input().split())\n friend[A-1][B-1] = 1\n friend[B-1][A-1] = 1\n uf.unite(A-1, B-1)\nfor j in range(K):\n C, D = map(int, input().split())\n block[C-1][D-1] = 1\n block[D-1][C-1] = 1\n\nfor i in range(N):\n ans = 0\n for j in range(N):\n if i == j:\n continue\n elif uf.isSame(i,j) and friend[i][j] == 0 and block[i][j] == 0:\n ans += 1\n print(ans, end= ' ')\n", 'import sys\n\ndef input(): return sys.stdin.readline().rstrip()\nsys.setrecursionlimit(10 ** 7)\n\n\nclass UnionFind():\n \n def __init__(self, n):\n self.n = n\n self.parent = [-1]*(n+1) \n self.rank = [0]*(n+1) \n\n def root(self, x):\n \n if self.parent[x] < 0: \n return x\n else:\n self.parent[x] = self.root(self.parent[x]) \n return self.parent[x]\n \n def unite(self, x, y):\n \n x = self.root(x)\n y = self.root(y)\n if x == y:\n return 0\n elif self.rank[x] > self.rank[y]:\n self.parent[x] += self.parent[y]\n self.parent[y] = x\n else:\n self.parent[y] += self.parent[x]\n self.parent[x] = y\n if self.rank[x] == self.rank[y]:\n self.rank[y] += 1\n\n def isSame(self, x, y):\n \n return self.root(x) == self.root(y) or x==y\n \n def size(self, x):\n \n return -self.parent[self.root(x)]\n\n\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\nfriends = [[] for _ in range(N)]\nblocks = [[] for _ in range(N)]\nfor i in range(M):\n A, B = map(int, input().split())\n A -= 1; B -= 1\n uf.unite(A, B)\n friends[A].append(B)\n friends[B].append(A)\nfor i in range(K):\n C, D = map(int, input().split())\n C -= 1; D -= 1\n blocks[C].append(D)\n blocks[D].append(C)\n\nans = [0] * N\nfor i in range(N):\n ans[i] = uf.size(i) - 1 \n ans[i] -= len(friends[i]) \n block_num = 0\n for j in blocks[i]:\n if uf.isSame(i,j):\n block_num += 1\n ans[i] -= block_num\n\nprint(*ans)\n'] | ['Time Limit Exceeded', 'Accepted'] | ['s966438868', 's767100550'] | [2000628.0, 47588.0] | [2226.0, 1282.0] | [1599, 2036] |
p02762 | u480264129 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["n,m,k=map(int,input().split())\nfr=[input() for i in range(m)]\nbl=[input() for i in range(k)]\nrel=[[0]*n for i in range(n)]\nfor i in range(n):\n rel[i][i]=''\nrelmap=[0]*n\nfor l in fr:\n a,b=map(int,l.split())\n rel[a-1][b-1]+=1\n rel[b-1][a-1]+=1\nfor l in bl:\n a,b=map(int,l.split())\n rel[a-1][b-1]-=1\n rel[b-1][a-1]-=1\n\n#print(rel)", "n,m,k=map(int,input().split())\nrelfr={i:set() for i in range(n)}\nrelbl={i:set() for i in range(n)}\nfor i in range(m):\n a,b=map(int,input().split())\n relfr[a-1].add(b-1)\n relfr[b-1].add(a-1)\nfor i in range(k):\n a,b=map(int,input().split())\n relbl[a-1].add(b-1)\n relbl[b-1].add(a-1)\nblsiz=[0 for i in range(n)]\nans=[0]*n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.root = [-1]*(n+1)\n self.rnk = [0]*(n+1)\n def Find_Root(self, x):\n if(self.root[x] < 0):\n return x\n else:\n self.root[x] = self.Find_Root(self.root[x])\n return self.root[x]\n def Unite(self, x, y):\n x = self.Find_Root(x)\n y = self.Find_Root(y)\n if(x == y):\n return\n elif(self.rnk[x] > self.rnk[y]):\n self.root[x] += self.root[y]\n self.root[y] = x\n else:\n self.root[y] += self.root[x]\n self.root[x] = y\n if(self.rnk[x] == self.rnk[y]):\n self.rnk[y] += 1\n def isSameGroup(self, x, y):\n return self.Find_Root(x) == self.Find_Root(y)\n def Count(self, x):\n return -self.root[self.Find_Root(x)]\nuf=UnionFind(n)\nfor i in range(n):\n for j in relfr[i]:\n uf.Unite(i,j)\nfor i in range(n):\n for j in relbl[i]:\n if uf.isSameGroup(i,j):\n blsiz[i]+=1\nfor i in range(n):\n ans[i]=uf.Count(i)-len(relfr[i])-blsiz[i]-1\n\nprint(' '.join(map(str,ans)))"] | ['Wrong Answer', 'Accepted'] | ['s511051545', 's055770876'] | [1854112.0, 99560.0] | [2223.0, 1780.0] | [353, 1440] |
p02762 | u486251525 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["import sys\ninput = sys.stdin.readline\nN, M, K = map(int, input().split())\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\nuf = UnionFind(N)\n\nab = []\nfor _ in range(M):\n a, b = map(int, input().split())\n uf.union(a - 1, b - 1)\n ab.append([a, b])\n\nout = []\nfor x in range(N):\n out.append(uf.size(x)-1)\n \n\nfor x in ab:\n out[x[0] - 1] -= 1\n out[x[1] - 1] -= 1\n\ncd = []\nfor _ in range(K):\n c, d = map(int, input().split())\n if uf.same(c - 1, d - 1):\n out[c - 1] -= 1\n out[d - 1] -= 1\nprint(out)\n", 'import sys\ninput = sys.stdin.readline\nN, M, K = map(int, input().split())\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\nuf = UnionFind(N)\n\nab = []\nfor _ in range(M):\n a, b = map(int, input().split())\n uf.union(a - 1, b - 1)\n ab.append([a, b])\n\nout = []\nfor x in range(N):\n out.append(uf.size(x)-1)\n \n\nfor x in ab:\n out[x[0] - 1] -= 1\n out[x[1] - 1] -= 1\n\ncd = []\nfor _ in range(K):\n c, d = map(int, input().split())\n if uf.same(c - 1, d - 1):\n out[c - 1] -= 1\n out[d - 1] -= 1\nprint(" ".join(map(str, out)))\n'] | ['Wrong Answer', 'Accepted'] | ['s847582814', 's810750991'] | [29628.0, 34624.0] | [813.0, 822.0] | [1652, 1672] |
p02762 | u490553751 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['#template\ndef inputlist(): return [int(j) for j in input().split()]\nfrom collections import Counter\n#template\n\n#Union Find\nN,M,K = inputlist()\ngraph = [[] for _ in range(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)\nfor i in range(M):\n A,B = inputlist()\n graph[A-1].append(B-1)\n graph[B-1].append(A-1)\n unite(A-1,B-1)\nbgraph = [[] for _ in range(N)]\nfor i in range(K):\n C,D = inputlist()\n if same(C-1,D-1):\n bgraph[C-1].append(D-1)\n bgraph[D-1].append(C-1)\nli = [0]*N\nfor i in range(N):\n k = size(i)\n n = len(graph[i])\n m = len(bgraph[i])\n print(k,m,n)\n li[i] = k-n-m-1\nprint(*li)', '#template\ndef inputlist(): return [int(j) for j in input().split()]\nfrom collections import Counter\n#template\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\nN,M,K = inputlist()\nuf = UnionFind(N+1)\ngraph = [[] for _ in range(N+1)]\nfor i in range(M):\n a,b = inputlist()\n uf.union(a,b)\n graph[a].append(b)\n graph[b].append(a)\nbrogra = [[] for _ in range(N+1)]\nli = [0]*N\nfor i in range(K):\n c,d = inputlist()\n if uf.same(c,d):\n brogra[c].append(d)\n brogra[d].append(c)\nfor i in range(1,N+1):\n li[i-1] = uf.size(i) - len(graph[i]) - len(brogra[i]) -1\nprint(*li)'] | ['Wrong Answer', 'Accepted'] | ['s852330877', 's213778660'] | [52016.0, 47120.0] | [1508.0, 1512.0] | [1243, 1453] |
p02762 | u506858457 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['οΌ@YottyPG\u3000Qiita\nfrom collections import deque\n\nN,M,K = map(int,input().split())\nfriend = [list(map(int,input().split())) for _ in range(M)]\nblock = [list(map(int,input().split())) for _ in range(K)]\n\nf = [set() for _ in range(N+1)]\nb = [set() for _ in range(N+1)]\n\nfor i,j in friend:\n f[i].add(j)\n f[j].add(i)\nfor i,j in block:\n b[i].add(j)\n b[j].add(i)\n\nstack=deque()\nans = [0]*(N+1)\nvisited = [0]*(N+1)\n\nfor i in range(1,N+1):\n if visited[i]:\n continue\n link = {i}\n visited[i] = 1 \n stack.append(i)\n while stack:\n n = stack.pop()\n for j in f[n]:\n if visited[j]==0:\n stack.append(j)\n visited[j] = 1\n link.add(j)\n for i in link:\n ans[i] = len(link) - len(link & f[i]) - len(link & b[i]) - 1\nprint(*ans[1:])', '\nclass UnionFind:\n def __init__(self, n):\n self.n = n\n self.parent = [i for i in range(n)] \n self.rank = [1] * n \n self.size = [1] * n \n\n def find(self, x): \n if self.parent[x] == x:\n return x\n else:\n self.parent[x] = self.find(self.parent[x]) \n return self.parent[x]\n\n def unite(self, x, y): \n x = self.find(x)\n y = self.find(y)\n if x != y:\n if self.rank[x] < self.rank[y]:\n self.parent[x] = y\n self.size[y] += self.size[x]\n else:\n self.parent[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n def is_same(self, x, y): \n return self.find(x) == self.find(y)\n\n def group_size(self, x): \n return self.size[self.find(x)]\n\n\nN, M, K = map(int, input().split())\nA, B = [0] * M, [0] * M \nC, D = [0] * K, [0] * K \n\ndirect =[[] for _ in range(N)] \nuf = UnionFind(N) \n\nfor i in range(M):\n A[i], B[i] = map(int, input().split())\n A[i] -= 1\n B[i] -= 1\n direct[A[i]].append(B[i])\n direct[B[i]].append(A[i])\n uf.unite(A[i], B[i])\n\nfor i in range(K):\n C[i], D[i] = map(int, input().split())\n C[i] -= 1\n D[i] -= 1\n if uf.is_same(C[i], D[i]):\n direct[C[i]].append(D[i])\n direct[D[i]].append(C[i])\n\nans = [0] * N\nfor i in range(N):\n ans[i] = uf.group_size(i) - len(direct[i]) - 1\nprint(*ans)'] | ['Runtime Error', 'Accepted'] | ['s347080624', 's696203624'] | [2940.0, 41488.0] | [18.0, 1395.0] | [824, 2011] |
p02762 | u514383727 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['N, M, K = map(int, input().split())\nAB = [list(map(int, input().split())) for _ in range(M)]\nCD = [list(map(int, input().split())) for _ in range(K)]\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\nuf_friend = UnionFind(N)\n\nes_friend = [[] for _ in range(N)]\nes_block = [[] for _ in range(N)]\n\nfor i in range(M):\n uf_friend.union(AB[i][0]-1, AB[i][1]-1)\n es_friend[AB[i][0]-1].append(AB[i][1]-1)\n es_friend[AB[i][1]-1].append(AB[i][0]-1)\nfor i in range(K):\n es_block[CD[i][0]-1].append(CD[i][1]-1)\n es_block[CD[i][1]-1].append(CD[i][0]-1)\n\nans = [0 for _ in range(N)]\nfor root in uf_friend.roots():\n m = uf_friend.members(root)\n l = len(uf_friend.members(root))\n for i in range(l):\n for j in range(i+1, l):\n # if m[j] not in es_friend[m[i]] and m[j] not in es_block[m[i]]:\n ans[m[i]] += 1\n ans[m[j]] += 1\nprint(" ".join(list(map(str, ans))))\n', 'N, M, K = map(int, input().split())\nAB = [list(map(int, input().split())) for _ in range(M)]\nCD = [list(map(int, input().split())) for _ in range(K)]\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\nuf_friend = UnionFind(N)\nuf_block = UnionFind(N)\n\nes_friend = [0 for _ in range(N)]\nes_block = [0 for _ in range(N)]\n\nfor i in range(M):\n uf_friend.union(AB[i][0]-1, AB[i][1]-1)\n es_friend[AB[i][0]-1] += 1\n es_friend[AB[i][1]-1] += 1\nfor i in range(K):\n uf_block.union(CD[i][0]-1, CD[i][1]-1)\nfor i in range(K):\n if uf_friend.same(CD[i][0]-1, CD[i][1]-1):\n es_block[CD[i][0]-1] += 1\n es_block[CD[i][1]-1] += 1\n\n\nans = [0 for _ in range(N)]\nfor i in range(N):\n ans[i] = uf_friend.size(i) - es_friend[i] - es_block[i] - 1\n\nprint(" ".join(list(map(str, ans))))\n'] | ['Wrong Answer', 'Accepted'] | ['s165881468', 's733078188'] | [92628.0, 69840.0] | [2109.0, 1360.0] | [2006, 1888] |
p02762 | u521602455 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\nsys.setrecursionlimit(10**6)\nN,M,K=map(int,input().split())\nF=[[] for i in range(N)]\nfor _ in range(M):\n A,B=map(int,input().split())\n F[A-1].append(B-1)\n F[B-1].append(A-1)\nB=[[] for i in range(N)]\nfor _ in range(K):\n C,D=map(int,input().split())\n B[C-1].append(D-1)\n B[D-1].append(C-1)\nans=[0 for i in range(N)]\nseen=[False for i in range(N)]\nn=0\nG=[i for i in range(N)]\ndef root(i):\n if G[i]==i:\n return i\n else:\n a=root(G[i])\n G[i]=a\n return a\ndef union(i,j):\n x=root(i)\n y=root(j)\n if x==y:\n return\n else:\n if x>y:\n x,y=y,x\n G[y]=x\n return\nfor i in range(N):\n for f in F[i]:\n union(i, f)\ngroup={}\nfor i in range(N):\n if G[i] in group:\n group[G[i]]+=1\n else:\n group[G[i]]=1\nfor i in range(N):\n ans=group[G[i]]\n for f in F[i]:\n if root(i)==root(f):\n ans-=1\n for b in B[i]:\n if root(i)==root(b):\n ans-=1\n print(ans-1, end=" ")', 'import sys\nsys.setrecursionlimit(2000000)\nN,M,K=map(int,input().split())\nF=[set() for i in range(N)]\nfor _ in range(M):\n a,b=map(int,input().split())\n F[a-1].add(b-1)\n F[b-1].add(a-1)\nB=[set() for i in range(N)]\nfor _ in range(K):\n c,d=map(int,input().split())\n B[c-1].add(d-1)\n B[d-1].add(c-1)\n\ndef dps(i, j, c):\n s=0\n con=False\n for f in F[j]:\n if f not in c:\n con=True\n break\n if not con:\n return 0\n for f in F[j]:\n if f in c:\n continue\n c.add(f)\n if f not in F[i] and f not in B[i]:\n s+=1\n s+=dps(i,f,c)\n return s\nfor i in range(0,N):\n checked=set()\n print(dps(i, i, checked)-1, end=" ")', 'import sys\nsys.setrecursionlimit(2000000)\nN,M,K=map(int,input().split())\nF=[set() for i in range(N)]\nfor _ in range(M):\n a,b=map(int,input().split())\n F[a-1].add(b-1)\n F[b-1].add(a-1)\nB=[set() for i in range(N)]\nfor _ in range(K):\n c,d=map(int,input().split())\n B[c-1].add(d-1)\n B[d-1].add(c-1)\n\ndef dps(i, j, c):\n s=0\n con=False\n for f in F[j]:\n if f not in c:\n con=True\n c.add(f)\n if f not in F[i] and f not in B[i]:\n s+=1\n s+=dps(i,f,c)\n if not con:\n return 0\n else:\n return s\nfor i in range(0,N):\n checked=set()\n print(dps(i, i, checked)-1, end=" ")', 'N,M,K=map(int,input().split())\nF=[[] for i in range(N)]\nfor _ in range(M):\n A,B=map(int,input().split())\n F[A-1].append(B-1)\n F[B-1].append(A-1)\nB=[[] for i in range(N)]\nfor _ in range(K):\n C,D=map(int,input().split())\n B[C-1].append(D-1)\n B[D-1].append(C-1)\nans=[0 for i in range(N)]\nseen=[False for i in range(N)]\nn=0\nG=[i for i in range(N)]\ndef root(i):\n if G[i]==i:\n return i\n else:\n a=root(G[i])\n G[i]=a\n return a\ndef union(i,j):\n x=root(i)\n y=root(j)\n if x==y:\n return\n else:\n if x>y:\n x,y=y,x\n G[y]=x\n return\nfor i in range(N):\n for f in F[i]:\n union(i, f)\ngroup={}\nfor i in range(N):\n if G[i] in group:\n group[G[i]]+=1\n else:\n group[G[i]]=1\nfor i in range(N):\n ans=group[G[i]]\n for f in F[i]:\n if root(i)==root(f):\n ans-=1\n for b in B[i]:\n if root(i)==root(b):\n ans-=1\n print(ans-1, end=" ")', 'import sys\nsys.setrecursionlimit(2000000)\nN,M,K=map(int,input().split())\nF=[set() for i in range(N)]\nfor _ in range(M):\n a,b=map(int,input().split())\n F[a-1].add(b-1)\n F[b-1].add(a-1)\nB=[set() for i in range(N)]\nfor _ in range(K):\n c,d=map(int,input().split())\n B[c-1].add(d-1)\n B[d-1].add(c-1)\n\ndef dps(i, j, c, fr, bl):\n s=0\n con=False\n for f in F[j]:\n if f not in c:\n con=True\n c.add(f)\n if f not in fr and f not in bl:\n s+=1\n s+=dps(i,f,c, fr, bl)\n if not con:\n return 0\n else:\n return s\nfor i in range(0,N):\n checked=set([i])\n print(dps(i, i, checked, F[i], B[i]), end=" ")\n', 'import sys\nsys.setrecursionlimit(10**6)\nN,M,K=map(int,input().split())\nF=[[] for i in range(N)]\nfor _ in range(M):\n A,B=map(int,input().split())\n F[A-1].append(B-1)\n F[B-1].append(A-1)\nB=[[] for i in range(N)]\nfor _ in range(K):\n C,D=map(int,input().split())\n B[C-1].append(D-1)\n B[D-1].append(C-1)\nG=[i for i in range(N)]\ndef root(i):\n if G[i]==i:\n return i\n else:\n a=root(G[i])\n G[i]=a\n return a\ndef union(i,j):\n x=root(i)\n y=root(j)\n if x==y:\n return\n else:\n G[y]=x\n return\nfor i in range(N):\n for f in F[i]:\n union(i, f)\ngroup={}\nfor i in range(N):\n if G[i] in group:\n group[G[i]]+=1\n else:\n group[G[i]]=1\nfor i in range(N):\n ans=group[G[i]]\n for f in F[i]:\n if root(i)==root(f):\n ans-=1\n for b in B[i]:\n if root(i)==root(b):\n ans-=1\n print(ans-1, end=" ")', 'import sys\nsys.setrecursionlimit(2000000)\nN,M,K=map(int,input().split())\nF=[set() for i in range(N)]\nfor _ in range(M):\n a,b=map(int,input().split())\n F[a-1].add(b-1)\n F[b-1].add(a-1)\nB=[set() for i in range(N)]\nfor _ in range(K):\n c,d=map(int,input().split())\n B[c-1].add(d-1)\n B[d-1].add(c-1)\n\ndef dps(i, j, c):\n s=0\n con=False\n for f in F[j]:\n if f not in c:\n con=True\n c.add(f)\n if f not in F[i] and f not in B[i]:\n s+=1\n s+=dps(i,f,c)\n if not con:\n return 0\n else:\n return s\nfor i in range(0,N):\n checked=set([i])\n print(dps(i, i, checked), end=" ")', 'import sys\nsys.setrecursionlimit(2000000)\nN,M,K=map(int,input().split())\nF=[set() for i in range(N)]\nfor _ in range(M):\n a,b=map(int,input().split())\n F[a-1].add(b-1)\n F[b-1].add(a-1)\nB=[set() for i in range(N)]\nfor _ in range(K):\n c,d=map(int,input().split())\n B[c-1].add(d-1)\n B[d-1].add(c-1)\n\ndef dps(i, j, c):\n s=0\n con=False\n for f in F[j]:\n if f not in c:\n con=True\n break\n if not con:\n return 0\n for f in F[j]:\n if f in c:\n continue\n c.add(f)\n if f not in F[i] and f not in B[i]:\n s+=1\n s+=dps(i,f,c)\n return s\nprint(F, B)\nfor i in range(0,N):\n checked=set()\n print(dps(i, i, checked)-1, end=" ")', 'N,M,K=map(int,input().split())\nA=[];B=[]\nfor i in range(M):\n a,b=map(int,input().split())\n A.append(a);B.append(b)\nC=[];D=[]\nfor i in range(K):\n c,d=map(int,input().split())\n C.append(c);D.append(d)\nf=[set() for i in range(N)]\nb=[set() for i in range(N)]\nfor i in range(M):\n f[A[i]-1].add(B[i]-1)\n f[B[i]-1].add(A[i]-1)\nfor i in range(K):\n b[C[i]-1].add(D[i]-1)\n b[D[i]-1].add(C[i]-1)\nchecked=[False for i in range(N)]\nclass UnionFind:\n def __init__(self,n):\n self.n=n\n self.parents=[-1]*n\n def root(self,x):\n if self.parents[x]<0:\n return x\n else:\n self.parents[x]=self.root(self.parents[x])\n return self.parents[x]\n def union(self,x,y):\n x=self.root(x)\n y=self.root(y)\n if x==y:\n 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 same(self,x,y):\n return self.root(x)==self.root(y)\n def size(self,x):\n return -self.parents[self.root(x)]\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())\nuf=UnionFind(N)\nfor i in range(N):\n for people in f[i]:\n uf.union(i,people)\nans=[]\nfor i in range(N):\n c=uf.size(i)\n bl=0\n for x in b[i]:\n if uf.same(i,x):\n bl+=1\n ans.append(c-bl-1-len(f[i]))\nprint(*ans)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Time Limit Exceeded', 'Wrong Answer', 'Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s009843604', 's043725116', 's092670346', 's155001577', 's329717766', 's487071746', 's586237167', 's633235583', 's522212019'] | [49012.0, 89960.0, 89980.0, 49048.0, 90120.0, 51572.0, 89980.0, 94204.0, 93344.0] | [1642.0, 2108.0, 2109.0, 1723.0, 2109.0, 1706.0, 2110.0, 2109.0, 1760.0] | [1020, 719, 672, 980, 698, 923, 673, 731, 1463] |
p02762 | u531603069 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['class unionfindtree:\n def __init__(self, n):\n self.root = [i for i in range(n + 1)]\n self.friendcount = [1] * (n + 1)\n\n def getroot(self, x):\n node = self.root[x]\n if node == x:\n return x\n self.root[x] = self.getroot(node)\n return self.root[x]\n\n def unite(self, x, y):\n xroot = self.getroot(x)\n yroot = self.getroot(y)\n if xroot == yroot:\n return\n self.root[xroot] = yroot\n self.friendcount[yroot] += self.friendcount[xroot]\n\n def getfriendcount(self, x):\n xroot = self.getroot(x)\n return self.friendcount[xroot]\n\n def same(self, x, y):\n if self.getroot(x) == self.getroot(y):\n return true\n return false\n\n\nn, m, k = map(int, input().split())\na = [0] * m\nb = [0] * m\nc = [0] * k\nd = [0] * k\n\nfor i in range(m):\n a[i], b[i] = map(int, input().split())\nfor i in range(k):\n c[i], d[i] = map(int, input().split())\n\ntree = unionfindtree(n)\nfor i in range(m):\n tree.unite(a[i], b[i])\n\nfriendscount = [0] * (n + 1)\nblockcount = [0] * (n + 1)\nfor i in range(m):\n friendscount[a[i]] += 1\n friendscount[b[i]] += 1\nfor i in range(k):\n if tree.same(c[i], d[i]):\n blockcount[c[i]] += 1\n blockcount[d[i]] += 1\n\n# print(1, 4, tree.same(1, 4))\n# print(1, tree.getfriendcount(1))\n# print(4, tree.getfriendcount(4))\n\nresult = [str(tree.getfriendcount(i) - 1 - friendscount[i] - blockcount[i]) for i in range(1, n + 1)]\nprint(" ".join(result))\n\n', 'class UnionFindTree:\n def __init__(self, N):\n self.root = [i for i in range(N + 1)]\n self.friendcount = [1] * (N + 1)\n\n def getroot(self, x):\n node = self.root[x]\n if node == x:\n return x\n self.root[x] = self.getroot(node)\n return self.root[x]\n\n def unite(self, x, y):\n xroot = self.getroot(x)\n yroot = self.getroot(y)\n if xroot == yroot:\n return\n if xroot > yroot:\n self.root[xroot] = yroot\n self.friendcount[yroot] += self.friendcount[xroot]\n else:\n self.root[yroot] = xroot\n self.friendcount[xroot] += self.friendcount[yroot]\n\n def getfriendcount(self, x):\n xroot = self.getroot(x)\n return self.friendcount[xroot]\n\n def same(self, x, y):\n if self.getroot(x) == self.getroot(y):\n return True\n return False\n\n\nN, M, K = map(int, input().split())\nA = [0] * M\nB = [0] * M\nC = [0] * K\nD = [0] * K\n\nfor i in range(M):\n A[i], B[i] = map(int, input().split())\nfor i in range(K):\n C[i], D[i] = map(int, input().split())\n\ntree = UnionFindTree(N + 1)\nfor i in range(M):\n tree.unite(A[i], B[i])\n\nfriendscount = [0] * (N + 1)\nblockcount = [0] * (N + 1)\nfor i in range(M):\n friendscount[A[i]] += 1\n friendscount[B[i]] += 1\nfor i in range(K):\n if tree.same(C[i], D[i]):\n blockcount[C[i]] += 1\n blockcount[D[i]] += 1\n\nresult = [str(tree.getfriendcount(i) - 1 - friendscount[i] - blockcount[i]) for i in range(1, N + 1)]\nprint(" ".join(result))\n'] | ['Runtime Error', 'Accepted'] | ['s549814066', 's218329002'] | [25264.0, 33072.0] | [814.0, 1024.0] | [1510, 1559] |
p02762 | u537892680 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['# D - Friend Suggestions\n\nfrom queue import Queue\n\nN, M, K = map(int, input().split())\n\nfriends = [(i, []) for i in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a, b = a - 1, b - 1\n friends[a][1].append(b)\n friends[b][1].append(a)\n\nblocks = [(i, []) for i in range(N)]\nfor _ in range(K):\n c, d = map(int, input().split())\n c, d = c - 1, d - 1\n blocks[c][1].append(d)\n blocks[d][1].append(c)\n\nQ = Queue()\ncnt = [0] * N\nfor i in range(N):\n visited = [False] * N\n Q.put(friends[i])\n visited[i] = True\n while not Q.empty():\n q = Q.get()\n if (q[0] != i and\n q[0] not in friends[i][1] and\n q[0] not in blocks[i][1]):\n cnt[i] += 1\n for j in q[1]:\n if not visited[j]:\n visited[j] = True\n Q.put(friends[j])\n\nprint(cnt)\n', '# D - Friend Suggestions\n\nfrom queue import Queue\n\nN, M, K = map(int, input().split())\n\nfriends = [(i, []) for i in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a, b = a - 1, b - 1\n friends[a][1].append(b)\n friends[b][1].append(a)\n\nblocks = [(i, []) for i in range(N)]\nfor _ in range(K):\n c, d = map(int, input().split())\n c, d = c - 1, d - 1\n blocks[c][1].append(d)\n blocks[d][1].append(c)\n\nQ = Queue()\nvisited = [False] * N\ngroup = [0] * N\nfor i in range(N):\n if visited[i]:\n continue\n Q.put(friends[i])\n visited[i] = True\n while not Q.empty():\n q = Q.get()\n group[q[0]] = i\n for j in q[1]:\n if not visited[j]:\n visited[j] = True\n Q.put(friends[j])\n\ncnt = {}\nfor num in group:\n if num in cnt:\n cnt[num] += 1\n else:\n cnt[num] = 1\n\nans = [0] * N\nfor i in range(N):\n ans[i] = cnt[group[i]] - len(friends[i][1]) - 1\n for block in blocks[i][1]:\n if group[i] == group[block]:\n ans[i] -= 1\n\nprint(*ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s501779206', 's536155386'] | [61916.0, 68112.0] | [2107.0, 1854.0] | [869, 1067] |
p02762 | u539367121 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["def makenetwork():\n for n in range(1,N+1):\n visited=set((n,))\n while visited:\n v=visited.pop()\n D[n].append(v)\n for i in F[v]:\n if i not in D[n]:\n visited.add(i)\n\n\ndef main():\n makenetwork()\n #print(D)\n #ans=[0]*(N+1)\n #for n in range(1, N+1):\n #\tans[n]=len(D[n]) - len(F[n]) - len(set(D[n])&set(B[n])) - 1\n #print(*ans[1:])\n\n\nif __name__=='__main__':\n N, M, K = map(int, input().split())\n F=[[] for n in range(N+1)]\n for m in range(M):\n a, b = map(int, input().split())\n F[a]+=[b]\n F[b]+=[a]\n B=[[] for n in range(N+1)]\n for k in range(K):\n c, d = map(int, input().split())\n B[c]+=[d]\n B[d]+=[c]\n D=[[] for n in range(N+1)]\n #print(F)\n \n main()", "def makeRelation():\n visited=[False]*(N+1)\n g=0 # group\n for n in range(1,N+1):\n if visited[n]:\n continue\n q={n}\n D.append(set())\n while q:\n j=q.pop()\n for i in F[j]: # search for friend\n if not visited[i]:\n visited[i]=True\n q.add(i)\n D[g]|={i}\n g+=1\n \ndef main():\n makeRelation()\n #print(D)\n for g in D:\n for d in g:\n ans[d]=len(g) - len(F[d]) - len(g&B[d]) - 1\n print(*ans[1:])\n\n\nif __name__=='__main__':\n N, M, K = map(int, input().split())\n F=[set() for n in range(N+1)]\n AB=[list(map(int, input().split())) for m in range(M)]\n for a,b in AB:\n F[a].add(b)\n F[b].add(a)\n B=[set() for n in range(N+1)]\n CD=[list(map(int, input().split())) for k in range(K)]\n for c,d in CD:\n B[c].add(d)\n B[d].add(c)\n D=[]\n #print(F)\n \n ans=[0]*(N+1)\n main()"] | ['Wrong Answer', 'Accepted'] | ['s102649589', 's111990760'] | [81456.0, 146380.0] | [2207.0, 1217.0] | [725, 858] |
p02762 | u540761833 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["import sys\ndef input(): return sys.stdin.readline().strip()\nN,M,K = map(int,input().split())\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())\nuni = UnionFind(N)\nfrd = [[] for i in range(N)]\nbl = [[] for i in range(N)]\nfor i in range(M):\n a,b= map(int,input().split())\n a -= 1\n b -= 1\n uni.union(a,b)\n frd[a].append(b)\n frd[b].append(a)\nfor i in range(K):\n a,b= map(int,input().split())\n a -= 1\n b -= 1\n bl[a].append(b)\n bl[b].append(a)\nans = [0 for i in range(N)]\nfor i in range(N):\n a = set(uni.members(i)) - set(bl[i])\n print(len(a)-len(frd[i])-1,sep=' ')", "import sys\ndef input(): return sys.stdin.readline().strip()\nN,M,K = map(int,input().split())\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())\nuni = UnionFind(N)\nfrd = [0 for i in range(N)]\nbl = [[] for i in range(N)]\nfor i in range(M):\n a,b= map(int,input().split())\n a -= 1\n b -= 1\n uni.union(a,b)\n frd[a] +=1\n frd[b] += 1\nfor i in range(K):\n a,b= map(int,input().split())\n a -= 1\n b -= 1\n bl[a].append(b)\n bl[b].append(a)\nans = [0 for i in range(N)]\nfor i in range(N):\n a = set(uni.members(i)) - set(bl[i])\n print(len(a)-frd[i]-1,end=' ')", "import sys\ndef input(): return sys.stdin.readline().strip()\nN,M,K = map(int,input().split())\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())\nuni = UnionFind(N)\nfn = [0 for i in range(N)]\nbl = [[] for i in range(N)]\nbn = [0 for i in range(N)]\nfor i in range(M):\n a,b= map(int,input().split())\n a -= 1\n b -= 1\n uni.union(a,b)\n fn[a] +=1\n fn[b] += 1\nfor i in range(K):\n a,b= map(int,input().split())\n a -= 1\n b -= 1\n if uni.find(a) == uni.find(b):\n bn[a] += 1\n bn[b] += 1\nans = [0 for i in range(N)]\nfor i in range(N):\n ans[i] = uni.size(i) - bn[i] - fn[i] -1\nprint(' '.join([str(i) for i in ans]))"] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s815324747', 's997240425', 's683397348'] | [64368.0, 52480.0, 26728.0] | [2107.0, 2106.0, 857.0] | [1693, 1676, 1740] |
p02762 | u557565572 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['\n# # import heapq\n# # from copy import deepcopy\nfrom collections import deque\n# # from collections import Counter\n# # from itertools import accumulate\n# # from itertools import permutations\n# import numpy as np\n# # import math\n\nn, m, k = map(int, input().split())\n# a = list(map(int, input().split()))\n# n = int(input())\n\nfriend =[[] for _ in range(n)]\nblock = [[] for _ in range(n)]\nfor i in range(m):\n a,b = map(int, input().split())\n a,b = a-1,b-1\n friend[a].append(b); friend[b].append(a)\n\nfor i in range(k):\n c,d = map(int, input().split())\n c,d = c-1,d-1\n block[c].append(d); block[d].append(c)\n\ndef suggest(s):\n count = 0\n seen = [False] * n\n que = deque([s])\n while que:\n start = que.popleft()\n seen[start] = True\n for i in friend[start]:\n if seen[i]: continue\n else:\n que.append(i)\n\n for i in range(n):\n if i != s and seen[i] and (i not in friend[s]) and (i not in block[s]):\n count += 1\n\n return count\n\nfor i in range(n):\n print(suggest(i))\n\n\n\n', '\n# # import heapq\n# # from copy import deepcopy\nfrom collections import deque\n# # from collections import Counter\n# # from itertools import accumulate\n# # from itertools import permutations\n# import numpy as np\n# # import math\n\nn, m, k = map(int, input().split())\n# a = list(map(int, input().split()))\n# n = int(input())\n\nfriend =[[] for _ in range(n)]\nblock = [[] for _ in range(n)]\nfor i in range(m):\n a,b = map(int, input().split())\n a,b = a-1,b-1\n friend[a].append(b); friend[b].append(a)\n\nfor i in range(k):\n c,d = map(int, input().split())\n c,d = c-1,d-1\n block[c].append(d); block[d].append(c)\n\ndef suggest(s):\n count = 0\n seen = [False] * n\n que = deque([s])\n while que:\n start = que.pop()\n seen[start] = True\n for i in friend[start]:\n if seen[i]: continue\n else:\n que.append(i)\n\n for i in range(n):\n if i != s and seen[i] and (i not in friend[s]) and (i not in block[s]):\n count += 1\n\n return count\n\nfor i in range(n):\n print(suggest(i))\n\n\n\n', '\n# import heapq\n# from copy import deepcopy\n# from collections import deque\n# from collections import Counter\n# from itertools import accumulate\n# from itertools import permutations\n# import numpy as np\n# import math\n\n\n# a = list(map(int, input().split()))\n# n = int(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 same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\nuf = UnionFind(n)\nfriend =[[] for _ in range(n)]\nblock = [[] for _ in range(n)]\nfor i in range(m):\n a,b = map(int, input().split())\n a,b = a-1,b-1\n uf.union(a,b)\n friend[a].append(b); friend[b].append(a)\n\nfor i in range(k):\n c,d = map(int, input().split())\n c,d = c-1,d-1\n if uf.same(c,d):\n block[c].append(d); block[d].append(c)\n\nw = [0] * n\nfor i in range(n):\n w[i] = uf.size(i) - len(friend[i]) - len(block[i]) - 1\n\nprint(*w)', '\n# import heapq\n# from copy import deepcopy\n# from collections import deque\n# from collections import Counter\n# from itertools import accumulate\n# from itertools import permutations\n# import numpy as np\n# import math\n\nn, m, k = map(int, input().split())\n# a = list(map(int, input().split()))\n# n = int(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 same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\nuf = UnionFind(n)\nfriend =[[] for _ in range(n)]\nblock = [[] for _ in range(n)]\nfor i in range(m):\n a,b = map(int, input().split())\n a,b = a-1,b-1\n uf.union(a,b)\n friend[a].append(b); friend[b].append(a)\n\nfor i in range(k):\n c,d = map(int, input().split())\n c,d = c-1,d-1\n if uf.same(c,d):\n block[c].append(d); block[d].append(c)\n\nw = [0] * n\nfor i in range(n):\n w[i] = uf.size(i) - len(friend[i]) - len(block[i]) - 1\n\nprint(*w)'] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Runtime Error', 'Accepted'] | ['s320661532', 's478523053', 's965587985', 's482572840'] | [41612.0, 41604.0, 3064.0, 46760.0] | [2109.0, 2106.0, 18.0, 1302.0] | [1084, 1080, 1465, 1463] |
p02762 | u563676207 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['# input\nN, M, K = map(int, input().split())\n\nFrends = [[] for _ in range(N)]\nFs = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n Frends[a].append(b)\n Frends[b].append(a)\n if a < b:\n Fs[a].append[b]\n else:\n Fs[b].append[a]\n\nBlocked = [[] for _ in range(N)]\nfor _ in range(K):\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n Blocked[c].append(d)\n Blocked[d].append(c)\n\n# process\n\nfg = []\nfor i in range (N):\n l = Fs[i] \n if len(l) == 0:\n continue\n\n l.append(i)\n s = set(l)\n\n t = -1\n j = 0\n fglen = len(fg)\n while j < fglen:\n sfg = s&fg[j]\n if len(sfg) > 0:\n if t < 0:\n t = j\n fg[j] |= s\n else:\n fg[t] |= fg[j]\n fg.pop(j)\n fglen -= 1\n j += 1\n\n if t < 0:\n fg.append(s)\n\n\ncand = [0 for _ in range(N)]\nfor g in fg:\n for f in g:\n cand[f] = len(g)-len(Frends[f])-len(set(Blocked[f])&g)-1\n\n# output\n#print(fg)\nprint(" ".join(map(str, cand)))\n', '# input\nN, M, K = map(int, input().split())\n\nFrends = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n Frends[a].append(b)\n Frends[b].append(a)\n\nBlocked = [[] for _ in range(N)]\nfor _ in range(K):\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n Blocked[c].append(d)\n Blocked[d].append(c)\n\n# process\n\nfg = []\nfor i in range (N):\n fs = Frends[i]\n for f in fs:\n if i > f:\n break\n\n t = -1\n s = set([i, f])\n j = 0\n fglen = len(fg)\n while j < fglen:\n g = fg[j]\n sand = s&g\n if t < 0:\n if len(sand) > 0:\n t = j\n if sand == s:\n break\n elif i in sand:\n g.add(f)\n else:\n g.add(i)\n\n elif len(sand) > 0:\n \n fg[t] = fg[t] | g\n fg.pop(j)\n fglen -= 1\n \n j += 1\n\n if t < 0:\n fg.append(s)\n\n\ncand = [0 for _ in range(N)]\nfor i in range(N):\n for g in fg:\n if i in g:\n cand[i] = len(g)-len(Frends[i])-len(set(Blocked[i])&g)-1\n break\n\n# output\n#print(fg)\nprint(" ".join(map(str, cand)))\n', '# input\nN, M, K = map(int, input().split())\n\nFrends = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n Frends[a].append(b)\n Frends[b].append(a)\n\nBlocked = [[] for _ in range(N)]\nfor _ in range(K):\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n Blocked[c].append(d)\n Blocked[d].append(c)\n\n# process\n\nfg = []\nfor i in range (N):\n l = [x for x in Frends[i] if x>i]\n if len(l) == 0:\n continue\n\n l.append(i)\n s = set(l)\n\n t = -1\n j = 0\n fglen = len(fg)\n while j < fglen:\n sfg = s&fg[j]\n if len(sfg) > 0:\n if t < 0:\n t = j\n fg[j] |= s\n else:\n fg[t] |= fg[j]\n fg.pop(j)\n fglen -= 1\n j += 1\n\n if t < 0:\n fg.append(s)\n\n\ncand = [0 for _ in range(N)]\nfor g in fg:\n for f in g:\n cand[f] = len(g)-len(Frends[f])-len(set(Blocked[f])&g)-1\n\n# output\nprint(fg)\nprint(" ".join(map(str, cand)))\n', '# input\nN, M, K = map(int, input().split())\n\nFrends = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n if a < b:\n Frends[a].append(b)\n else:\n Frends[b].append(a)\n\nBlocked = [[] for _ in range(N)]\nfor _ in range(K):\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n if c < d:\n Blocked[c].append(d)\n else:\n Blocked[d].append(c)\n\n# process\n\nfg = []\nfor i in range (N):\n fs = Frends[i]\n for f in fs:\n flg = False\n for g in fg:\n if i in g and f in g:\n flg = True\n continue\n elif not (i in g or f in g):\n continue\n else:\n if i in g:\n g.add(f)\n else:\n g.add(i)\n \n flg = True\n break\n \n if not flg:\n fg.append(set([i, f]))\n\nfor i in range(len(fg)-1):\n for j in range(i+1, len(fg)):\n if fg[i] & fg[j] != set():\n fg[i] = fg[i] | fg[j]\n fg[j].clear()\n\n#print(fg)\n\n\ncand = []\nfor i in range(N):\n for g in fg:\n if i in g:\n for f in g:\n if i < f and not f in Frends[i] and not f in Blocked[i]:\n cand.append((i, f,))\n\nprint(cand)\n\n\nans = [0 for _ in range(N)]\nfor c in cand:\n a, b = c\n ans[a] += 1\n ans[b] += 1\n\n# output\nprint(" ".join(map(str, ans)))\n', '# input\nN, M, K = map(int, input().split())\n\nFrends = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n Frends[a].append(b)\n Frends[b].append(a)\n\nBlocked = [[] for _ in range(N)]\nfor _ in range(K):\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n Blocked[c].append(d)\n Blocked[d].append(c)\n\n# process\n\nfg = []\nfor i in range (N):\n fs = Frends[i]\n for f in fs:\n if i > f:\n continue\n\n t = -1\n s = set([i, f])\n j = 0\n fglen = len(fg)\n while j < fglen:\n g = fg[j]\n sand = s&g\n if t < 0:\n if len(sand) > 0:\n t = j\n if sand == s:\n break\n elif i in sand:\n g.add(f)\n else:\n g.add(i)\n\n elif len(sand) > 0:\n \n fg[t] = fg[t] | g\n fg.pop(j)\n fglen -= 1\n \n j += 1\n\n if t < 0:\n fg.append(s)\n\n\ncand = [0 for _ in range(N)]\nfor i in range(N):\n for g in fg:\n if i in g:\n cand[i] = len(g)-len(Frends[i])-len(set(Blocked[i])&g)-1\n break\n\n# output\nprint(fg)\nprint(" ".join(map(str, cand)))\n', '# input\nN, M, K = map(int, input().split())\n\nFriends = [set() for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n Friends[a].add(b)\n Friends[b].add(a)\n\nBlocked = [set() for _ in range(N)]\nfor _ in range(K):\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n Blocked[c].add(d)\n Blocked[d].add(c)\n\n# process\n\nchecked = set()\nans = [0]*N\n\nfor i in range (N):\n if i in checked:\n continue\n \n fg = set()\n\n stack = list(Friends[i])\n while stack:\n f = stack.pop()\n if f in checked:\n continue\n\n checked.add(f)\n fg.add(f)\n stack.extend(Friends[f])\n\n for f in fg:\n ans[f] += len(fg)-1-len(fg&(Friends[f]|Blocked[f]))\n\n# output\nprint(" ".join(map(str, ans)))\n'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s069616419', 's413110824', 's422047109', 's501765817', 's794683172', 's686569331'] | [29140.0, 51672.0, 57044.0, 252620.0, 57052.0, 87824.0] | [297.0, 2106.0, 2106.0, 2120.0, 2106.0, 1308.0] | [1168, 1457, 1090, 1556, 1459, 821] |
p02762 | u566159623 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import defaultdict, deque\nn, m, k = map(int, input().split())\nfriends = defaultdict(list)\nblock = defaultdict(list)\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a].append(b)\n friends[b].append(a)\nfor _ in range(k):\n c, d = map(int, input().split())\n block[c].append(d)\n block[d].append(c)\nprint(friends)\nprint(block)\nans =[]\nfor i in range(n):\n ans.append(n-len(friends[i+1])-len(block[i+1])-1)\nprint(ans)', 'from collections import defaultdict, deque\nn, m, k = map(int, input().split())\nfriends = defaultdict(set)\nblock = defaultdict(set)\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a].add(b)\n friends[b].add(a)\nfor _ in range(k):\n c, d = map(int, input().split())\n block[c].add(d)\n block[d].add(c)\n#print(friends)\n#print(block)\n\nroopname = []\nroop = defaultdict(set)\nseen = [0]*n\n\n\nfor i in range(n):\n if not seen[i]==0:\n continue\n seen[i] = i+1\n roopname.append(i+1)\n roop[i+1].add(i+1)\n queue = deque(friends[i+1])\n while queue:\n p = queue.popleft()\n if not seen[p-1]==0:continue\n seen[p-1] = i+1\n roop[i+1].add(p)\n for j in friends[p]:\n if seen[j-1]==0:\n queue.append(j)\n#print(roopname)\n#print(roop)\n\nans = [len(roop[seen[i]])-len(roop[seen[i]]&friends[i+1])-len(roop[seen[i]]&block[i+1])-1 for i in range(n)]\n\n \n\nL=[str(a) for a in ans]\nL=" ".join(L)\nprint(L)'] | ['Wrong Answer', 'Accepted'] | ['s017835755', 's554072446'] | [62392.0, 144196.0] | [1218.0, 1352.0] | [460, 995] |
p02762 | u568576853 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import deque\nimport numpy as np\nn,m,k=map(int,input().split())\nlink=[[] for _ in range(n)]\nblock=[[] for _ in range(n)]\nans=[]\ns=[]\nfor i in range(m):\n a,b=map(int,input().split())\n link[a-1].append(b-1)\n link[b-1].append(a-1)\nfor i in range(k):\n a,b=map(int,input().split())\n block[a-1].append(b-1)\n block[b-1].append(a-1)\nfor i in range(n):\n visited=set()\n q=deque([i])\n while len(q)>0:\n x=q.pop()\n visited.add(x)\n for j in link[x]:\n if j in visited:\n continue\n elif j in q:\n continue\n else:q.append(j)\n ans.append(len(visited))\n s.append(visited)', 'from collections import deque\nn,m,k=map(int,input().split())\nlink=[[] for _ in range(n)]\nblock=[[] for _ in range(n)]\nans=[0]*n\ns=[]\nfor i in range(m):\n a,b=map(int,input().split())\n link[a-1].append(b-1)\n link[b-1].append(a-1)\nfor i in range(k):\n a,b=map(int,input().split())\n block[a-1].append(b-1)\n block[b-1].append(a-1)\nfor i in range(n):\n u=[0]*n\n q=deque([i])\n while len(q)>0:\n x=q.pop()\n u[x]=1\n for j in link[x]:\n if u[j]==1:\n continue\n elif j in q:\n continue\n else:q.append(j)\n s.append(u)\n ans[i]=sum(u)-1', 'class UnionFind():\n def __init__(self,n):\n self.n=n\n self.root=[-1]*(n+1)\n self.rank=[0]*(n+1)\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 0\n elif self.rank[x]>self.rank[y]:\n self.root[x]+=self.root[y]\n self.root[y]=x\n else:\n self.root[y]+=self.root[x]\n self.root[x]=y\n if self.rank[x]==self.rank[y]:\n self.rank[y]+=1\n \n def Same(self,x,y):\n return self.find(x)==self.find(y)\n \n def size(self,x):\n return -self.root[self.find(x)]\nimport sys\ninput=sys.stdin.buffer.readline\nn,m,k=map(int,input().split())\nlink=UnionFind(n)\nf=[0]*n\nblock=[[] for _ in range(n)]\nfor _ in range(m):\n a,b=map(int,input().split())\n a-=1\n b-=1\n link.unite(a,b)\n f[a]+=1\n f[b]+=1\nfor _ in range(k):\n a,b=map(int,input().split())\n block[a-1].append(b-1)\n block[b-1].append(a-1)\nans=[]\nfor i in range(n):\n ret=link.size(i)-f[i]-1\n for j in block[i]:\n if link.Same(i,j):\n ret-=1\n ans.append(ret)\nprint(*ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s335092195', 's807800466', 's411546200'] | [75188.0, 1095704.0, 29420.0] | [2112.0, 2170.0, 1007.0] | [699, 649, 1231] |
p02762 | u584083761 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import deque\nn,m,k = list(map(int, input().split()))\nab = [list(map(int, input().split())) for _ in range(m)]\ncd = [list(map(int, input().split())) for _ in range(k)]\n\nf1 = [set() for _ in range(0, n+1)]\nb1 = [set() for _ in range(0, n+1)]\nfb1 = [set() for _ in range(0, n+1)]\nans = [0]*(n+1)\n\nfor x,y in ab:\n f1[x].add(y)\n f1[y].add(x)\n fb1[x].add(y)\n fb1[y].add(x)\n\nfor x,y in cd:\n b1[x].add(y)\n b1[y].add(x)\n fb1[x].add(y)\n fb1[y].add(x)\n\nstack = deque()\nvisited = [0]*(n+1)\nlinks = []\n\nfor i in range(1, n+1):\n if visited[i]: continue\n link = {i}\n visited[i] = 1\n stack.append(i)\n while stack:\n n1 = stack.pop()\n for j in f1[n1]:\n if visited[j] == 0:\n stack.append(j)\n visited[j] = 1\n link.add(j)\n links.append(link)\n\nfor i in v0:\n leni = len(i)\n for j in i:\n ans[j] = leni - len(i & fb1[j]) - 1\n\nprint(*ans[1:])', 'from collections import deque\nn,m,k = list(map(int, input().split()))\nab = [list(map(int, input().split())) for _ in range(m)]\ncd = [list(map(int, input().split())) for _ in range(k)]\n\nf1 = [set() for _ in range(0, n+1)]\nb1 = [set() for _ in range(0, n+1)]\nfb1 = [set() for _ in range(0, n+1)]\nans = [0]*(n+1)\n\nfor x,y in ab:\n f1[x].add(y)\n f1[y].add(x)\n fb1[x].add(y)\n fb1[y].add(x)\n\nfor x,y in cd:\n b1[x].add(y)\n b1[y].add(x)\n fb1[x].add(y)\n fb1[y].add(x)\n\nstack = deque()\nvisited = [0]*(n+1)\nlinks = []\n\nfor i in range(1, n+1):\n if visited[i]: continue\n link = {i}\n visited[i] = 1\n stack.append(i)\n while stack:\n n1 = stack.pop()\n for j in f1[n1]:\n if visited[j] == 0:\n stack.append(j)\n visited[j] = 1\n link.add(j)\n links.append(link)\n\nfor i in links:\n leni = len(i)\n for j in i:\n ans[j] = leni - len(i & fb1[j]) - 1\n\nprint(*ans[1:])'] | ['Runtime Error', 'Accepted'] | ['s672199047', 's243589710'] | [180884.0, 183172.0] | [1431.0, 1568.0] | [958, 961] |
p02762 | u595375942 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["N,M,K=map(int,input().split())\ngraph_data=[[0]*N for _ in range(N)]\nblock_data=[[0]*N for _ in range(N)]\n\nfor _ in range(M):\n i,j=map(int,input().split())\n graph_data[i-1][j-1]=graph_data[j-1][i-1]=1\nfor _ in range(K):\n i,j=map(int,input().split())\n block_data[i-1][j-1]=block_data[j-1][i-1]=1\n\nfrom collections import deque\n\ndef bfs(start, W):\n work_queue = deque([])\n visited = set()\n work_queue.append(start)\n visited.add(start)\n while work_queue:\n here = work_queue.popleft()\n for i, node in enumerate(W[here]):\n if node ==0: continue\n if i not in visited:\n work_queue.append(i)\n visited.add(i)\n\n return visited\n\nans=[0]*N\nfor i in range(N):\n for j in bfs(i,graph_data):\n if graph_data[i][j]==0:\n ans[i]+=1\n if block_data[i][j]==1:\n ans[i]-=1\npri=''\nfor i in range(N):\n pri+=str(ans[i])\n if i!=N-1:\n pri+=' '\nprint(pri)", 'N, M, K = map(int, input().split())\n\nclass UnionFind:\n def __init__(self, n):\n self.ps = [-1] * (n + 1)\n \n def find(self, x):\n if self.ps[x] < 0:\n return x\n else:\n self.ps[x] = self.find(self.ps[x])\n return self.ps[x]\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return False\n if self.ps[x] > self.ps[y]:\n x, y = y, x\n self.ps[x] += self.ps[y]\n self.ps[y] = x\n return True\n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n def size(self, x):\n x = self.find(x)\n return -self.ps[x]\n\nuf = UnionFind(N)\nfriends = [0]*(N+1)\nchain = [0]*(N+1)\n\n\nfor _ in range(M):\n A, B = map(int, input().split())\n friends[A] += 1\n friends[B] += 1\n uf.union(A, B)\n\nfor _ in range(K):\n C, D = map(int, input().split())\n if uf.same(C, D):\n friends[C] += 1\n friends[D] += 1\n\nans = []\n\nfor i in range(1, N+1):\n ans.append(uf.size(i) - friends[i] - 1)\n\nprint(*ans)'] | ['Wrong Answer', 'Accepted'] | ['s386887580', 's473374561'] | [1970548.0, 19400.0] | [2226.0, 665.0] | [971, 1078] |
p02762 | u595952233 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["n, m, k = map(int, input().split())\nab = [list(map(int, input().split())) for _ in range(m)]\ncd = [list(map(int, input().split())) for _ in range(k)]\n\nblock = [[] for i in range(n)]\nfriend = [[] for i in range(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\nuf = UnionFind(n)\nfor a, b in ab:\n uf.union(a-1, b-1)\n friend[a-1].append(b-1)\n friend[b-1].append(a-1)\n\nfor c, d in cd:\n block[c-1].append(d-1)\n block[d-1].append(c-1)\n\nfor i in range(n):\n ans = len(set(uf.members(i)) - (set(friend[i])|set(block[i])))-1\n print(ans)\n ", "import sys\ninput = sys.stdin.readline\nn, m, k = map(int, input().split())\n\nfriend = [0] * n\nblock = [0] * 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\nuf = UnionFind(n)\nab = [list(map(int, input().split())) for i in range(m)]\nfor a, b in ab:\n uf.union(a-1, b-1)\n friend[a-1]+=1\n friend[b-1]+=1\n\nfor i in range(k):\n c, d = map(int, input().split())\n if uf.same(d-1, c-1):\n block[c-1]+=1\n block[d-1]+=1\n\nans = []\nfor i in range(n):\n ans.append(uf.size(i) - friend[i] - block[i] -1 )\nprint(' '.join(list(map(str, ans))))"] | ['Time Limit Exceeded', 'Accepted'] | ['s676762212', 's999346680'] | [97820.0, 44404.0] | [2209.0, 555.0] | [1655, 1654] |
p02762 | u597455618 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\n\n\nclass UnionFind:\n def __init__(self, n):\n self.table = [-1] * n\n\n def _root(self, x):\n stack = []\n tbl = self.table\n while tbl[x] >= 0:\n stack.append(x)\n x = tbl[x]\n for y in stack:\n tbl[y] = x\n return x\n\n def find(self, x, y):\n return self._root(x) == self._root(y)\n\n def union(self, x, y):\n r1 = self._root(x)\n r2 = self._root(y)\n if r1 == r2:\n return\n d1 = self.table[r1]\n d2 = self.table[r2]\n if d1 <= d2:\n self.table[r2] = r1\n self.table[r1] += d2\n else:\n self.table[r1] = r2\n self.table[r2] += d1\n\n\ndef main():\n n, m, k = map(int, sys.stdin.buffer.readline().split())\n uf = UnionFind(n)\n fb = [0]*n\n i = 0\n for x in sys.stdin.buffer.readlines():\n print(uf.table)\n if i < m:\n a, b = map(int, x.split())\n fb[a-1] += 1\n fb[b-1] += 1\n uf.union(a-1, b-1)\n else:\n c, d = map(int, x.split())\n if uf._root(c-1) == uf._root(d-1):\n fb[c-1] += 1\n fb[d-1] += 1\n i += 1\n\n ans = [-uf.table[uf._root(i)]-1-fb[i] for i in range(n)]\n print(*ans)\n\n\nif __name__ == "__main__":\n main()\n', 'n, m, k = map(int, input().split())\ntable = [[0 for i in range(n+1)] for j in range(n+1)]\nfor i in range(m):\n a, b = map(int, input().split())\n table[min(a,b)][max(a,b)] = 1\nfor i in range(k):\n c, d = map(int, input().split())\n table[max(c,d)][min(c,d)] = -1\n\nans = [0 for i in range(n)]\n\nfor i in range(1, n+1):\n for j in range(i+1, n+1):\n check = 0\n if table[i][j] == 0 and table[j][i] != -1:\n for k in range(i, j-1):\n if table[k][k+1] != 1 or table[k+1][k] == -1:\n check = 1\n if check == 0:\n ans[i-1] += 1\n ans[j-1] += 1\nfor i in ans:\n print(i, end = " ")', 'import sys\n\n\nclass UnionFind:\n def __init__(self, n):\n self.table = [-1] * n\n\n def _root(self, x):\n stack = []\n tbl = self.table\n while tbl[x] >= 0:\n stack.append(x)\n x = tbl[x]\n for y in stack:\n tbl[y] = x\n return x\n\n def find(self, x, y):\n return self._root(x) == self._root(y)\n\n def union(self, x, y):\n r1 = self._root(x)\n r2 = self._root(y)\n if r1 == r2:\n return\n d1 = self.table[r1]\n d2 = self.table[r2]\n if d1 <= d2:\n self.table[r2] = r1\n self.table[r1] += d2\n else:\n self.table[r1] = r2\n self.table[r2] += d1\n\n\ndef main():\n n, m, k = map(int, sys.stdin.buffer.readline().split())\n uf = UnionFind(n)\n fb = [0]*n\n i = 0\n for x in sys.stdin.buffer.readlines():\n if i < m:\n a, b = map(int, x.split())\n fb[a-1] += 1\n fb[b-1] += 1\n uf.union(a-1, b-1)\n else:\n c, d = map(int, x.split())\n if uf._root(c-1) == uf._root(d-1):\n fb[c-1] += 1\n fb[d-1] += 1\n i += 1\n\n ans = [-uf.table[uf._root(i)]-1-fb[i] for i in range(n)]\n print(*ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s346741259', 's843034860', 's313423362'] | [151152.0, 497944.0, 24508.0] | [2155.0, 2134.0, 397.0] | [1331, 676, 1307] |
p02762 | u609061751 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\ninput = sys.stdin.readline\n \nn,m,k = map(int,input().split())\nab = [set() for _ in range(n)]\ncd = [[] * n for _ in range(n)]\nprint(cd)\n\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 _ in range(m):\n a, b = [int(x) for x in input().split()]\n unite(a - 1, b - 1)\n ab[a - 1].add(b - 1)\n ab[b - 1].add(a - 1)\n\nfor i in range(k):\n c, d = [int(x) for x in input().split()]\n if same(c - 1, d - 1):\n cd[c - 1].append(d - 1)\n cd[d - 1].append(c - 1)\n\nans = [0] * n\n\nfor i in range(n):\n ans[i] = size(i) - 1 - len(cd[i]) - len(ab[i])\n\nprint(*ans)\n\n\n', 'import sys\ninput = sys.stdin.readline\n \nn,m,k = map(int,input().split())\nab = [set() for _ in range(n)]\ncd = [[] * n for _ in range(n)]\n\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 _ in range(m):\n a, b = [int(x) for x in input().split()]\n unite(a - 1, b - 1)\n ab[a - 1].add(b - 1)\n ab[b - 1].add(a - 1)\n\nfor i in range(k):\n c, d = [int(x) for x in input().split()]\n if same(c - 1, d - 1):\n cd[c - 1].append(d - 1)\n cd[d - 1].append(c - 1)\n\nans = [0] * n\n\nfor i in range(n):\n ans[i] = size(i) - 1 - len(cd[i]) - len(ab[i])\n\nprint(*ans)\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s449628391', 's432311849'] | [64888.0, 64496.0] | [999.0, 976.0] | [1200, 1190] |
p02762 | u619144316 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["N, M = [int(i) for i in input().split(' ')]\nSC = []\nfor _ in range(M):\n SC.append([int(i) for i in input().split(' ')])\n\nch = [-1] * N\nfor s,c in SC:\n if N >1:\n if s == 1 and c == 0:\n print(-1)\n exit()\n\n if ch[s-1] == -1 or ch[s-1] == c:\n ch[s-1] = c\n else:\n print(-1)\n exit()\ns = 10**(N-1) if N >1 else 0\nf = 10 ** N if N >1 else 10\nfor n in range(s,f):\n n = list(str(n))\n flg = 0\n for s,c in SC:\n if not n[s-1] == str(c):\n flg = 1\n\n if flg == 0:\n print(''.join(n))\n exit()", 'from collections import defaultdict\nimport sys\nsys.setrecursionlimit(10**7)\ninput = sys.stdin.readline\nN, M, K = map(int, input().split())\n\ndef dfs(v):\n size = 1\n for w in fr[v]:\n if ~roots[w]: continue\n roots[w] = roots[v]\n size += dfs(w)\n return size\n\nfr = defaultdict(set)\nfor _ in range(M):\n a, b = [int(x) -1 for x in input().split()]\n fr[a].add(b)\n fr[b].add(a)\nbl = defaultdict(set)\nfor _ in range(K):\n a, b = [int(x) - 1 for x in input().split()]\n bl[a].add(b)\n bl[b].add(a)\n\nroots = [-1] * N\nsizes = [-1] * N\n\nfor v in range(N):\n if ~roots[v]: continue\n roots[v] = v\n sizes[v] = dfs(v)\n\nans = []\nfor v in range(N):\n w = roots[v]\n res = sizes[w] - len(fr[v]) - sum(1 for u in bl[v] if roots[u] == w) -1\n ans.append(res)\n\nprint(*ans)'] | ['Runtime Error', 'Accepted'] | ['s855799134', 's488140812'] | [3064.0, 98180.0] | [17.0, 1252.0] | [580, 806] |
p02762 | u624533266 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["from collections import defaultdict\nimport sys\nsys.setrecursionlimit(100000)\n\ndef root(uft, x):\n if uft[x] == x: return x\n uft[x] = root(uft, uft[x])\n return uft[x]\n\ndef union(uft, x, y):\n x = root(uft, x)\n y = root(uft, y)\n if x == y:\n return\n uft[x] = y\n\ndef answer():\n n, m, k = map(int, input().split())\n friend = defaultdict(set)\n block = defaultdict(set)\n group = defaultdict(set)\n uft = [i for i in range(n+1)]\n for i in range(m):\n a, b = map(int, input().split())\n union(uft, j, i)\n friend[a].add(b)\n friend[b].add(a)\n for j in range(k):\n c, d = map(int, input().split())\n block[c].add(d)\n block[d].add(c)\n for i in range(1, n+1):\n root(uft, i)\n for i in range(1, n+1):\n group[root(uft, i)].add(i)\n return ' '.join(str(len(group[uft[i]]-block[i])-len(friend[i])-1) for i in range(1, n+1))\n\nprint(answer())\n\n", 'from collections import defaultdict, Counter\nimport sys\n\ndef root(uft, x):\n if uft[x] == x: return x\n uft[x] = root(uft, uft[x])\n return uft[x]\n\ndef union(uft, rank, x, y):\n x = root(uft, x)\n y = root(uft, y)\n if x == y:\n return\n\n if rank[x] >= rank[y]:\n uft[y] = x\n if rank[x] == rank[y]:\n rank[x] += 1\n else:\n uft[x] = y\n\ndef same(uft, x, y):\n return root(uft, x) == root(uft, y)\n\ndef answer():\n n, m, k = map(int, input().split())\n friend = defaultdict(int)\n block = defaultdict(int)\n group = defaultdict(set)\n uft = [i for i in range(n+1)]\n rank = [0] * (n+1)\n for i in range(m):\n a, b = map(int, input().split())\n union(uft, rank, a, b)\n friend[a] += 1\n friend[b] += 1\n for j in range(k):\n c, d = map(int, input().split())\n if not same(uft, c, d):\n continue\n block[c] += 1\n block[d] += 1\n for i in range(1, n+1):\n root(uft, i)\n c = Counter(uft)\n return [c[uft[i]]-block[i]-friend[i]-1 for i in range(1, n+1)]\n\nprint(*answer())\n\n'] | ['Runtime Error', 'Accepted'] | ['s029726203', 's698909157'] | [75888.0, 34832.0] | [446.0, 1098.0] | [936, 1106] |
p02762 | u624696727 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\nfrom collections import deque\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\nprintV = lambda x: print(*x, sep="\\n")\nprintH = lambda x: print(" ".join(map(str,x)))\ndef IS(): return sys.stdin.readline()[:-1]\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LI1(): return list(map(int1, sys.stdin.readline().split()))\ndef LII(rows_number): return [II() for _ in range(rows_number)]\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef LLI1(rows_number): return [LI1() for _ in range(rows_number)]\n\ndef main():\n\tN,M,K = MI()\n\tfrend = [[] for _ in range(N)]\n\tblock = [[] for _ in range(N)]\n\tfor _ in range(M):\n\t\tA,B = map(int1, sys.stdin.readline().split())\n\t\tfrend[A].append(B)\n\t\tfrend[B].append(A)\n\tgroup = []\n\tque = deque()\n\tcnt = 0\n\tN_ch = [-1]*N\n\tg = -1\n\twhile cnt < N:\n\t\tque.append(N_ch.index(-1))\n\t\tg+=1\n\t\tN_ch[i]=g\n\t\tgroup.append(0)\n\t\twhile len(que)>0:\n\t\t\ti = que[-1]\n\t\t\tcnt += 1\n\t\t\tque.pop()\n\t\t\tgroup[g]+=1\n\t\t\tfr = frend[i]\n\t\t\tfor f in fr:\n\t\t\t\tif(N_ch[f]==-1):\n\t\t\t\t\tque.appendleft(f)\n\t\t\t\t\tN_ch[f]=g\n\n\tfor _ in range(K):\n\t\tC,D = map(int1, sys.stdin.readline().split())\n\t\tif(N_ch[C]==N_ch[D]):\n\t\t\tblock[C].append(D)\n\t\t\tblock[D].append(C)\n\n\tans_v = []\n\tfor i in range(N):\n\t\tans = group[N_ch[i]]-len(frend[i])-len(block[i])\n\t\tans_v.append(ans-1)\n\tprintH(ans_v)\n\nif __name__ == \'__main__\':\n\tmain()', 'import sys\nfrom collections import deque\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\nprintV = lambda x: print(*x, sep="\\n")\nprintH = lambda x: print(" ".join(map(str,x)))\ndef IS(): return sys.stdin.readline()[:-1]\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LI1(): return list(map(int1, sys.stdin.readline().split()))\ndef LII(rows_number): return [II() for _ in range(rows_number)]\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef LLI1(rows_number): return [LI1() for _ in range(rows_number)]\n\ndef main():\n\tN,M,K = MI()\n\tfrend = [[] for _ in range(N)]\n\tblock = [[] for _ in range(N)]\n\tfor _ in range(M):\n\t\tA,B = map(int1, sys.stdin.readline().split())\n\t\tfrend[A].append(B)\n\t\tfrend[B].append(A)\n\tgroup = []\n\tque = deque()\n\tcnt = 0\n\tN_ch = [-1]*N\n\tg = -1\n\twhile cnt < N:\n\t\tque.append(N_ch.index(-1))\n\t\tg+=1\n\t\tN_ch[i]=g\n\t\tgroup.append(0)\n\t\twhile len(que)>0:\n\t\t\ti = que[-1]\n\t\t\tcnt += 1\n\t\t\tque.pop()\n\t\t\tgroup[g]+=1\n\t\t\tfr = frend[i]\n\t\t\tfor f in fr:\n\t\t\t\tif(N_ch[f]==-1):\n\t\t\t\t\tque.appendleft(f)\n\t\t\t\t\tN_ch[f]=g\n\n\tfor _ in range(K):\n\t\tC,D = map(int1, sys.stdin.readline().split())\n\t\tif(N_ch[C]==N_ch[D]):\n\t\t\tblock[C].append(D)\n\t\t\tblock[D].append(C)\n\n\tans_v = []\n\tfor i in range(N):\n\t\tans = group[N_ch[i]]-len(frend[i])-len(block[i])\n\t\tans_v.append(ans-1)\n\tprintH(ans_v)\n\nif __name__ == \'__main__\':\n\tmain()', 'import sys\nfrom collections import deque\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\nprintV = lambda x: print(*x, sep="\\n")\nprintH = lambda x: print(" ".join(map(str,x)))\ndef IS(): return sys.stdin.readline()[:-1]\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LI1(): return list(map(int1, sys.stdin.readline().split()))\ndef LII(rows_number): return [II() for _ in range(rows_number)]\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef LLI1(rows_number): return [LI1() for _ in range(rows_number)]\n\nclass UnionFind():\n\tdef __init__(self, n):\n\t\tself.n=n\n\t\tself.parents = [-1]*n\n\tdef find(self, x):\n\t\tif self.parents[x] < 0:\n\t\t\treturn x\n\t\telse:\n\t\t\tself.parents[x] = self.find(self.parents[x])\n\t\t\treturn self.parents[x]\n\tdef union(self,x,y):\n\t\tx = self.find(x)\n\t\ty = self.find(y)\n\t\tif x==y:\n\t\t\treturn\n\t\tif self.parents[x] > self.parents[y]:\n\t\t\tx, y = y, x\n\t\tself.parents[x] += self.parents[y]\n\t\tself.parents[y] = x\n\tdef size(self, x):\n\t\treturn -self.parents[self.find(x)]\n\tdef same(self, x, y):\n\t\treturn self.find(x) == self.find(y)\n\ndef main():\n\tN,M,K = MI()\n\tfrend = [[] for _ in range(N)]\n\tblock = [[] for _ in range(N)]\n\tuf = UnionFind(N)\n\tfor _ in range(M):\n\t\tA,B = map(int1, sys.stdin.readline().split())\n\t\tuf.union(A,B)\n\t\tfrend[A].append(B)\n\t\tfrend[B].append(A)\n\n\tfor _ in range(K):\n\t\tC,D = map(int1, sys.stdin.readline().split())\n\t\tif uf.same(C,D):\n\t\t\tblock[C].append(D)\n\t\t\tblock[D].append(C)\n\n\tans_v = []\n\tfor i in range(N):\n\t\tans = uf.size(i)-len(frend[i])-len(block[i])-1\n\t\tans_v.append(ans)\n\tprintH(ans_v)\n\nmain()'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s889206476', 's935959153', 's588247805'] | [30184.0, 30148.0, 51728.0] | [290.0, 284.0, 896.0] | [1451, 1451, 1673] |
p02762 | u625963200 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n,m,k=map(int,input().split())\nAB=[list(map(int,input().split())) for _ in range(m)]\nCD=[list(map(int,input().split())) for _ in range(k)]\n\nfriends=[set() for _ in range(n)]\nblocks=[set() for _ in range(n)]\nfor a,b in AB:\n a,b=a-1,b-1\n friends[a].add(b)\n friends[b].add(a)\nfor c,d in CD:\n c,d=c-1,d-1\n blocks[c].add(d)\n blocks[d].add(c)\n\nprint(friends)\nprint(blocks)\nans=[0]*n\nfor i in range(n):\n koho=set()\n for f in friends[i]:\n for ff in friends[f]:\n print(i,f,ff,friends[i],blocks[i])\n if ff not in friends[i] and ff not in blocks[i] and ff!=i:\n koho.add(ff)\n print(koho)\n ans[i]=len(koho)\nprint(ans)', 'class UnionFind:\n def __init__(self,n):\n self.parent=[i for i in range(n)] \n self.rank=[0]*n \n self.count=0\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.root(self.parent[x])\n \n def is_same(self,x,y): \n return self.root(x)==self.root(y)\n \n def union(self,x,y): \n \n x=self.root(x)\n y=self.root(y)\n if x==y: return \n \n if self.rank[x]<self.rank[y]:\n self.parent[x]=y\n else:\n self.parent[y]=x\n if self.rank[x]==self.rank[y]: self.rank[x]+=1\n self.count+=1\n \nfrom collections import Counter\nn,m,k=map(int,input().split())\nAB=[list(map(int,input().split())) for _ in range(m)]\nCD=[list(map(int,input().split())) for _ in range(k)]\n\nblocks=[set() for _ in range(n)]\nfor c,d in CD:\n c,d=c-1,d-1\n blocks[c].add(d)\n blocks[d].add(c)\n\nfriends=[0]*n\nuf=UnionFind(n)\nfor a,b in AB:\n a,b=a-1,b-1\n friends[a]+=1\n friends[b]+=1\n if not uf.is_same(a,b): uf.union(a,b)\n \nctr=Counter()\nfor i in range(n):\n r=uf.root(i)\n ctr[r]+=1\n \nans=[]\nfor i in range(n):\n tmp=ctr[uf.root(i)]-friends[i]-1\n for b in blocks[i]:\n if uf.is_same(i,b): tmp-=1\n ans.append(tmp)\nprint(*ans)'] | ['Wrong Answer', 'Accepted'] | ['s813699070', 's877713373'] | [186100.0, 105088.0] | [2111.0, 1914.0] | [634, 1664] |
p02762 | u626468554 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n li[x] = 1\n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n union(a-1,b-1,li1)\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1))]\nfor i in range(N):\n m = root(i,li1)\n mm[m-1] += 1\n\n# print(li1)\n# print(mm)\nans = [mm[li1[i]-1]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'import sys\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n print(y)\n \n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n union(a-1,b-1,li1)\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1))]\nfor i in range(N):\n m = root(i,li1)\n mm[m-1] += 1\n\n# print(li1)\n# print(mm)\nans = [mm[li1[i]-1]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'import sys\nsys.setrecursionlimit(100000)\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n li[x]=y\n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n print(str(i)+" ",end="")\n union(min(a-1,b-1),max(a-1,b-1),li1)\n\n# c = CD[i][0]\n# d = CD[i][1]\n# union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1)+1)]\nfor i in range(N):\n m = root(i,li1)\n mm[m] += 1\n\nprint(li1)\nprint(mm)\nans = [mm[li1[i]]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'import sys\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n \n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n union(a-1,b-1,li1)\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1))]\nfor i in range(N):\n m = root(i,li1)\n mm[m-1] += 1\n\n# print(li1)\n# print(mm)\nans = [mm[li1[i]-1]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'import sys\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n li[x]=y\n\nli1 = [i+1 for i in range(N)]\nli2 = [i+1 for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n union(min(a-1,b-1),max(a-1,b-1),li1)\n\n# c = CD[i][0]\n# d = CD[i][1]\n# union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1))]\nfor i in range(N):\n m = root(i,li1)\n mm[m-1] += 1\n\n# print(li1)\n# print(mm)\nans = [mm[li1[i]-1]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'import sys\nsys.setrecursionlimit(10000)\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n li[x]=y\n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n union(min(a-1,b-1),max(a-1,b-1),li1)\n\n# c = CD[i][0]\n# d = CD[i][1]\n# union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1)+1)]\nfor i in range(N):\n m = root(i,li1)\n mm[m] += 1\n\nprint(li1,file=sys.stderr)\nprint(mm,file=sys.stderr)\nans = [mm[li1[i]-1]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'N,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n li[x] = y\n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n union(a-1,b-1,li1)\n\n# c = CD[i][0]\n# d = CD[i][1]\n# union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1))]\nfor i in range(N):\n m = root(i,li1)\n mm[m-1] += 1\n\n\nans = [mm[li1[i]-1]-1 for _ in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(ans)\n\n\n\n', 'import sys\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n li[x] = y\n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n union(a-1,b-1,li1)\n\n# c = CD[i][0]\n# d = CD[i][1]\n# union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1))]\nfor i in range(N):\n m = root(i,li1)\n mm[m-1] += 1\n\n# print(li1)\n# print(mm)\nans = [mm[li1[i]-1]-1 for i in range(N)]\n# print(ans)\nsys.exit()\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'import sys\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n li[x]=y\n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\n\n# a = AB[i][0]\n# b = AB[i][1]\n# union(a-1,b-1,li1)\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1))]\nfor i in range(N):\n m = root(i,li1)\n mm[m-1] += 1\n\n# print(li1)\n# print(mm)\nans = [mm[li1[i]-1]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'import sys\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n \n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n union(a-1,b-1,li1)\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1))]\nfor i in range(N):\n m = root(i,li1)\n mm[m-1] += 1\n\n# print(li1)\n# print(mm)\nans = [mm[li1[i]-1]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'import sys\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n li[x] = y\n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\nsys.exit()\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n union(a-1,b-1,li1)\n\n# c = CD[i][0]\n# d = CD[i][1]\n# union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1))]\nfor i in range(N):\n m = root(i,li1)\n mm[m-1] += 1\n\n# print(li1)\n# print(mm)\nans = [mm[li1[i]-1]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'import sys\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n li[x] = y\n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n union(a-1,b-1,li1)\n\n# c = CD[i][0]\n# d = CD[i][1]\n# union(c-1,d-1,li2)\nsys.exit()\nmm = [0 for i in range(max(li1))]\nfor i in range(N):\n m = root(i,li1)\n mm[m-1] += 1\n\n# print(li1)\n# print(mm)\nans = [mm[li1[i]-1]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n', 'import sys\nsys.setrecursionlimit(100000)\n\nN,M, K = map(int,input().split())\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\n\n\ndef root(x,li): \n if li[x] == x:\n return x\n else:\n li[x] = root(li[x],li)\n return li[x]\n\n\ndef find(x,y,li):\n return root(x,li) == root(y,li)\n\n\ndef union(x,y,li):\n x = root(x,li)\n y = root(y,li)\n if x==y:\n return\n else:\n li[x]=y\n\nli1 = [i for i in range(N)]\nli2 = [i for i in range(N)]\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n # print(str(i)+" ",end="")\n union(min(a-1,b-1),max(a-1,b-1),li1)\n\n# c = CD[i][0]\n# d = CD[i][1]\n# union(c-1,d-1,li2)\n\nmm = [0 for i in range(max(li1)+1)]\nfor i in range(N):\n m = root(i,li1)\n mm[m] += 1\n\n# print(li1)\n# print(mm)\nans = [mm[li1[i]]-1 for i in range(N)]\n# print(ans)\n\nfor i in range(M):\n a = AB[i][0]\n b = AB[i][1]\n ans[a-1] -= 1\n ans[b-1] -= 1\n\n\nfor i in range(K):\n c = CD[i][0]\n d = CD[i][1]\n if find(c-1,d-1,li1):\n ans[c-1] -= 1\n ans[d-1] -= 1\nprint(*ans)\n\n\n\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s067428531', 's174038850', 's199530598', 's339637309', 's351878324', 's443250057', 's499675228', 's632239300', 's752754441', 's759466274', 's770416571', 's918595095', 's506108288'] | [63788.0, 64972.0, 109488.0, 63672.0, 60636.0, 67612.0, 63424.0, 61396.0, 63676.0, 63796.0, 59816.0, 60100.0, 108752.0] | [1218.0, 1276.0, 1398.0, 1065.0, 757.0, 1183.0, 1188.0, 913.0, 1105.0, 1070.0, 667.0, 871.0, 1200.0] | [1146, 1154, 1223, 1123, 1174, 1227, 1117, 1164, 1152, 1095, 1164, 1164, 1229] |
p02762 | u626881915 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n,m,k = map(int, input().split())\n\ng = [[] for i in range(n+1)]\nf = [0]*(n+1)\nb = []\nfor i in range(m):\n u, v = map(int, input().split())\n g[u].append(v)\n g[v].append(u)\n f[u] += 1\n f[v] += 1\nfor i in range(k):\n b.append(map(int, input().split()))\n\ncount = 0\nrenketu_list = [-1]*(n+1)\nrenketu_size = [0]\nstack = []\nfor i in range(1, n+1):\n if renketu_list[i] == -1:\n count += 1\n renketu_list[i] = count\n renketu_size.append(1)\n while len(g[i]) > 0:\n stack.append(g[i].pop())\n while len(stack) > 0:\n u,v=stack.pop()\n if renketu_list[v] == -1:\n renketu_list[v] = count\n renketu_size[count] += 1\n while len(g[v])>0:\n stack.append(g[v].pop())\n\ns = [0] * (n+1)\nfor i in range(1, n):\n s[i] += renketu_size[renketu_list[i]] + f[i]\n \nfor i in range(k):\n u, v = b[i]\n if renketu_list[u] == renketu_list[v]:\n s[u] -= 1\n s[v] -= 1\n\nprint(" ".join(list(map(str, s))))\n ', 'n,m,k = map(int, input().split())\n\ng = [[] for i in range(n+1)]\nf = [0]*(n+1)\nb = []\nfor i in range(m):\n u, v = map(int, input().split())\n g[u].append(v)\n g[v].append(u)\n f[u] += 1\n f[v] += 1\nfor i in range(k):\n b.append(map(int, input().split()))\ncount = 0\nrenketu_list = [-1]*(n+1)\nrenketu_size = [0]\nstack = []\nfor i in range(1, n+1):\n if renketu_list[i] == -1:\n count += 1\n renketu_list[i] = count\n renketu_size.append(1)\n while len(g[i]) > 0:\n stack.append(g[i].pop())\n while len(stack) > 0:\n v=stack.pop()\n if renketu_list[v] == -1:\n renketu_list[v] = count\n renketu_size[count] += 1\n while len(g[v])>0:\n stack.append(g[v].pop())\n\ns = [0] * (n+1)\nfor i in range(1, n+1):\n s[i] += renketu_size[renketu_list[i]] - f[i] - 1\n \nfor i in range(k):\n u, v = b[i]\n if renketu_list[u] == renketu_list[v]:\n s[u] -= 1\n s[v] -= 1\n\nprint(" ".join(list(map(str, s[1:]))))\n \n'] | ['Runtime Error', 'Accepted'] | ['s889159876', 's314299347'] | [69320.0, 69892.0] | [914.0, 1247.0] | [935, 943] |
p02762 | u628262476 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n, m, k = map(int, input().split())\n\nf_adj_list = [[] for i in range(n)]\nb_adj_list = [[] for i in range(n)]\n\nfor i in range(m):\n _, __ = map(int, input().split())\n _ -= 1\n __ -= 1\n f_adj_list[_].append(__)\n f_adj_list[__].append(_)\n \nfor j in range(k):\n _, __ = map(int, input().split())\n _ -= 1\n __ -= 1\n b_adj_list[_].append(__)\n b_adj_list[__].append(_)\n \n \ngroup_id = [None for i in range(n)]\nfor i in range(n):\n \n newly_visited = [i]\n group_id[i] = i\n while len(newly_visited) > 0:\n now = newly_visited.pop()\n for j in f_adj_list[now]:\n if group_id[j] is not None: continue\n newly_visited.append(j)\n group_id[j] = i\n\n# group_id\n# print(group_id)\n\n\nfrom collections import Counter\ncnt = Counter(group_id)\n# cnt[5] = 7\n\nans_list = []\nfor i in range(n):\n ans = cnt[group_id[i]]\n ans -= 1 \n ans -= len(f_adj_list[i]) \n for j in b_adj_list[i]:\n if group_id[i] == group_id[j]:\n ans -= 1\n ans_list.append(ans)\n\nprint(" ".join(ans_list))\n', 'n, m, k = map(int, input().split())\n\nf_adj_list = [[] for i in range(n)]\nb_adj_list = [[] for i in range(n)]\n\nfor i in range(m):\n _, __ = map(int, input().split())\n _ -= 1\n __ -= 1\n f_adj_list[_].append(__)\n f_adj_list[__].append(_)\n \nfor j in range(k):\n _, __ = map(int, input().split())\n _ -= 1\n __ -= 1\n b_adj_list[_].append(__)\n b_adj_list[__].append(_)\n \n \ngroup_id = [None for i in range(n)]\nfor i in range(n):\n if group_id[i] is not None: continue\n \n newly_visited = [i]\n group_id[i] = i\n while len(newly_visited) > 0:\n now = newly_visited.pop()\n for j in f_adj_list[now]:\n if group_id[j] is not None: continue\n newly_visited.append(j)\n group_id[j] = i\n\n# group_id\n# print(group_id)\n\n\nfrom collections import Counter\ncnt = Counter(group_id)\n# cnt[5] = 7\n\nans_list = []\nfor i in range(n):\n ans = cnt[group_id[i]]\n ans -= 1 \n ans -= len(f_adj_list[i]) \n for j in b_adj_list[i]:\n if group_id[i] == group_id[j]:\n ans -= 1\n ans_list.append(ans)\n\nprint(" ".join(map(str, ans_list)))\n'] | ['Runtime Error', 'Accepted'] | ['s858301025', 's174007446'] | [54888.0, 57736.0] | [816.0, 768.0] | [1058, 1107] |
p02762 | u652583512 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | [" class union_find():\n def __init__(self, n):\n self.par = [i for i in range(n + 1)]\n self.rank = [1 for i in range(n + 1)]\n self.size = [1 for i in range(n + 1)]\n \n def find(self, c):\n if self.par[c] == c:\n return c\n \n ret = self.find(self.par[c])\n self.par[c] = ret\n return ret\n \n def union(self, x, y):\n \n xr = self.find(x)\n yr = self.find(y)\n if xr == yr:\n return\n \n if self.rank[yr] > self.rank[xr]:\n self.par[xr] = yr\n else:\n self.par[yr] = xr\n self.size[xr] += self.size[yr]\n if self.rank[xr] == self.rank[yr]:\n self.rank[xr] += 1\n \n def mass_size(self):\n return [i == v for i, v in enumerate(self.par)].count(True) - 1\n \n def size_belong(self, i):\n \treturn self.size[self.find(i)]\n \n def show(self):\n print('parent', self.par[1:])\n print('rank', self.rank[1:])\n \n def main():\n from collections import defaultdict\n \n dicf = defaultdict(lambda :[])\n dicb = defaultdict(lambda :[])\n \n N, M, K = map(int, input().split())\n \n uf = union_find(N)\n for i in range(M):\n a, b = map(int, input().split())\n dicf[a].append(b)\n dicf[b].append(a)\n if a > b:\n a, b = b, a\n uf.union(a, b)\n \n for i in range(K):\n c, d = map(int, input().split())\n dicb[c].append(d)\n dicb[d].append(c)\n \n ans = []\n for i in range(1, N + 1):\n x = uf.size_belong(i) - len(dicf[i]) - 1\n m = 0\n for b in dicb[i]:\n if uf.find(b) == uf.find(i):\n m += 1\n \n ans.append(x - m)\n \n \n print(' '.join(map(str, ans)))\n \n \n \n \n if __name__ == '__main__':\n main()", 'class union_find():\n __slots__ = ["par", "rank", "size"]\n def __init__(self, n):\n self.par = [i for i in range(n + 1)]\n self.rank = [1 for i in range(n + 1)]\n self.size = [1 for i in range(n + 1)]\n\n def find(self, c):\n if self.par[c] == c:\n return c\n\n ret = self.find(self.par[c])\n self.par[c] = ret\n return ret\n\n def union(self, x, y):\n\n xr = self.find(x)\n yr = self.find(y)\n if xr == yr:\n return\n\n if self.rank[yr] > self.rank[xr]:\n self.par[xr] = yr\n self.size[yr] += self.size[xr]\n else:\n self.par[yr] = xr\n self.size[xr] += self.size[yr]\n if self.rank[xr] == self.rank[yr]:\n self.rank[xr] += 1\n\n def size_belong(self, i):\n return self.size[self.find(i)]\n\n def mass_size(self):\n return [i == v for i, v in enumerate(self.par)].count(True) - 1\n\n def show(self):\n print(\'parent\', self.par[1:])\n print(\'rank\', self.rank[1:])\n\ndef main():\n from collections import defaultdict\n\n dicf = defaultdict(lambda :[])\n dicb = defaultdict(lambda :[])\n\n N, M, K = map(int, input().split())\n\n uf = union_find(N)\n for i in range(M):\n a, b = map(int, input().split())\n dicf[a].append(b)\n dicf[b].append(a)\n if a > b:\n a, b = b, a\n uf.union(a, b)\n\n for i in range(K):\n c, d = map(int, input().split())\n dicb[c].append(d)\n dicb[d].append(c)\n\n ans = []\n for i in range(1, N + 1):\n x = uf.size_belong(i) - len(dicf[i]) - 1\n m = 0\n for b in dicb[i]:\n if uf.find(b) == uf.find(i):\n m += 1\n\n ans.append(x - m)\n\n\n print(\' \'.join(map(str, ans)))\n\n\n\n\nif __name__ == \'__main__\':\n main()'] | ['Runtime Error', 'Accepted'] | ['s627305445', 's678974900'] | [2940.0, 65412.0] | [17.0, 1478.0] | [2094, 1840] |
p02762 | u657786757 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n,m,k = list(map(int,input().split()))\nans_l =[0 for _ in range(n)] \nfriend = [[] for _ in range(n)]\nfriend_line =[i for i in range(n)]\nfor _ in range(m):\n a,b= list(map(int,input().split()))\n if not a-1 in friend[b-1]:\n friend[a-1].append(b-1)\n friend[b-1].append(a-1)\n\nnum = 0\nwhile(num < n):\n #print(num)\n for x in friend[num]:\n friend_line[x]=friend_line[num]\n num+=1\n #print(frend_line)\n\nfor _ in range(k):\n a,b= list(map(int,input().split()))\n if not a-1 in friend[b-1]:\n friend[a-1].append(b-1)\n friend[b-1].append(a-1)\n\n#print(friend)\n#print(friend_line)\n\nfor i in range(n):\n print(friend_line.count(friend_line[i])-1-len(friend[i]),end=" ")', 'n,m,k = list(map(int,input().split()))\nans_l =[0 for _ in range(n)] \nfrend = [[] for _ in range(n)]\ngroup = [[] for _ in range(n)]\nfrend_line =[i for i in range(n)]\nfor _ in range(m):\n a,b= list(map(int,input().split()))\n frend[a-1].append(b-1)\n frend[b-1].append(a-1)\nfor _ in range(k):\n a,b= list(map(int,input().split()))\n group[a-1].append(b-1)\n group[b-1].append(a-1)\n#print(frend)\nnum = 0\nwhile(num < n):\n #print(num)\n for x in frend[num]:\n frend_line[x]=frend_line[num]\n num+=1\n #print(frend_line)\n\n#print(frend_line)\nfor i in range(n):\n for j in range(i+1,n):\n if not j in frend[i] and not j in group[i] and frend_line[i]==frend_line[j]:\n ans_l[i]+=1\n ans_l[j]+=1\n\nfor ans in ans_l:\n print(ans,end=" ")\nprint()', 'n,m,k = list(map(int,input().split()))\nans_l =[0 for _ in range(n)] \nfriend = [[] for _ in range(n)]\nfriend_line =[i for i in range(n)]\nfor _ in range(m):\n a,b= list(map(int,input().split()))\n if not a-1 in friend[b-1]:\n friend[a-1].append(b-1)\n friend[b-1].append(a-1)\n\nnum = 0\nwhile(num < n):\n #print(num)\n for x in friend[num]:\n friend_line[x]=friend_line[num]\n num+=1\n #print(frend_line)\n\nfor _ in range(k):\n a,b= list(map(int,input().split()))\n if not a-1 in friend[b-1]:\n friend[a-1].append(b-1)\n friend[b-1].append(a-1)\n\nprint(friend)\nprint(friend_line)\n\nfor i in range(n):\n print(friend_line.count(friend_line[i])-1-len(friend[i]),end=" ")', 'import sys\nimport math\nfrom collections import deque\nfrom collections import defaultdict\n\nclass UnionFind():\n def __init__(self, n):\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 if x == y:\n 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\n def size(self, x):\n \n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n \n return self.find(x) == self.find(y)\n\n def members(self, x):\n \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 \n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n \n return len(self.roots())\n\n def all_group_members(self):\n \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\ndef main():\n n, m, k = list(map(int,sys.stdin.readline().split()))\n uf = UnionFind(n)\n num_of_friends = [-1] * n\n\n for _ in range(m):\n a, b = list(map(int,sys.stdin.readline().split()))\n a -= 1\n b -= 1\n uf.union(a,b)\n num_of_friends[a] -= 1\n num_of_friends[b] -= 1\n #print(num_of_friends)\n \n """\n for i2 in range(n):\n roots[find(i2)] += 1\n print(roots)"""\n for i3 in range(n):\n num_of_friends[i3] += uf.size(i3)\n #print(num_of_friends)\n\n for _ in range(k):\n c, d = list(map(int,sys.stdin.readline().split()))\n c -= 1\n d -= 1\n """\n if find(c) == find(d):\n num_of_friends[c] -= 1\n num_of_friends[d] -= 1\n """\n if uf.same(c,d):\n num_of_friends[c] -= 1\n num_of_friends[d] -= 1 \n #print(num_of_friends)\n print(\' \'.join([str(number) for number in num_of_friends]))\n\nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s221095069', 's514831144', 's936595180', 's006860926'] | [34352.0, 53552.0, 43052.0, 18388.0] | [2106.0, 2107.0, 2106.0, 834.0] | [752, 831, 750, 2884] |
p02762 | u664373116 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\nsys.setrecursionlimit(10**5)\ntotal=0\ndef bfs(ind,num):\n kouho=friends[ind]\n \n for i in kouho:\n if sans[i]!=-1:\n continue\n num+=1\n sans[i]=sans[ind]\n l[sans[ind]].append(i)\n num+=bfs(i,0)\n return num\nn,m,k=list(map(int,input().split()))\nf=[list(map(int,input().split())) for _ in range(m)]\nfriends=[set() for _ in range(n)]\nfriends_num=list(map(lambda x:len(x),friends))\nbl=[list(map(int,input().split())) for _ in range(k)]\nl=[[i] for i in range(n)]\n\nfor each in f:\n a,b=each\n friends[a-1].add(b-1)\n friends[b-1].add(a-1)\n\nblock=[set() for _ in range(n)]\nfor each in bl:\n a,b=each\n block[a-1].add(b-1)\n block[b-1].add(a-1)\n\nsans=[-1 for _ in range(n)]\nsans[0]=0\ntotal=bfs(0,total)\nfor i in range(n):\n if sans[i]!=-1:\n continue\n sans[i]=i\n total=bfs(i,total)\nans=[0 for _ in range(n)]\n\n\n\nans=" ".join(map(str,ans))\n#print("total:",total)\nprint(ans)\n', 'import sys\nsys.setrecursionlimit(10**5)\ntotal=0\ndef bfs(ind,num):\n kouho=friends[ind]\n \n for i in kouho:\n if sans[i]!=-1:\n continue\n num+=1\n sans[i]=sans[ind]\n l[sans[ind]].append(i)\n num+=bfs(i,0)\n return num\nn,m,k=list(map(int,input().split()))\nf=[list(map(int,input().split())) for _ in range(m)]\nfriends=[set() for _ in range(n)]\nfriends_num=list(map(lambda x:len(x),friends))\nbl=[list(map(int,input().split())) for _ in range(k)]\nl=[[i] for i in range(n)]\n\nfor each in f:\n a,b=each\n friends[a-1].add(b-1)\n friends[b-1].add(a-1)\n\nblock=[set() for _ in range(n)]\nfor each in bl:\n a,b=each\n block[a-1].add(b-1)\n block[b-1].add(a-1)\n\nsans=[-1 for _ in range(n)]\nsans[0]=0\ntotal=bfs(0,total)\nfor i in range(n):\n if sans[i]!=-1:\n continue\n sans[i]=i\n total=bfs(i,total)\nans=[0 for _ in range(n)]\n\n\nfor i in range(n):\n l[i]=set(l[i])\n\n\n\nans=" ".join(map(str,ans))\n#print("total:",total)\nprint(ans)\n', 'import sys\nsys.setrecursionlimit(10**5)\ndef bfs(ind):\n kouho=friends[ind]\n for i in kouho:\n if sans[i]!=-1:\n continue\n sans[i]=sans[ind]\n l[sans[ind]].append(i)\n bfs(i)\nn,m,k=list(map(int,input().split()))\nf=[list(map(int,input().split())) for _ in range(m)]\nfriends=[set() for _ in range(n)]\nfriends_num=list(map(lambda x:len(x),friends))\nbl=[list(map(int,input().split())) for _ in range(k)]\nl=[[] for i in range(n)]\n\nfor each in f:\n a,b=each\n friends[a-1].add(b-1)\n friends[b-1].add(a-1)\n\nblock=[set() for _ in range(n)]\nfor each in bl:\n a,b=each\n block[a-1].add(b-1)\n block[b-1].add(a-1)\n\nsans=[-1 for _ in range(n)]\nsans[0]=0\nbfs(0)\nfor i in range(n):\n if sans[i]!=-1:\n continue\n sans[i]=i\n bfs(i)\nans=[0 for _ in range(n)]\nfor i in range(n):\n l[i]=set(l[i])\nfor i in range(n):\n tmp=l[i]-block[i]-friends[i]-{i}\n ans[i]=len(tmp)\n\n\nans=" ".join(map(str,ans))\nprint(ans)\n', 'import sys\nsys.setrecursionlimit(10**5)\ndef bfs(ind):\n kouho=friends[ind]\n for i in kouho:\n if sans[i]!=-1:\n continue\n sans[i]=sans[ind]\n l[sans[ind]].append(i)\n bfs(i)\nn,m,k=list(map(int,input().split()))\nf=[list(map(int,input().split())) for _ in range(m)]\nfriends=[set() for _ in range(n)]\nfriends_num=list(map(lambda x:len(x),friends))\nbl=[list(map(int,input().split())) for _ in range(k)]\nl=[[] for i in range(n)]\n\nfor each in f:\n a,b=each\n friends[a-1].add(b-1)\n friends[b-1].add(a-1)\n\nblock=[set() for _ in range(n)]\nfor each in bl:\n a,b=each\n block[a-1].add(b-1)\n block[b-1].add(a-1)\n\nsans=[-1 for _ in range(n)]\nsans[0]=0\nbfs(0)\nfor i in range(n):\n if sans[i]!=-1:\n continue\n sans[i]=i\n bfs(i)\nans=[0 for _ in range(n)]\n\nans=" ".join(map(str,ans))\nprint(ans)\n', 'def bfs(ind):\n kouho=friends[ind]\n for i in kouho:\n if sans[i]!=-1:\n continue\n sans[i]=sans[ind]\n l[sans[ind]].add(i)\n bfs(i)\nn,m,k=list(map(int,input().split()))\nf=[list(map(int,input().split())) for _ in range(m)]\nfriends=[set() for _ in range(n)]\nfriends_num=list(map(lambda x:len(x),friends))\nbl=[list(map(int,input().split())) for _ in range(k)]\nl=[{i} for i in range(n)]\n\nfor each in f:\n a,b=each\n friends[a-1].add(b-1)\n friends[b-1].add(a-1)\n\nblock=[set() for _ in range(n)]\nfor each in bl:\n a,b=each\n block[a-1].add(b-1)\n block[b-1].add(a-1)\n\nsans=[-1 for _ in range(n)]\nsans[0]=0\nbfs(0)\nfor i in range(n):\n if sans[i]!=-1:\n continue\n sans[i]=i\n bfs(i)\nans=[0 for _ in range(n)]\n\nans=" ".join(map(str,ans))\nprint(ans)\n', 'a=0\nfor i in range(10**13):\n a+=1\nprint(0)', 'import sys\nsys.setrecursionlimit(10**5)\ntotal=0\ndef bfs(ind,num):\n kouho=friends[ind]\n \n for i in kouho:\n if sans[i]!=-1:\n continue\n num+=1\n sans[i]=sans[ind]\n l[sans[ind]].add(i)\n num+=bfs(i,0)\n return num\nn,m,k=list(map(int,input().split()))\nf=[list(map(int,input().split())) for _ in range(m)]\nfriends=[set() for _ in range(n)]\nfriends_num=list(map(lambda x:len(x),friends))\nbl=[list(map(int,input().split())) for _ in range(k)]\nl=[{i} for i in range(n)]\n\nfor each in f:\n a,b=each\n friends[a-1].add(b-1)\n friends[b-1].add(a-1)\n\nblock=[set() for _ in range(n)]\nfor each in bl:\n a,b=each\n block[a-1].add(b-1)\n block[b-1].add(a-1)\n\nsans=[-1 for _ in range(n)]\nsans[0]=0\ntotal=bfs(0,total)\nfor i in range(n):\n if sans[i]!=-1:\n continue\n sans[i]=i\n total=bfs(i,total)\nans=[0 for _ in range(n)]\n\n\nfor i in range(n):\n l[i]=set(l[i])\n\n\nfor i in range(n):\n tmp=l[sans[i]]\n ans[i]+=len(tmp)-len(friends[i])-1\n for j in block[i]:\n if sans[i]==sans[j]:\n ans[j]-=1\n\nans=" ".join(map(str,ans))\n#print("total:",total)\nprint(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Time Limit Exceeded', 'Accepted'] | ['s089794178', 's203123749', 's558415953', 's661781867', 's756906874', 's899368738', 's928838783'] | [148324.0, 160100.0, 158428.0, 145124.0, 160060.0, 2940.0, 165776.0] | [1392.0, 1440.0, 1481.0, 1351.0, 1385.0, 2107.0, 1617.0] | [1083, 1083, 962, 939, 897, 43, 1139] |
p02762 | u677121387 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import deque,Counter\nimport sys\ninput = sys.stdin.readline\n\nn,m,k = map(int,input().split())\nfrd = [[] for _ in range(n)]\nblk = [[] for _ in range(n)]\nfor _ in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n frd[a].append(b)\n frd[b].append(a)\nfor _ in range(k):\n c,d = map(int,input().split())\n c -= 1\n d -= 1\n blk[c].append(d)\n blk[d].append(c)\n\nucnt = 0\nuni = [-1]*n\nstk = deque()\nfor i in range(n):\n if uni[i] != -1: continue\n stk.append((i,-1))\n while stk:\n cur,prev = stk.pop()\n uni[cur] = ucnt\n for nxt in frd[cur]:\n if nxt == prev: continue\n if uni[nxt] != -1: continue\n stk.append((nxt,cur))\n ucnt += 1\ncnt = Counter(uni)\n\nfor i in range(n):\n ans = cnt[uni[i]] - len(frd[i]) - 1\n for b in blk[i]:\n if uni[i] == uni[b]: ans -= 1\n print(ans,end=" ")', 'from collections import deque,Counter\n\nn,m,k = map(int,input().split())\nfrd = [[] for _ in range(n)]\nblk = [[] for _ in range(n)]\nfor _ in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n frd[a].append(b)\n frd[b].append(a)\nfor _ in range(k):\n c,d = map(int,input().split())\n c -= 1\n d -= 1\n blk[c].append(d)\n blk[d].append(c)\n\nucnt = 0\nuni = [-1]*n\nstk = deque()\nfor i in range(n):\n if uni[i] != -1: continue\n stk.append((i,-1))\n while stk:\n cur,prev = stk.pop()\n uni[cur] = ucnt\n for nxt in frd[cur]:\n if nxt == prev: continue\n if uni[nxt] != -1: continue\n stk.append((nxt,cur))\n ucnt += 1\ncnt = Counter(uni)\n\nfor i in range(n):\n ans = cnt[uni[i]] - len(frd[i]) - 1\n for b in blk[i]:\n if uni[i] == uni[b]: ans -= 1\n print(ans,end=" ")', 'from collections import deque,Counter\nimport sys\ninput = sys.stdin.readline\n\nn,m,k = map(int,input().split())\nans = [0]*(n+1)\nfrd = [[] for _ in range(n+1)]\n\nfor _ in range(m):\n a,b = map(int,input().split())\n frd[a].append(b)\n frd[b].append(a)\n ans[a] -= 1\n ans[b] -= 1\n\nucnt = 0\nuni = [-1]*(n+1)\nstk = deque()\nfor i in range(n):\n if uni[i] != -1: continue\n stk.append((i,0))\n while stk:\n cur,prev = stk.pop()\n uni[cur] = ucnt\n for nxt in frd[cur]:\n if uni[nxt] != -1 or nxt == prev: continue\n stk.append((nxt,cur))\n ucnt += 1\ncnt = Counter(uni)\n\nfor _ in range(k):\n c,d = map(int,input().split())\n if uni[c] == uni[d]:\n ans[c] -= 1\n ans[d] -= 1\n\nfor i in range(1,n+1): \n ans[i] += cnt[uni[i]] - 1\n print(ans[i],end=" ")', 'from collections import deque,Counter\n\nn,m,k = map(int,input().split())\nfrd = [[] for _ in range(n)]\nblk = [[] for _ in range(n)]\nfor _ in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n frd[a].append(b)\n frd[b].append(a)\nfor _ in range(k):\n c,d = map(int,input().split())\n c -= 1\n d -= 1\n blk[c].append(d)\n blk[d].append(c)\n\nucnt = 0\nuni = [-1]*n\nstk = deque()\nfor i in range(n):\n if uni[i] != -1: continue\n stk.append((i,-1))\n while stk:\n cur,prev = stk.pop()\n uni[cur] = ucnt\n for nxt in frd[cur]:\n if nxt == prev: continue\n if uni[nxt] != -1: continue\n stk.append((nxt,cur))\n ucnt += 1\ncnt = Counter(uni)\n\nfor i in range(n):\n ans = cnt[uni[i]] - 1\n for f in frd[i]:\n if uni[i] == uni[f]: ans -= 1\n for b in blk[i]:\n if uni[i] == uni[b]: ans -= 1\n print(ans,end=" ")', 'from collections import deque,Counter\nn,m,k = map(int,input().split())\nG = [[] for _ in range(n)]\n\nexc = [0]*n\nfor _ in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n G[a].append(b)\n G[b].append(a)\n exc[a] += 1\n exc[b] += 1\n\nstk = deque()\ngrp = [-1]*n\ngrpnum = 0\ndef dfs(s,g):\n stk.append(s)\n grp[s] = g\n while stk:\n cur = stk.pop()\n for nxt in G[cur]:\n if grp[nxt] != -1: continue\n grp[nxt] = g\n stk.append(nxt)\n\nfor i in range(n):\n if grp[i] != -1: continue\n dfs(i,grpnum)\n grpnum += 1\ncnt = Counter(grp)\n\nfor _ in range(k):\n c,d = map(int,input().split())\n c -= 1\n d -= 1\n if grp[c] == grp[d]:\n exc[c] += 1\n exc[d] += 1\n\nans = [cnt[grp[i]] - exc[i] - 1 for i in range(n)]\nprint(*ans) '] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s373731322', 's385537858', 's535732119', 's575236104', 's629076495'] | [47832.0, 47836.0, 30936.0, 47832.0, 33032.0] | [2106.0, 2106.0, 2105.0, 2106.0, 958.0] | [895, 857, 817, 902, 813] |
p02762 | u678167152 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["N, M, K = map(int, input().split())\nfriend = [[] for _ in range(N+1)]\nblock = [[] for _ in range(N+1)]\n\nfor i in range(M):\n A,B = map(int, input().split())\n friend[A].append(B)\n friend[B].append(A)\n\nfor i in range(K):\n C,D = map(int, input().split())\n block[C].append(D)\n block[D].append(C)\n#print(friend)\n#print(block)\n\nimport queue\ngrouping = [False]*(N+1)\n#print(grouping)\ngrouping[0] = True\ngroup = [0]*(N+1)\ng_num = 0\ng_cnt = []\nfor i in range(1,N+1):\n cnt = 0\n if grouping[i] == True:\n continue \n group[i] = g_num\n grouping[i] = True\n q = queue.Queue()\n q.put(i)\n while not q.empty():\n #print('v:',visited)\n p = q.get()\n for f in friend[p]:\n #print(p,f)\n if grouping[f]==False:\n q.put(f)\n group[f]=g_num\n grouping[f] =True\n cnt += 1\n g_num += 1\n g_cnt.append(cnt)\n #print('g:',grouping)\nans = []\nfor i in range(N+1):\n c = g_cnt[group[i]]-len(friend[i])\n for b in block[i]:\n if group[b]==group[i]:\n c -= 1\n ans.append(c)\nprint(*ans)", "N, M, K = map(int, input().split())\nfriend = [[] for _ in range(N+1)]\nblock = [[] for _ in range(N+1)]\n\nfor i in range(M):\n A,B = map(int, input().split())\n friend[A].append(B)\n friend[B].append(A)\n\nfor i in range(K):\n C,D = map(int, input().split())\n block[C].append(D)\n block[D].append(C)\n#print(friend)\n#print(block)\n\nimport queue\n\nfor i in range(1,N+1):\n c = 0\n visited = [False]*(N+1)\n visited[i]=True\n q = queue.Queue()\n for f in friend[i]:\n q.put(f)\n visited[f] = True\n frifri = []\n while not q.empty():\n p = q.get()\n for f in friend[p]:\n if visited[f]==False:\n q.put(f)\n frifri.append(f)\n visited[f] = True \n for g in frifri:\n if g not in block[i]:\n c += 1\n print(c,end=' ')", "N, M, K = map(int, input().split())\nfriend = [[] for _ in range(N+1)]\nblock = [[] for _ in range(N+1)]\n\nfor i in range(M):\n A,B = map(int, input().split())\n friend[A].append(B)\n friend[B].append(A)\n\nfor i in range(K):\n C,D = map(int, input().split())\n block[C].append(D)\n block[D].append(C)\n#print(friend)\n#print(block)\n\n\ngrouping = [False]*(N+1)\n#print(grouping)\ngrouping[0] = True\ngroup = [0]*(N+1)\ng_num = 0\ng_cnt = []\nfor i in range(1,N+1):\n cnt = 0\n if grouping[i] == True:\n continue \n group[i] = g_num\n grouping[i] = True\n \n #q.put(i)\n stack = [i]\n #while not q.empty():\n while len(stack)>0:\n #print('v:',visited)\n \n p = stack.pop()\n for f in friend[p]:\n #print(p,f)\n if grouping[f]==False:\n #q.put(f)\n stack.append(f)\n group[f]=g_num\n grouping[f] =True\n cnt += 1\n g_num += 1\n g_cnt.append(cnt)\n #print('g:',grouping)\nans = []\nfor i in range(1,N+1):\n c = g_cnt[group[i]]-len(friend[i])\n for b in block[i]:\n if group[b]==group[i]:\n c -= 1\n ans.append(c)\nprint(*ans)\n"] | ['Wrong Answer', 'Time Limit Exceeded', 'Accepted'] | ['s628329079', 's840543893', 's968062447'] | [48468.0, 43852.0, 49328.0] | [2109.0, 2106.0, 756.0] | [1014, 747, 1103] |
p02762 | u695079172 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['#import sys\n\n\nclass UF:\n \n def __init__(self,n):\n self.n = n\n self.parents = [-1] * (n+1) \n self.rnks = [0] * (n+1)\n\n def find(self,n):\n if self.parents[n] < 0:\n return n\n else:\n self.parents[n] = self.find(self.parents[n])\n return self.parents[n]\n\n def union(self,a,b):\n a_par = self.find(a)\n b_par = self.find(b)\n\n if a_par == b_par:\n return\n ##union by rank\n \n \n #if self.rnks[a_par] == self.rnks[b_par]:\n # self.rnks[a_par] += 1\n if self.size(a_par) < self.size(b_par): \n a_par,b_par = b_par,a_par\n self.parents[a_par] += self.parents[b_par]\n self.parents[b_par] = a_par\n\n def size(self,n):\n par = self.find(n)\n return abs(self.parents[par])\n\n def is_same(self,a,b):\n return self.find(a) == self.find(b)\n\n\n\ndef main():\n n,m,k = map(int,input().split())\n uf = UF(n)\n block_lst = [0 for _ in range(n+1)]\n friend_lst = [0 for _ in range(n+1)]\n \n for i in range(m):\n a,b = map(int,input().split())\n friend_lst[a] += 1\n friend_lst[b] += 1\n uf.union(a,b)\n #print(friend_lst)\n\n \n for i in range(k):\n c,d = map(int,input().split())\n if uf.is_same(c,d):\n block_lst[c] += 1\n block_lst[d] += 1\n #print(block_lst)\n \n answer = []\n\n for i in range(1,n+1):\n f_o_f = uf.length(i)\n answer.append(f_o_f - friend_lst[i] - block_lst[i] - 1)\n\n\n print(" ".join(map(str,answer)))\n\n\n\n\n\n\nif __name__ == \'__main__\':\n main()\n', '#import sys\n\n\nclass UF:\n \n def __init__(self,n):\n self.n = n\n self.parents = [-1] * (n+1) \n self.rnks = [0] * (n+1)\n\n def find(self,n):\n if self.parents[n] < 0:\n return n\n else:\n self.find(self.parents[n])\n\n\n def union(self,a,b):\n a_par = self.find(a)\n b_par = self.find(b)\n\n if a_par == b_par:\n return\n ##union by rank\n \n \n #if self.rnks[a_par] == self.rnks[b_par]:\n # self.rnks[a_par] += 1\n if self.size(a_par) < self.size(b_par): \n a_par,b_par = b_par,a_par\n self.parents[a_par] += self.parents[b_par]\n self.parents[b_par] = a_par\n\n def size(self,n):\n par = self.find(n)\n return abs(self.parents[par])\n\n def is_same(self,a,b):\n return self.find(a) == self.find(b)\n\n\n\ndef main():\n n,m,k = map(int,input().split())\n uf = UF(n)\n block_lst = [0 for _ in range(n+1)]\n friend_lst = [0 for _ in range(n+1)]\n \n for i in range(m):\n a,b = map(int,input().split())\n friend_lst[a] += 1\n friend_lst[b] += 1\n uf.union(a,b)\n #print(friend_lst)\n\n \n for i in range(k):\n c,d = map(int,input().split())\n if uf.is_same(c,d):\n block_lst[c] += 1\n block_lst[d] += 1\n #print(block_lst)\n \n answer = []\n\n for i in range(1,n+1):\n f_o_f = uf.size(i)\n answer.append(f_o_f - friend_lst[i] - block_lst[i] - 1)\n\n\n print(" ".join(map(str,answer)))\n\n\n\n\n\n\nif __name__ == \'__main__\':\n main()\n', '\nimport sys\nsys.setrecursionlimit(999999999999)\n\nclass UF:\n \n def __init__(self,n):\n self.n = n\n self.parents = [-1] * (n+1) \n self.rnks = [0] * (n+1)\n\n def find(self,n):\n if self.parents[n] < 0:\n return n\n else:\n self.parents[n] = self.find(self.parents[n])\n return self.parents[n]\n\n def union(self,a,b):\n a_par = self.find(a)\n b_par = self.find(b)\n\n if a_par == b_par:\n return\n if self.rnks[a_par] > self.rnks[b_par]:\n a_par,b_par = b_par,a_par\n if self.rnks[a_par] == self.rnks[b_par]:\n self.rnks[a_par] += 1\n self.parents[a_par] += self.parents[b_par]\n self.parents[b_par] = a_par\n\n def length(self,n):\n par = self.find(n)\n return abs(self.parents[par])\n\n def is_same(self,a,b):\n return self.find(a) == self.find(b)\n\n\n\ndef main():\n n,m,k = map(int,input().split())\n uf = UF(n)\n block_lst = [0 for _ in range(n+1)]\n friend_lst = [0 for _ in range(n+1)]\n \n for i in range(m):\n a,b = map(int,input().split())\n friend_lst[a] += 1\n friend_lst[b] += 1\n uf.union(a,b)\n #print(friend_lst)\n\n \n for i in range(k):\n c,d = map(int,input().split())\n if uf.is_same(c,d):\n block_lst[c] += 1\n block_lst[d] += 1\n #print(block_lst)\n \n answer = []\n\n for i in range(1,n+1):\n f_o_f = uf.length(i)\n answer.append(f_o_f - friend_lst[i] - block_lst[i] - 1)\n\n\n print(" ".join(map(str,answer)))\n\n\n\n\n\n\nif __name__ == \'__main__\':\n main()\n', '#import sys\n\n\nclass UF:\n \n def __init__(self,n):\n self.n = n\n self.parents = [-1] * (n+1) \n self.rnks = [0] * (n+1)\n\n def find(self,n):\n if self.parents[n] < 0:\n return n\n else:\n return self.find(self.parents[n])\n\n\n def union(self,a,b):\n a_par = self.find(a)\n b_par = self.find(b)\n\n if a_par == b_par:\n return\n #union by rank\n if self.rnks[a_par] < self.rnks[b_par]: \n a_par,b_par = b_par,a_par\n if self.rnks[a_par] == self.rnks[b_par]:\n self.rnks[a_par] += 1\n\n\n self.parents[a_par] += self.parents[b_par]\n self.parents[b_par] = a_par\n\n def size(self,n):\n par = self.find(n)\n return abs(self.parents[par])\n\n def is_same(self,a,b):\n return self.find(a) == self.find(b)\n\n\n\ndef main():\n n,m,k = map(int,input().split())\n uf = UF(n)\n block_lst = [0 for _ in range(n+1)]\n friend_lst = [0 for _ in range(n+1)]\n \n for i in range(m):\n a,b = map(int,input().split())\n friend_lst[a] += 1\n friend_lst[b] += 1\n uf.union(a,b)\n #print(friend_lst)\n\n \n for i in range(k):\n c,d = map(int,input().split())\n if uf.is_same(c,d):\n block_lst[c] += 1\n block_lst[d] += 1\n #print(block_lst)\n \n answer = []\n\n for i in range(1,n+1):\n f_o_f = uf.size(i)\n answer.append(f_o_f - friend_lst[i] - block_lst[i] - 1)\n\n\n print(" ".join(map(str,answer)))\n\n\n\n\n\n\nif __name__ == \'__main__\':\n main()\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s261864440', 's281234596', 's939079396', 's323959551'] | [9384.0, 10280.0, 3188.0, 20348.0] | [986.0, 889.0, 18.0, 1041.0] | [2246, 2192, 1861, 2198] |
p02762 | u697696097 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\nfrom io import StringIO\nimport unittest\n\nclass UnionFind():\n \n \n def __init__(self, n):\n self.n = n\n \n \n self.root = [-1]*(n+1)\n \n self.rnk = [0]*(n+1)\n\n \n def Find_Root(self, x):\n if(self.root[x] < 0):\n return x\n else:\n \n self.root[x] = self.Find_Root(self.root[x])\n return self.root[x]\n \n def Unite(self, x, y):\n \n x = self.Find_Root(x)\n y = self.Find_Root(y)\n \n if(x == y):\n return \n \n elif(self.rnk[x] > self.rnk[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.rnk[x] == self.rnk[y]):\n self.rnk[y] += 1\n \n def isSameGroup(self, x, y):\n return self.Find_Root(x) == self.Find_Root(y)\n\n \n def Count(self, x):\n return -self.root[self.Find_Root(x)]\n\ndef resolve():\n int1 = lambda x: int(x) - 1\n readline=sys.stdin.readline\n\n n,m,k=map(int, readline().strip().split())\n\n uf = UnionFind(n)\n\n exc=[0]*n\n\n for i in range(m):\n a,b=map(int1, readline().strip().split())\n uf.Unite(a,b)\n exc[a]+=1\n exc[b]+=1\n \n for i in range(k):\n a,b=map(int1, readline().strip().split())\n if uf.isSameGroup(a,b):\n exc[a]+=1\n exc[b]+=1\n \n rescnt=[]\n\n for i in range(n):\n ri=uf.Count(i)-1-exc[i]\n rescnt.append(str(ri))\n \n print(" ".join(rescnt))\n\n', 'import sys\nfrom io import StringIO\nimport unittest\n\nclass UnionFind():\n \n \n def __init__(self, n):\n self.n = n\n \n \n self.root = [-1]*(n+1)\n \n self.rnk = [0]*(n+1)\n\n \n def Find_Root(self, x):\n if(self.root[x] < 0):\n return x\n else:\n \n self.root[x] = self.Find_Root(self.root[x])\n return self.root[x]\n \n def Unite(self, x, y):\n \n x = self.Find_Root(x)\n y = self.Find_Root(y)\n \n if(x == y):\n return \n \n elif(self.rnk[x] > self.rnk[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.rnk[x] == self.rnk[y]):\n self.rnk[y] += 1\n \n def isSameGroup(self, x, y):\n return self.Find_Root(x) == self.Find_Root(y)\n\n \n def Count(self, x):\n return -self.root[self.Find_Root(x)]\n\ndef resolve():\n n,m,k=map(int, sys.stdin.readline().strip().split())\n #list(map(int,input().strip().split()))\n\n uf = UnionFind(n)\n\n res=[[] for i in range(n)]\n frd=[0 for i in range(n)]\n blk=[0 for i in range(n)]\n\n for i in range(m):\n #a,b=list(map(int,input().strip().split()))\n a,b=map(int, sys.stdin.readline().strip().split())\n a-=1\n b-=1\n uf.Unite(a,b)\n frd[a]+=1\n frd[b]+=1\n \n for i in range(k):\n #a,b=list(map(int,input().strip().split()))\n a,b=map(int, sys.stdin.readline().strip().split())\n a-=1\n b-=1\n if uf.isSameGroup(a,b):\n blk[a]+=1\n blk[b]+=1\n \n rescnt=[]\n\n for i in range(n):\n ri=uf.Count(i)-1-blk[i]-frd[i]\n rescnt.append(str(ri))\n \n \n print(" ".join(rescnt))\n\n', 'import sys\nfrom io import StringIO\nimport unittest\n\nclass UnionFind():\n \n \n def __init__(self, n):\n self.n = n\n \n \n self.root = [-1]*(n+1)\n \n self.rnk = [0]*(n+1)\n\n \n def Find_Root(self, x):\n if(self.root[x] < 0):\n return x\n else:\n \n self.root[x] = self.Find_Root(self.root[x])\n return self.root[x]\n \n def Unite(self, x, y):\n \n x = self.Find_Root(x)\n y = self.Find_Root(y)\n \n if(x == y):\n return \n \n elif(self.rnk[x] > self.rnk[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.rnk[x] == self.rnk[y]):\n self.rnk[y] += 1\n \n def isSameGroup(self, x, y):\n return self.Find_Root(x) == self.Find_Root(y)\n\n \n def Count(self, x):\n return -self.root[self.Find_Root(x)]\n\ndef resolve():\n int1 = lambda x: int(x) - 1\n readline=sys.stdin.readline\n\n n,m,k=map(int, readline().strip().split())\n\n uf = UnionFind(n)\n\n exc=[0]*n\n\n for i in range(m):\n a,b=map(int1, readline().strip().split())\n uf.Unite(a,b)\n exc[a]+=1\n exc[b]+=1\n \n for i in range(k):\n a,b=map(int1, readline().strip().split())\n if uf.isSameGroup(a,b):\n exc[a]+=1\n exc[b]+=1\n \n rescnt=[]\n\n for i in range(n):\n ri=uf.Count(i)-1-exc[i]\n rescnt.append(str(ri))\n \n print(" ".join(rescnt))\n\nresolve()'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s023060071', 's469241153', 's300573930'] | [5712.0, 5636.0, 17096.0] | [43.0, 42.0, 781.0] | [2415, 2717, 2414] |
p02762 | u700805562 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n, m, k = map(int, input().split())\nres = []\nfor _ in range(m):\n a, b = map(int, input().split())\n res.append(a)\n res.append(b)\nfor _ in range(k):\n c, d = map(int, input().split())\n res.append(c)\n res.append(d)\nans = [(n-1)]*n\nfor i in range(n):\n p = res.count(i+1)\n ans[i] -= p\nfor i in range(n):\n if ans[i] < 0:\n ans[i] = 0\nprint(ans)', '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: return False\n \n if par[x] > par[y]: 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, k = map(int, input().split())\nfriend = [[] for _ in range(n)]\nenemy = [[] for _ in range(n)]\npar = [-1]*n\n\n\nfor _ in range(m):\n a, b = map(int, input().split())\n unite(a-1, b-1)\n friend[a-1].append(b-1)\n friend[b-1].append(a-1)\nfor _ in range(k):\n a, b = map(int, input().split())\n enemy[a-1].append(b-1)\n enemy[b-1].append(a-1)\nans = []\nfor i in range(n):\n block = 0\n for j in enemy[i]:\n if same(i, j): block += 1\n ans.append(size(i)-len(friend[i])-block-1)\nprint(*ans)'] | ['Wrong Answer', 'Accepted'] | ['s691813607', 's396418584'] | [19736.0, 50040.0] | [2105.0, 1363.0] | [370, 986] |
p02762 | u727407185 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | [", m, k = [int(x) for x in input().split()]\nfr = [i for i in range(n)]\ndfr = [[] for i in range(n)]\nbl = [[] for i in range(n)]\ndef deref(a):\n s = []\n while True:\n next = fr[a]\n if next == a:\n break\n s.append(a)\n a = next\n for i in s:\n fr[i] = a\n return a\n\ndef merge(a, b):\n #print('merge(',a,b) \n ra, rb = deref(a), deref(b)\n fr[rb] = ra\n\nfor i in range(m):\n a, b = [int(x) - 1 for x in input().split()]\n dfr[a].append(b)\n dfr[b].append(a)\n a, b = min(a, b), max(a, b)\n merge(a, b)\nfor i in range(n):\n deref(i)\n#print(dfr) \n#print(fr) \nss = [[] for i in range(n)]\nfor i in range(n):\n ss[fr[i]].append(i)\nfor i in range(k):\n c, d = [int(x) - 1 for x in input().split()]\n bl[c].append(d)\n bl[d].append(c)\n for i in range(n):\n bl[i].sort()\nr = []\nfor i in range(n):\n v = len(ss[fr[i]]) - len(dfr[i]) - 1\n v -= sum(fr[j] == fr[i] for j in bl[i])\n r.append(v)\nprint(' '.join(str(x) for x in r))\n\n", "n, m, k = [int(x) for x in input().split()]\nfr = [i for i in range(n)]\ndfr = [[] for i in range(n)]\nbl = [[] for i in range(n)]\ndef deref(a):\n s = []\n while True:\n next = fr[a]\n if next == a:\n break\n s.append(a)\n a = next\n for i in s:\n fr[i] = a\n return a\ndef merge(a, b):\n ra, rb = deref(a), deref(b)\n fr[rb] = ra\nfor i in range(m):\n a, b = [int(x) - 1 for x in input().split()]\n dfr[a].append(b)\n dfr[b].append(a)\n a, b = min(a, b), max(a, b)\n merge(a, b)\nfor i in range(n):\n deref(i)\nss = [[] for i in range(n)]\nfor i in range(n):\n ss[fr[i]].append(i)\nfor i in range(k):\n c, d = [int(x) - 1 for x in input().split()]\n bl[c].append(d)\n bl[d].append(c)\nfor i in range(n):\n bl[i].sort()\nr = []\nfor i in range(n):\n v = len(ss[fr[i]]) - len(dfr[i]) - 1\n v -= sum(fr[j] == fr[i] for j in bl[i])\n r.append(v)\nprint(' '.join(str(x) for x in r))"] | ['Runtime Error', 'Accepted'] | ['s255407293', 's078804343'] | [3064.0, 62804.0] | [17.0, 1776.0] | [1219, 945] |
p02762 | u729133443 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['r=lambda x:p[x]>=0and r(p[x])or x\n(n,m,k),*t=[map(int,t.split())for t in open(0)]\np,f=[-1]*-~n,[-1]*-~n\nfor a,b in t[:m]:\n x,y=r(a),r(b)\n if x!=y:\n if x>y:x,y=y,x\n p[x]+=p[y]\n p[y]=x\n f[a]-=1,\n f[b]-=1,\na=[f[i]-p[r(i)]for i in range(n+1)]\nfor c,d in t[m:]:\n if r(c)==r(d):\n a[c]-=1\n a[d]-=1\nprint(*a[1:])', 'r=lambda x:p[x]>=0and r(p[x])or x\n(n,m,k),*t=[map(int,t.split())for t in open(0)]\np=[-1]*-~n\ns=[-1]*-~n\nfor a,b in t:\n x,y=sorted((r(a),r(b)))\n if(x!=y)*m>0:p[x]+=p[y];p[y]=x\n if m>0or x==y:s[a]-=1;s[b]-=1\n m-=1\nprint(*[s[i+1]-p[r(i+1)]for i in range(n)])', 'r=lambda x:p[x]>0and r(p[x])or x\n(n,m,k),*t=[map(int,t.split())for t in open(0)]\np=[-1]*-~n\ns=p[:]\nfor a,b in t:\n x,y=sorted((r(a),r(b)))\n if(x!=y)*m>0:p[x]+=p[y];p[y]=y=x\n if x==y:s[a]-=1;s[b]-=1;m-=1\nprint(*[s[i+1]-p[r(i+1)]for i in range(n)])'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s238627699', 's791679394', 's901112661'] | [97112.0, 3064.0, 96856.0] | [861.0, 18.0, 1525.0] | [324, 255, 245] |
p02762 | u729535891 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['a, b = [0] * m, [0] * m\nc, d = [0] * k, [0] * k\n\ndirect =[[] for _ in range(n)]\nuf = UnionFind(n)\n\nfor i in range(m):\n a[i], b[i] = map(int, input().split())\n a[i] -= 1\n b[i] -= 1\n direct[a[i]].append(b[i])\n direct[b[i]].append(a[i])\n uf.union(a[i], b[i])\n\nfor i in range(k):\n c[i], d[i] = map(int, input().split())\n c[i] -= 1\n d[i] -= 1\n if uf.same(c[i], d[i]):\n direct[c[i]].append(d[i])\n direct[d[i]].append(c[i])\n\nans = [0] * n\nfor i in range(n):\n ans[i] = uf.size(i) - len(direct[i]) - 1\n\nprint(*ans)', "class UnionFind():\n def __init__(self, n):\n self.n = n\n self.par = [-1] * n\n def find(self, x):\n if self.par[x] < 0:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.find(x) > self.find(y):\n x, y = y, x\n self.par[x] += self.par[y]\n self.par[y] = x\n def size(self, x):\n return -self.par[(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.par) 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\nn, m, k = map(int, input().split())\na, b = [0] * m, [0] * m\nc, d = [0] * k, [0] * k\n\ndirect =[[] for _ in range(n)]\nuf = UnionFind(n)\n\nfor i in range(m):\n a[i], b[i] = map(int, input().split())\n a[i] -= 1\n b[i] -= 1\n direct[a[i]].append(b[i])\n direct[b[i]].append(a[i])\n uf.union(a[i], b[i])\n\nfor i in range(k):\n c[i], d[i] = map(int, input().split())\n c[i] -= 1\n d[i] -= 1\n if uf.same(c[i], d[i]):\n direct[c[i]].append(d[i])\n direct[d[i]].append(c[i])\n\nans = [0] * n\nfor i in range(n):\n ans[i] = uf.size(i) - len(direct[i]) - 1\n\nprint(*ans)"] | ['Runtime Error', 'Accepted'] | ['s539857816', 's191796407'] | [3064.0, 39908.0] | [18.0, 1454.0] | [552, 1679] |
p02762 | u734442632 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\n\nline = sys.stdin.readline().strip()\nn,m,k = map(int, line.split())\nroots = list(range(n))\nlinked = [0]*n\nfor i in range(m):\n line = sys.stdin.readline().strip()\n a,b = map(int, line.split())\n c, d = min(a,b)-1, max(a,b) - 1\n linked[c] += 1 \n linked[d] += 1\n while c != roots[c]:\n c = roots[c]\n while d != roots[d]:\n d = roots[d]\n e,f = min(c,d), max(c,d)\n roots[f] = e\n\n\nfor i in range(n):\n cursor = i\n while cursor != roots[cursor]:\n cursor = roots[cursor]\n roots[i] = cursor\n\nprint(roots)\nres = [0]*n\nfor i in range(k):\n line = sys.stdin.readline().strip()\n a,b = map(int, line.split())\n c,d = a-1, b-1\n # same group blacklist\n if roots[c] == roots[d]:\n res[c] -= 1\n res[d] -= 1 \nset_sizes = dict()\n\nrs = list(set(roots))\nfor r in rs:\n count = 0\n for one in roots:\n if one == r:\n count += 1\n set_sizes[r] = count\n\nfor i in range(n):\n r = roots[i]\n res[i] += (set_sizes[r]-1-linked[i])\nprint (" ".join(map(str, res)))', 'import sys\n\nline = sys.stdin.readline().strip()\nn,m,k = map(int, line.split())\nroots = [-1]*n\nlinked = [0]*n\ndef find_root(x):\n if roots[x] < 0:\n return x\n else:\n roots[x] = find_root(roots[x])\n return roots[x]\ndef unite(x, y):\n x = find_root(x)\n y = find_root(y)\n if (x==y):\n return\n if roots[x] > roots[y]:\n c, d = y,x\n x,y = c,d\n roots[x] += roots[y]\n roots[y] = x\n\nfor i in range(m):\n line = sys.stdin.readline().strip()\n a,b = map(int, line.split())\n c, d = a-1,b-1\n linked[c] += 1 \n linked[d] += 1\n unite(c,d)\n#print(roots)\nblacks = [[]for i in range(n)]\nfor i in range(k):\n line = sys.stdin.readline().strip()\n a,b = map(int, line.split())\n c,d = a-1, b-1\n blacks[c].append(d)\n blacks[d].append(c)\nres = []\nfor i in range(n):\n r = -roots[find_root(i)] - 1 - linked[i]\n for one in blacks[i]:\n if find_root(one) == find_root(i):\n r -= 1\n res.append(r)\n \nprint (" ".join(map(str, res)))'] | ['Wrong Answer', 'Accepted'] | ['s430829231', 's474953414'] | [16088.0, 36436.0] | [2108.0, 1268.0] | [1049, 1019] |
p02762 | u736470924 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['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 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 if x == y:\n return\n if self.parents[x] > self.parents[y]:\n x, y = x, y\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\nfriends = [[] for _ in range(N)]\nblocks = [[] for _ in range(N)]\nroot = {}\n\nfor i in range(M):\n a, b = map(int, input().split())\n friends[a - 1].append(b - 1)\n friends[b - 1].append(a - 1)\n uf.unite(a, b)\n\nroots = uf.roots()\nfor r in roots:\n size = uf.size(r)\n root[r] = size - 1\n\nfor i in range(K):\n c, d = map(int, input().split())\n if uf.same(c - 1, d - 1):\n blocks[c - 1].append(d - 1)\n blocks[d - 1].append(c - 1)\n\nans = []\nfor i in range(N):\n ans.append(root[uf.find(i)] - len(blocks[i]) - len(friends[i]))\nprint(*ans)\n', 'N, M, K = map(int, input().split())\ntable = [[\'*\'] * N for i in range(N)]\nfor _ in range(M + K):\n a, b = map(int, input().split())\n table[a - 1][b - 1] = ""\n table[b - 1][a - 1] = ""\n\nfor i in range(N):\n for j in range(N):\n if i == j:\n table[i][j] = ""\n print("".join(table[i]).count(\'*\'), end=\' \')\n\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 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 if x == y:\n 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\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\nfriends = [[] for _ in range(N)]\nblocks = [[] for _ in range(N)]\nroot = {}\n\nfor i in range(M):\n a, b = map(int, input().split())\n friends[a - 1].append(b - 1)\n friends[b - 1].append(a - 1)\n uf.unite(a - 1, b - 1)\n\nfor i in range(K):\n c, d = map(int, input().split())\n if uf.same(c - 1, d - 1):\n blocks[c - 1].append(d - 1)\n blocks[d - 1].append(c - 1)\n\nans = []\nfor i in range(N):\n ans.append(uf.size(i) - 1 - len(blocks[i]) - len(friends[i]))\nprint(*ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s639831184', 's692794319', 's652122194'] | [39868.0, 1978612.0, 50052.0] | [1197.0, 2224.0, 1351.0] | [1361, 313, 1286] |
p02762 | u747602774 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\nsys.getrecursionlimit(10**6)\n\nN,M,K = map(int,input().split())\n\npar = [i for i in range(N+1)]\n\n\ndef root(x):\n if par[x] == x:\n return x\n else:\n par[x] = root(par[x])\n return par[x]\n\n\ndef bool_same(x,y):\n return root(x) == root(y)\n\n\ndef unite(x,y):\n x = root(x)\n y = root(y)\n if x != y:\n par[x] = y\n\nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n\nfor i in range(M):\n a,b = AB[i]\n unite(a,b)\n\nmember = [0 for i in range(N+1)]\n\nfor i in range(1,N+1):\n member[root(i)] += 1\n\nans = [member[par[i]]-1 for i in range(N+1)]\n\nfor i in range(M):\n a,b = AB[i]\n if bool_same(a,b):\n ans[a] -= 1\n ans[b] -= 1\n\nfor i in range(K):\n c,d = CD[i]\n if bool_same(c,d):\n ans[c] -= 1\n ans[d] -= 1\n\nprint(*ans[1:])\n', "import sys\nsys.setrecursionlimit(10**6)\n\nN,M,K = map(int,input().split())\n \npar = [i for i in range(N+1)]\n \n\ndef root(x):\n if par[x] == x:\n return x\n else:\n par[x] = root(par[x])\n return par[x]\n \n\ndef bool_same(x,y):\n return root(x) == root(y)\n \n\ndef unite(x,y):\n x = root(x)\n y = root(y)\n if x != y:\n par[x] = y\n \nAB = [list(map(int,input().split())) for i in range(M)]\nCD = [list(map(int,input().split())) for i in range(K)]\n \nfor a,b in AB:\n unite(a,b)\n \nfor i in range(N+1):\n root(i)\n \nmember = [0 for i in range(N+1)]\n \nfor p in par:\n member[p] += 1\n \nans = [member[par[i]]-1 for i in range(N+1)]\n \nfor a,b in AB:\n if bool_same(a,b):\n ans[a] -= 1\n ans[b] -= 1\nfor c,d in CD:\n if bool_same(c,d):\n ans[c] -= 1\n ans[d] -= 1\nprint(' '.join(map(str,ans[1:])))\n "] | ['Runtime Error', 'Accepted'] | ['s677169230', 's348599345'] | [3064.0, 83148.0] | [18.0, 1172.0] | [963, 950] |
p02762 | u747703115 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\nsys.setrecursionlimit(10**6)\nfrom collections import Counter\n\ndef dfs(nw):\n for nx in B[nw]:\n if V[nx]==-1:\n V[nx] = cnt\n dfs(nx)\n\nF = [[] for _ in range(n)]\nB = [[] for _ in range(n)]\nn, m, k = list(map(int, sys.stdin.readaline().split()))\nfor i in range(m):\n a,b = map(lambda x: int(x)-1, map(int, sys.stdin.readline().split()))\n F[a].append(b)\n F[b].append(a)\nfor i in range(k):\n c,d = map(lambda x: int(x)-1, map(int, sys.stdin.readline().split()))\n F[c].append(d)\n F[d].append(c)\n\nV = [-1]*n\ncnt = 1\nfor i in range(n):\n if V[i]==-1:\n V[i] = cnt\n dfs(i)\n cnt += 1\ncV = Counter(V)\nans = []\nfor i in range(n):\n ans.append(cV[V[i]]-1 - len(F[i]) - sum([V[b]==V[i] for b in B[i]]))\n\nprint(*ans)', 'import sys\nsys.setrecursionlimit(10**6)\nfrom collections import Counter\n\ndef dfs(nw):\n for nx in F[nw]:\n if V[nx]==-1:\n V[nx] = cnt\n dfs(nx)\n\nn, m, k = list(map(int, sys.stdin.readline().split()))\nF = [[] for _ in range(n)]\nB = [[] for _ in range(n)]\nfor i in range(m):\n a,b = map(lambda x: int(x)-1, map(int, sys.stdin.readline().split()))\n F[a].append(b)\n F[b].append(a)\nfor i in range(k):\n c,d = map(lambda x: int(x)-1, map(int, sys.stdin.readline().split()))\n B[c].append(d)\n B[d].append(c)\n\nV = [-1]*n\ncnt = 1\nfor i in range(n):\n if V[i]==-1:\n V[i] = cnt\n dfs(i)\n cnt += 1\ncV = Counter(V)\nans = []\nfor i in range(n):\n ans.append(cV[V[i]]-1 - len(F[i]) - sum([V[b]==V[i] for b in B[i]]))\n\nprint(*ans)'] | ['Runtime Error', 'Accepted'] | ['s830339319', 's053660338'] | [9348.0, 64744.0] | [29.0, 649.0] | [782, 781] |
p02762 | u755989869 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['\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 if x == y:\n return\n\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\n def issame(self, x, y):\n return self.find(x) == self.find(y)\n\n def count(self,x):\n return -self.parents[self.find(x)]\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 __str__(self):\n return \'\\n\'.join(\'{}: {}\'.format(root, self.members(root)) for root in self.roots())\n\nn,m,k = map(int, input().split(" "))\n\nuf_friend = UnionFind(n+1)\nuf_block = UnionFind(n+1)\ncount = [0]*(n+1)\nfor i in range(m):\n a,b = map(int, input().split(" "))\n uf_friend.union(a, b)\n count[a] += 1\n count[b] += 1\n\nfor i in range(k):\n a,b = map(int, input().split(" "))\n if(uf_friend.issame(a,b)):\n count[a] += 1\n count[b] += 1\n\nresult = [0]*n\nfor i in range(1,n+1):\n result[i-1] = uf_friend.count(i) - count[i] - 1\n\nprint(result)', '\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 if x == y:\n return\n\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\n def issame(self, x, y):\n return self.find(x) == self.find(y)\n\n def count(self,x):\n return -self.parents[self.find(x)]\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 __str__(self):\n return \'\\n\'.join(\'{}: {}\'.format(root, self.members(root)) for root in self.roots())\n\nn,m,k = map(int, input().split(" "))\n\nuf_friend = UnionFind(n+1)\nuf_block = UnionFind(n+1)\ncount = [0]*(n+1)\nfor i in range(m):\n a,b = map(int, input().split(" "))\n uf_friend.union(a, b)\n count[a] += 1\n count[b] += 1\n\nfor i in range(k):\n a,b = map(int, input().split(" "))\n if(uf_friend.issame(a,b)):\n count[a] += 1\n count[b] += 1\n\nresult = [0]*n\nfor i in range(1,n+1):\n result[i-1] = uf_friend.count(i) - count[i] - 1\n\nprint(*result)'] | ['Wrong Answer', 'Accepted'] | ['s426215330', 's917744921'] | [14600.0, 14900.0] | [1069.0, 1089.0] | [1476, 1477] |
p02762 | u762420987 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['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\n\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\nnot_friend_candidates = [1]*N\nfor _ in range(M):\n A, B = map(int, input().split())\n uf.union(A-1, B-1)\n not_friend_candidates[A-1] += 1\n not_friend_candidates[B-1] += 1\nfor _ in range(K):\n C, D = map(int, input().split())\n not_friend_candidates[C-1] += 1\n not_friend_candidates[D-1] += 1\nfor hito in range(N):\n print(uf.size(hito) - not_friend_candidates[hito], end=" ")\nprint()', 'import numpy as np\nfrom scipy.sparse.csgraph import shortest_path\nfrom scipy.sparse import csr_matrix\ninf = 10**6\n\n\nN, M, K = map(int, input().split())\ngraph = np.zeros((N, N), np.int32)\nfor _ in range(M):\n A, B = map(int, input().split())\n graph[A-1][B-1] = 1\n graph[B-1][A-1] = 1\nfor _ in range(K):\n C, D = map(int, input().split())\n graph[C-1][D-1] = inf\n graph[D-1][C-1] = inf\n\n\ncsgraph = csr_matrix(graph)\nshortest_paths = shortest_path(csgraph, directed=False, method="BF")\n\n\nok = sorted(list(zip(*np.where(graph < inf))))\nnow = 0\nans = 0\nfor x, y in ok:\n if x == now:\n if shortest_paths[x][y] > 1:\n ans += 1\n else:\n print(ans, end=" ")\n ans = 0\n now += 1\n while now < x:\n if now != N - 1:\n print(0, end=" ")\n else:\n print(0, end="")\n now += 1\n if shortest_paths[x][y] != 1:\n ans += 1\n\nwhile now <= N-1:\n if ans != 0:\n print(ans , end=" ")\n continue\n if now != N-1:\n print(0, end=" ")\n else:\n print(0, end="")\n now += 1\nprint()\n\n', 'import sys\ninput = sys.stdin.readline\n\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n self.group_count = 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 self.group_count -= 1\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 all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\ndef int_(num_str):\n return int(num_str) - 1\n\n\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\nsome = [1] * N\nfor i in range(M):\n a, b = map(int_, input().split())\n uf.union(a, b)\n some[a] += 1\n some[b] += 1\nfor i in range(K):\n c, d = map(int_, input().split())\n if uf.same(c, d):\n some[c] += 1\n some[d] += 1\n\n\nans = [uf.size(i) - some[i] for i in range(N)]\nprint(*ans)\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s270498253', 's273346785', 's261138227'] | [8604.0, 19676.0, 14192.0] | [1053.0, 2109.0, 788.0] | [1604, 1126, 1488] |
p02762 | u762540523 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import defaultdict\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_ε
₯εδΎ_1(self):\n input = """4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1"""\n output = """0 1 0 1"""\n self.assertIO(input, output)\n\n def test_ε
₯εδΎ_2(self):\n input = """5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5"""\n output = """0 0 0 0 0"""\n self.assertIO(input, output)\n\n def test_ε
₯εδΎ_3(self):\n input = """10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1"""\n output = """1 3 5 4 3 3 3 3 1 0"""\n self.assertIO(input, output)\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\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\ndef resolve():\n n, m, k = map(int, input().split())\n u = UnionFind(n)\n d = [0] * n\n e = [0] * n\n for _ in range(m):\n a, b = map(int, input().split())\n u.union(a - 1, b - 1)\n d[a - 1] += 1\n d[b - 1] += 1\n for _ in range(k):\n a, b = map(int, input().split())\n if u.same(a, b):\n e[a - 1] += 1\n e[b - 1] += 1\n ans = [0] * n\n for i in range(n):\n ans[i] = u.size(i) - 1 - d[i] - e[i]\n print(*ans)\n\n\nif __name__ == "__main__":\n unittest.main()\n', "from collections import defaultdict\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 d = {}\n for i in range(self.n):\n p = self.find(i)\n if p in d:\n d[p].append(i)\n else:\n d[p] = [i]\n return d\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(k, v) for k, v in self.all_group_members().items())\n\n\ndef resolve():\n n, m, k = map(int, input().split())\n u = UnionFind(n)\n d = defaultdict(int)\n e = defaultdict(int)\n for _ in range(m):\n a, b = [int(x) - 1 for x in input().split()]\n u.union(a, b)\n d[a] += 1\n d[b] += 1\n for _ in range(k):\n a, b = [int(x) - 1 for x in input().split()]\n if u.same(a, b):\n e[a] += 1\n e[b] += 1\n ans = [0] * n\n for i, v in u.all_group_members().items():\n x = len(v) - 1\n for j in v:\n ans[j] = x-d[j] - e[j]\n print(*ans)\n\n\nif __name__ == '__main__':\n resolve()\n"] | ['Runtime Error', 'Accepted'] | ['s793348210', 's653014741'] | [5820.0, 44192.0] | [49.0, 1235.0] | [3785, 1936] |
p02762 | u780475861 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['\n\nimport sys\nreadline = sys.stdin.readine\n\nN, M, K = map(int, readline().split())\n\nF = [[] for _ in range(N + 1)]\nfor _ in range(M):\n a, b = map(int, readline().split())\n F[a].append(b)\n F[b].append(a)\n\nB = [[] for _ in range(N + 1)]\nfor _ in range(K):\n c, d = map(int, readline().split())\n B[c].append(d)\n B[d].append(c)\n\nseen = [-1] * (N + 1)\ngroup = 0\n\n\ndef dfs(graph, s):\n stack = [s]\n seen[s] = group\n n_connection = 1\n\n while stack:\n u = stack.pop()\n for v in graph[u]:\n if seen[v] == -1:\n n_connection += 1\n seen[v] = group\n stack.append(v)\n\n return n_connection\n\n\nunion = {}\nfor i in range(1, N + 1):\n if seen[i] == -1:\n n = dfs(F, i)\n union[group] = n\n group += 1\n\nans = []\nfor i in range(1, N + 1):\n tmp = 0\n tmp += union[seen[i]] - 1\n tmp -= len(F[i])\n for j in B[i]:\n if seen[j] == seen[i]:\n tmp -= 1\n ans.append(tmp)\n\nprint(" ".join(map(str, ans)))\n', '\n\nimport sys\nreadline = sys.stdin.readline\n\nN, M, K = map(int, readline().split())\n\nF = [[] for _ in range(N + 1)]\nfor _ in range(M):\n a, b = map(int, readline().split())\n F[a].append(b)\n F[b].append(a)\n\nB = [[] for _ in range(N + 1)]\nfor _ in range(K):\n c, d = map(int, readline().split())\n B[c].append(d)\n B[d].append(c)\n\nseen = [-1] * (N + 1)\ngroup = 0\n\n\ndef dfs(graph, s):\n stack = [s]\n seen[s] = group\n n_connection = 1\n\n while stack:\n u = stack.pop()\n for v in graph[u]:\n if seen[v] == -1:\n n_connection += 1\n seen[v] = group\n stack.append(v)\n\n return n_connection\n\n\nunion = {}\nfor i in range(1, N + 1):\n if seen[i] == -1:\n n = dfs(F, i)\n union[group] = n\n group += 1\n\nans = []\nfor i in range(1, N + 1):\n tmp = 0\n tmp += union[seen[i]] - 1\n tmp -= len(F[i])\n for j in B[i]:\n if seen[j] == seen[i]:\n tmp -= 1\n ans.append(tmp)\n\nprint(" ".join(map(str, ans)))\n'] | ['Runtime Error', 'Accepted'] | ['s918712039', 's514455504'] | [3064.0, 51732.0] | [18.0, 679.0] | [1079, 1080] |
p02762 | u788068140 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import deque\n\n\nN,M,K = map(int,input().split())\n\nARR = []\nBRR = []\nfor i in range(M):\n ARR.append(list(map(int,input().split())))\n\nfor i in range(K):\n BRR.append(list(map(int,input().split())))\n\n#\n# N = 10\n# M = 9\n# K = 3\n# ARR = [\n# [10, 1],\n# [6, 7],\n# [8, 2],\n# [2, 5],\n# [8, 4],\n# [7, 3],\n# [10, 9],\n# [6, 4],\n# [5, 8],\n# [2, 6],\n# ]\n#\n# BRR = [\n# [7, 5],\n# [3, 1],\n# ]\n\ndef prepare(n, arr):\n nodes = [[] for i in range(n)]\n nodeStates = [False for i in range(n)]\n nodeLabels = [0 for i in range(n)]\n for ar in arr:\n fromNode = ar[0] - 1\n toNode = ar[1] - 1\n nodes[fromNode].append(toNode)\n nodes[toNode].append(fromNode)\n\n return nodes, nodeStates, nodeLabels\n\ndef prepare2(n,brr):\n nodes = [set() for i in range(n)]\n for ar in brr:\n fromNode = ar[0] - 1\n toNode = ar[1] - 1\n nodes[fromNode].add(toNode)\n\n return nodes\n\n\ndef calculate(n, m, k, nodes, nodeStates, nodeLabels,blockNodes):\n q = deque()\n\n label = 0\n labelDict = []\n while nodeStates.count(False) > 0:\n\n falseIndex = nodeStates.index(False)\n\n q.append(falseIndex)\n mmm = set()\n while len(q) > 0:\n node = q.popleft()\n if nodeStates[node] == True:\n continue\n nodeStates[node] = True\n nodeLabels[node] = label\n childNodes = nodes[node]\n mmm.add(node)\n for childNode in childNodes:\n if nodeStates[childNode] == False:\n q.append(childNode)\n\n labelDict.append(mmm)\n label = label + 1\n\n result = []\n for i in range(n):\n l = nodeLabels[i]\n\n p = labelDict[l]\n pp = blockNodes[i]\n s = p & pp\n result.append(str(len(labelDict[l]) - len(nodes[i]) - 1 - len(s)))\n\n print(" ".join(result))\n\n\nnodes, nodeStates, nodeLabels = prepare(N, ARR)\nblockNodes = prepare2(N,BRR)\ncalculate(N, M, K, nodes, nodeStates, nodeLabels,blockNodes)\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\n\n# N = 10\n# M = 9\n# K = 3\n# ARR = [\n# [10, 1],\n# [6, 7],\n# [8, 2],\n# [2, 5],\n# [8, 4],\n# [7, 3],\n# [10, 9],\n# [6, 4],\n# [5, 8],\n# ]\n#\n# BRR = [\n# [2, 6],\n# [7, 5],\n# [3, 1],\n# ]\n#\n\n\n\nN,M,K = list(map(int,input().split()))\n\nARR = []\n\nfor i in range(M):\n ARR.append(list(map(int,input().split())))\n\nBRR = []\nfor i in range(K):\n BRR.append(list(map(int,input().split())))\n\nunionFind = UnionFind(N)\n\nfl = [[] for i in range(N)]\nbl = [[] for i in range(N)]\nfor ar in ARR:\n fromNode = ar[0] - 1\n toNode = ar[1] - 1\n unionFind.union(fromNode, toNode)\n fl[fromNode].append(toNode)\n fl[toNode].append(fromNode)\n\nfor br in BRR:\n fromNode = br[0] - 1\n toNode = br[1] - 1\n bl[fromNode].append(toNode)\n bl[toNode].append(fromNode)\n\nresult = []\nfor i in range(N):\n size = unionFind.size(i) - 1\n\n\n for f in fl[i]:\n if unionFind.same(i,f):\n size = size - 1\n for b in bl[i]:\n if unionFind.same(i,b):\n size = size - 1\n\n result.append(str(size))\n\nprint(" ".join(result))\n'] | ['Wrong Answer', 'Accepted'] | ['s900009683', 's666363406'] | [106568.0, 90688.0] | [2114.0, 1975.0] | [2051, 2286] |
p02762 | u788703383 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\nsys.setrecursionlimit(10*9)\n\nn,m,k = map(int,input().split())\nparent_of = [-1 for _ in range(n)]\n#print(parent_of)\ndef root_of(x):\n\tif parent_of[x] < 0:\n\t\treturn x\n\telse:\n\t\tparent_of[x] = root_of(parent_of[x])\n\t\treturn parent_of[x]\n\ndef unite(x,y):\n\ttop_root_x = root_of(x)\n\ttop_root_y = root_of(y)\n\tif top_root_x == top_root_y:\n\t\treturn False\n\tif parent_of[top_root_x] > parent_of[top_root_y]:\n\t\ttop_root_x,top_root_y = top_root_y,top_root_x\n\t#print(parent_of[top_root_y])\n\tparent_of[top_root_x] += parent_of[top_root_y]\n\tparent_of[top_root_y] = top_root_x\n\treturn True\n\ndef size_of(x):\n\t\treturn -parent_of[root_of(x)]\n\ndef is_same(x,y):\n\treturn root_of(x) == root_of(y)\n\nfriend_list = [-1] * n\nfor _ in range(m):\n\ta,b = map(int,input().split())\n\ta -= 1\n\tb -= 1\n\tfriend_list[a] -=1\n\tfriend_list[b] -=1\n\tunite(a,b)\n\nfor _ in range(k):\n\tc,d = map(int,input().split())\n\tc -= 1\n\td -= 1\n\tif root_of(c) == root_of(d):\n\t\tblock_list[c] -= 1\n\t\tblock_list[d] -= 1\nfor i in range(n):\n\tfriend_list[i] += size_of(i)\n\t#print(size_of(i))\nprint(*friend_list)\n', 'import sys\nsys.setrecursionlimit(10*9)\n\nn,m,k = map(int,input().split())\nparent_of = [-1 for _ in range(n)]\n#print(parent_of)\ndef root_of(x):\n\tif parent_of[x] < 0:\n\t\treturn x\n\telse:\n\t\tparent_of[x] = root_of(parent_of[x])\n\t\treturn parent_of[x]\n\ndef unite(x,y):\n\ttop_root_x = root_of(x)\n\ttop_root_y = root_of(y)\n\tif top_root_x == top_root_y:\n\t\treturn False\n\tif parent_of[top_root_x] > parent_of[top_root_y]:\n\t\ttop_root_x,top_root_y = top_root_y,top_root_x\n\t#print(parent_of[top_root_y])\n\tparent_of[top_root_x] += parent_of[top_root_y]\n\tparent_of[top_root_y] = top_root_x\n\treturn True\n\ndef size_of(x):\n\t\treturn -parent_of[root_of(x)]\n\ndef is_same(x,y):\n\treturn root_of(x) == root_of(y)\n\nfriend_list = [-1] * n\nfor _ in range(m):\n\ta,b = map(int,input().split())\n\ta -= 1\n\tb -= 1\n\tfriend_list[a] -=1\n\tfriend_list[b] -=1\n\tunite(a,b)\n\nfor _ in range(k):\n\tc,d = map(int,input().split())\n\tc -= 1\n\td -= 1\n\tif root_of(c) == root_of(d):\n\t\tfriend_list[c] -= 1\n\t\tfriend_list[d] -= 1\nfor i in range(n):\n\tfriend_list[i] += size_of(i)\n\t#print(size_of(i))\nprint(*friend_list)\n'] | ['Runtime Error', 'Accepted'] | ['s782934083', 's838161910'] | [7820.0, 13388.0] | [469.0, 1003.0] | [1055, 1057] |
p02762 | u790012205 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["from collections import deque\nN, M, K = map(int, input().split())\nAB = [list(map(int, input().split())) for _ in range(M)]\nCD = [list(map(int, input().split())) for _ in range(K)]\n\nF = [[[] for _ in range(2)] for _ in range(N)]\nfor m in AB:\n F[m[0] - 1][0].append(m[1] - 1)\n F[m[1] - 1][0].append(m[0] - 1)\nfor k in CD:\n F[k[0] - 1][1].append(k[1] - 1)\n F[k[1] - 1][1].append(k[0] - 1)\n\nL = [0] * N\nm = [[] for _ in range(N)]\n\nfor i in range(N):\n if L[i] != 0:\n continue\n l = []\n c = 0\n d = [0] * N\n d[i] = 1\n l.append(i)\n Q = deque()\n Q.append(i)\n while len(Q) > 0:\n q = Q.pop()\n for j in range(len(F[q][0])):\n a = F[q][0][j]\n if d[a] == 1:\n continue\n d[a] = 1\n c += 1\n Q.append(a)\n l.append(a)\n m[i] = l\n for j in l:\n L[j] = c\n m[j] = l\n\nfor i in range(N):\n print(L[i] - len(F[i][0]) - len(set(F[i][1]) & set(m[i])), end=' ')\n\nprint('')", 'import time\nfrom collections import deque\nN, M, K = map(int, input().split())\nAB = [list(map(int, input().split())) for _ in range(M)]\nCD = [list(map(int, input().split())) for _ in range(K)]\n\nF = [set() for _ in range(N)]\nB = [set() for _ in range(N)]\n\nfor i, j in AB:\n F[i - 1].add(j - 1)\n F[j - 1].add(i - 1)\nfor i, j in CD:\n B[i - 1].add(j - 1)\n B[j - 1].add(i - 1)\n\nQ = deque()\nS = [0] * N\nd = [0] * N\n\nfor i in range(N):\n if d[i] != 0:\n continue\n L = {i}\n d[i] = 1\n Q.append(i)\n while len(Q) > 0:\n q = Q.pop()\n for j in F[q]:\n if d[j] == 0:\n d[j] = 1\n Q.append(j)\n L.add(j)\n for k in L:\n S[k] = len(L) - len(L & F[k]) - len(L & B[k]) - 1\n\nprint(*S)\n'] | ['Time Limit Exceeded', 'Accepted'] | ['s771272677', 's282527909'] | [105860.0, 129544.0] | [2112.0, 1288.0] | [1002, 769] |
p02762 | u797994565 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['class UnionFind:\n def __init__(self, N):\n self.rank = [0] * N\n self.parent = [i for i in range(N)]\n self.n = N\n self.size = [1 for i in range(N)]\n def find(self, x):\n if self.parent[x] == x:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[x]\n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if (x == y):\n return\n if (self.rank[x] < self.rank[y]):\n self.parent[x] = y\n self.size[y] += self.size[x]\n else:\n self.parent[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n def same(self, x, y):\n return self.find(x) == self.find(y)\n def get_parents(self):\n count = 0\n for i in range(self.n):\n if self.find(i) == i:\n count += 1\n return count\n def get_size(self, x):\n root = self.find(x)\n return self.size[root]\nN,M,K = map(int,input().split())\nU = UnionFind(N)\ndirect = [0 for i in range(N)]\nfor i in range(M):\n a,b = map(int,input().split())\n a,b = a-1,b-1\n U.unite(a,b)\n direct[a] += 1\n direct[b] += 1\nneg = [0 for i in range(N)]\nfor i in range(K):\n c,d = map(int,input().split())\n c,d = c-1,d-1\n if U.same(c,d):\n neg[c] += 1\n neg[d] += 1\nans = []\nfor i in range(N):\n print(U.get_size(i))\n ans.append(U.get_size(i)-1-neg[i]-direct[i])\nprint(*ans)', 'class UnionFind:\n def __init__(self, N):\n self.rank = [0] * N\n self.parent = [i for i in range(N)]\n self.n = N\n self.size = [1 for i in range(N)]\n def find(self, x):\n if self.parent[x] == x:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[x]\n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if (x == y):\n return\n if (self.rank[x] < self.rank[y]):\n self.parent[x] = y\n self.size[y] += self.size[x]\n else:\n self.parent[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n def same(self, x, y):\n return self.find(x) == self.find(y)\n def get_parents(self):\n count = 0\n for i in range(self.n):\n if self.find(i) == i:\n count += 1\n return count\n def get_size(self, x):\n root = self.find(x)\n return self.size[root]\nN,M,K = map(int,input().split())\nU = UnionFind(N)\ndirect = [0 for i in range(N)]\nfor i in range(M):\n a,b = map(int,input().split())\n a,b = a-1,b-1\n U.unite(a,b)\n direct[a] += 1\n direct[b] += 1\nneg = [0 for i in range(N)]\nfor i in range(K):\n c,d = map(int,input().split())\n c,d = c-1,d-1\n if U.same(c,d):\n neg[c] += 1\n neg[d] += 1\nans = []\nfor i in range(N):\n ans.append(U.get_size(i)-1-neg[i]-direct[i])\nprint(*ans)'] | ['Wrong Answer', 'Accepted'] | ['s823456481', 's469738161'] | [17068.0, 16540.0] | [1307.0, 1209.0] | [1548, 1523] |
p02762 | u814986259 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import collections\nN, M, K = map(int, input().split())\nAB = [tuple(map(int, input().split())) for i in range(M)]\n\nCD = [tuple(map(int, input().split())) for i in range(K)]\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\n\nF = unionFind(N)\nf = [set() for i in range(N)]\nfor a, b in AB:\n a -= 1\n b -= 1\n f[a].add(b)\n f[b].add(a)\n # F.unite(a+1, b+1)\n\nB = [set() for i in range(N)]\nfor c, d in CD:\n c -= 1\n d -= 1\n B[c].add(d)\n B[d].add(c)\n\nans = [0]*N\n# D = collections.defaultdict(set)\n\n# D[F.root(i)].add(i)\n\n# # print(f)\n\n# x = D[F.root(i)]\n\n\n\n\n# ans[i] = ret\nprint(*ans)\n', 'import collections\nN, M, K = map(int, input().split())\nAB = [tuple(map(int, input().split())) for i in range(M)]\n\nCD = [tuple(map(int, input().split())) for i in range(K)]\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\n\nF = unionFind(N)\nf = [set() for i in range(N)]\nfor a, b in AB:\n a -= 1\n b -= 1\n f[a].add(b)\n f[b].add(a)\n F.unite(a+1, b+1)\n\nB = [set() for i in range(N)]\nfor c, d in CD:\n c -= 1\n d -= 1\n B[c].add(d)\n B[d].add(c)\n\nans = [0]*N\nD = collections.defaultdict(set)\nfor i in range(N):\n D[F.root(i)].add(i)\n\n# # print(f)\n\n# x = D[F.root(i)]\n\n\n\n\n# ans[i] = ret\nprint(*ans)\n', 'import collections\nN, M, K = map(int, input().split())\nAB = [tuple(map(int, input().split())) for i in range(M)]\n\nCD = [tuple(map(int, input().split())) for i in range(K)]\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\n\nF = unionFind(N)\nf = [set() for i in range(N)]\nfor a, b in AB:\n a -= 1\n b -= 1\n f[a].add(b)\n f[b].add(a)\n F.unite(a+1, b+1)\n\nB = [set() for i in range(N)]\nfor c, d in CD:\n c -= 1\n d -= 1\n B[c].add(d)\n B[d].add(c)\n\nans = [0]*N\n# D = collections.defaultdict(set)\n\n# D[F.root(i)].add(i)\n\n# # print(f)\n\n# x = D[F.root(i)]\n\n\n\n\n# ans[i] = ret\nprint(*ans)\n', 'import collections\nimport sys\nsys.setrecursionlimit(10**5)\nN, M, K = map(int, input().split())\nAB = [tuple(map(int, input().split())) for i in range(M)]\n\nCD = [tuple(map(int, input().split())) for i in range(K)]\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\n\nF = unionFind(N)\nf = [set() for i in range(N)]\nfor a, b in AB:\n F.unite(a, b)\n a -= 1\n b -= 1\n f[a].add(b)\n f[b].add(a)\n\nB = [set() for i in range(N)]\nfor c, d in CD:\n c -= 1\n d -= 1\n B[c].add(d)\n B[d].add(c)\n\nans = [0]*N\nD = collections.defaultdict(set)\nfor i in range(N):\n D[F.root(i)].add(i)\n\n# print(f)\nfor i in range(N):\n x = D[F.root(i)]\n ret = len(x)\n ret -= 1\n ret -= len(x & f[i])\n ret -= len(x & B[i])\n ans[i] = ret\nprint(*ans)\n'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s046162431', 's845976664', 's856266603', 's123175536'] | [107240.0, 138628.0, 107184.0, 138588.0] | [1086.0, 1459.0, 1338.0, 1663.0] | [1309, 1301, 1307, 1321] |
p02762 | u824295380 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['N, M ,K= map(int, input().split())\na=[0]*M\nb=[0]*M\nc=[0]*K\nd=[0]*K\n\nfor i in range(M):\n a[i], b[i] = map(int, input().split())\nfor i in range(K):\n c[i], d[i] = map(int, input().split())\nl=[-1]*(N+1)\nla=N\n\nfor i in range(M):\n if l[a[i]]<0 and l[b[i]]<0:\n l[a[i]]=la\n l[b[i]]=la\n la-=1\n elif l[a[i]]>l[b[i]]:\n if l[b[i]]>0:\n l=[x if x is not l[b[i]] else l[a[i]] for x in l ]\n else:\n l[b[i]]=l[a[i]]\n\n else:\n if l[a[i]] > 0:\n l = [x if x is not l[a[i]] else l[b[i]] for x in l]\n else:\n l[a[i]]=l[b[i]]\n\nt=[]\n\nfor i in range(1,N+1):\n\n if l[i]>0:\n p=l.count(l[i])-1\n indexes = [j for j, x in enumerate(a) if x == i]\n for j in range(len(indexes)):\n if l[b[indexes[j]]]==l[i]:\n p-=1\n indexes = [j for j, x in enumerate(b) if x == i]\n for j in range(len(indexes)):\n if l[a[indexes[j]]] == l[i]:\n p -= 1\n indexes = [j for j, x in enumerate(d) if x == i]\n for j in range(len(indexes)):\n if l[c[indexes[j]]] == l[i]:\n p -= 1\n indexes = [j for j, x in enumerate(c) if x == i]\n for j in range(len(indexes)):\n if l[d[indexes[j]]] == l[i]:\n p -= 1\n\n\n else:\n p=0\n t.append(p)\nprint(t)\n', 'N, M ,K= map(int, input().split())\na=[0]*M\nb=[0]*M\nc=[0]*K\nd=[0]*K\n\nfor i in range(M):\n a[i], b[i] = map(int, input().split())\nfor i in range(K):\n c[i], d[i] = map(int, input().split())\n\nl=list(range(N+1))\nr=[0]*(N+1)\nsize=[1]*(N+1)\nla=N\ndi=[[]for _ in range(N+1)]\ndef find(x):\n if l[x]==x:\n return x\n else:\n return find(l[x])\n\ndef union(x,y):\n X=find(x)\n Y=find(y)\n if r[X]>r[Y]:\n l[Y]=l[X]\n size[X]+=size[Y]\n else:\n l[X]=l[Y]\n\n if r[X]==r[Y]:\n r[Y]+=1\n if X!=Y:\n size[Y] += size[X]\nfor i in range(M):\n union(a[i],b[i])\n di[a[i]].append(b[i])\n di[b[i]].append(a[i])\nfor i in range(K):\n if (find(c[i])==find(d[i])):\n di[c[i]].append(d[i])\n di[d[i]].append(c[i])\n\nt=[]\nfor i in range(N+1):\n p=size[find(i)]-1-len(di[i])\n\n t.append(p)\n\n\nprint(" ".join(map(str, t[1:])))\n'] | ['Wrong Answer', 'Accepted'] | ['s445788135', 's479217445'] | [20644.0, 47076.0] | [2105.0, 1162.0] | [1361, 895] |
p02762 | u834269725 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['class Node():\n def __init__(self, v):\n self.value = v\n self.friends = set()\n self.blocked = set()\n\nn, m, k = list(map(int, input().split()))\nlink = {i: Node(i) for i in range(1, n+1)}\ngroups = []\nfor _ in range(m):\n a, b = list(map(int, input().split()))\n link[a].friends.add(b)\n link[b].friends.add(a)\n holders = []\n for i, g in enumerate(groups):\n if a in g or b in g:\n g.add(a)\n g.add(b)\n holders.append(i)\n if len(holders) >= 2:\n ng = set()\n for h in reversed(holders):\n ng |= groups[h]\n groups.pop(h)\n groups.append(ng)\n elif len(holders) == 0:\n groups.append(set([a,b]))\n\nfor _ in range(k):\n c, d = list(map(int, input().split()))\n link[c].blocked.add(d)\n link[d].blocked.add(c)\n\nfor i in range(1, n+1):\n for g in groups:\n if i in g:\n cnt = len(g - link[i].blocked - link[i].friends) - 1 \n break\n else:\n cnt = 0\n print(cnt, end="" if i == n else " ")\n', 'class Node():\n def __init__(self, v):\n self.value = v\n self.friends = set()\n self.blocked = set()\n\nn, m, k = list(map(int, input().split()))\nlink = {i: Node(i) for i in range(1, n+1)}\nfor _ in range(m):\n a, b = list(map(int, input().split()))\n link[a].friends.add(link[b])\n link[b].friends.add(link[a])\n\nfor _ in range(k):\n c, d = list(map(int, input().split()))\n link[c].blocked.add(link[d])\n link[d].blocked.add(link[c])\n\ndef traverse(hist, friends, blocked):\n for f in friends:\n if f not in hist:\n if f not in blocked:\n hist.add(f)\n traverse(hist, f.friends, blocked)\n return hist\n\nfor i in range(1, n+1):\n node = link[i]\n hist = traverse(set(), node.friends, node.blocked)\n cnt = len(hist - set([node]) - node.friends - node.blocked)\n print(cnt, end="" if i == n else " ")\n', 'n, m, k = list(map(int, input().split()))\nlink = {i: (set(), set()) for i in range(1, n+1)}\n\nfriends = 0\nblocked = 1\n\ngroups = []\nfor _ in range(m):\n a, b = list(map(int, input().split()))\n link[a][friends].add(b)\n link[b][friends].add(a)\n holders = []\n for i, g in enumerate(groups):\n if a in g or b in g:\n g.add(a)\n g.add(b)\n holders.append(i)\n if len(holders) >= 2:\n ng = set()\n for h in reversed(holders):\n ng |= groups[h]\n groups.pop(h)\n groups.append(ng)\n elif len(holders) == 0:\n groups.append(set([a,b]))\n\nfor _ in range(k):\n c, d = list(map(int, input().split()))\n link[c][blocked].add(d)\n link[d][blocked].add(c)\n\nfor i in range(1, n+1):\n for g in groups:\n if i in g:\n cnt = len(g - link[i][blocked] - link[i][friends]) - 1 \n break\n else:\n cnt = 0\n print(cnt, end="" if i == n else " ")\n', 'class Tree:\n def __init__(self, v: int):\n self.value = v\n self.size = 1\n self.depth = 1\n self.parent = None\n self.friends = set()\n self.blocked = 0\n\n def get_root(self):\n t = self\n while(t.parent != None):\n t = t.parent\n return t\n\n def merge(self, t):\n p, c = (self, t) if self.depth > t.depth else (t, self)\n c.parent = p\n p.depth = max(p.size, c.size + 1)\n p.size += c.size\n\ndef main():\n n, m, k = [int(s) for s in input().split()]\n forest = [Tree(i+1) for i in range(n)]\n\n for i in range(m):\n a, b = [int(s) for s in input().split()]\n ta, tb = forest[a-1], forest[b-1]\n ta.friends.add(b)\n tb.friends.add(a)\n ra = ta.get_root()\n rb = tb.get_root()\n if ra != rb:\n ra.merge(rb)\n\n roots = [t.get_root() for t in forest]\n for i in range(k):\n c, d = [int(s) for s in input().split()]\n tc, td = forest[c-1], forest[d-1]\n rc = roots[c-1]\n rd = roots[d-1]\n if rc == rd:\n tc.blocked +=1\n td.blocked +=1\n\n cands = []\n for t in forest:\n root = roots[t.value - 1]\n cand = root.size - len(t.friends) - t.blocked - 1\n cands.append(str(cand))\n print(" ".join(cands))\n\nif __name__ == \'__main__\':\n main()\n'] | ['Time Limit Exceeded', 'Runtime Error', 'Time Limit Exceeded', 'Accepted'] | ['s244556809', 's641412837', 's905373348', 's069504477'] | [103712.0, 93472.0, 93532.0, 74828.0] | [2109.0, 2109.0, 2109.0, 1283.0] | [1046, 881, 962, 1366] |
p02762 | u852613820 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\ninput = sys.stdin.readline\n\ndef main():\n N, M, K = map(int, input().split())\n\n friends = [[False] * N for _ in range(N)]\n print(friends)\n\n for _ in range(M):\n A, B = map(int,input().split())\n friends[A-1][B-1] = True\n friends[B-1][A-1] = True\n\n print(friends)\n \n\nif __name__ == "__main__":\n main()\n', 'import sys\nfrom collections import deque\ninput = sys.stdin.readline\n\nclass UnionFind(object):\n def __init__(self, N):\n \n self.node = [-1] * N\n\n def root(self, x):\n if self.node[x] < 0:\n \n return x\n else:\n \n self.node[x] = self.root(self.node[x])\n \n return self.node[x]\n\n def size(self, x):\n \n \n return -self.node[self.root(x)]\n\n def connect(self, x, y):\n a = self.root(x) \n b = self.root(y) \n\n \n if a == b:\n return\n\n \n if self.size(a) < self.size(b):\n a, b = b, a\n\n \n self.node[a] += self.node[b]\n \n self.node[b] = a\n\n return\n\n def show_nodes(self):\n return self.node\n\n\ndef main():\n N, M, K = map(int, input().split())\n\n tree = UnionFind(N)\n\n friends = [ list(map(int, input().split())) for _ in range(M)]\n\n for A, B in friends:\n tree.connect(A-1, B-1)\n\n ans = [tree.size(x) - 1 for x in range(N)]\n\n for A, B in friends:\n if tree.root(A-1) == tree.root(B-1):\n ans[A-1] -= 1\n ans[B-1] -= 1\n\n for _ in range(K):\n C, D = map(int,input().split())\n if tree.root(C - 1) == tree.root(D - 1):\n ans[C-1] -= 1\n ans[D-1] -= 1\n\n print(*ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s556912842', 's851817755'] | [1975284.0, 38076.0] | [2226.0, 1120.0] | [351, 2084] |
p02762 | u860002137 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['class UnionFind:\n def __init__(self, n):\n self.root = list(range(n + 1))\n self.size = [1] * (n + 1)\n\n def find(self, x):\n root = self.root\n while root[x] != x:\n root[x] = root[root[x]]\n x = root[x]\n return 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 sx, sy = self.size[x], self.size[y]\n if sx < sy:\n self.root[x] = y\n self.size[y] += sx\n else:\n self.root[y] = x\n self.size[x] += sy\n\n\nn, m, k = map(int, input().split())\n\n\nuf = UnionFind(n)\n\nfriends = [0] + (n + 1)\nchain = [0] + (n + 1)\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a] += 1\n friends[b] += 1\n uf.union(a, b)\n\nfor i in range(1, n + 1):\n for j in range(1, n + 1):\n if uf.find(i) == uf.find(j):\n chain[i] += 1\n\nfor _ in range(k):\n c, d = map(int, input().split())\n if uf.find(c) == uf.find(d):\n friends[c] += 1\n friends[d] += 1\n\nans = []\nfor i in range(1, n + 1):\n ans.append(chain[i] - friends[i] - 1)\n\nprint(*ans)', 'from collections import defaultdict\n\n\nclass UnionFind:\n def __init__(self, n):\n self.root = list(range(n + 1))\n self.size = [1] * (n + 1)\n\n def find(self, x):\n root = self.root\n while root[x] != x:\n root[x] = root[root[x]]\n x = root[x]\n return 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 sx, sy = self.size[x], self.size[y]\n if sx < sy:\n self.root[x] = y\n self.size[y] += sx\n else:\n self.root[y] = x\n self.size[x] += sy\n\n\nn, m, k = map(int, input().split())\n\n\nuf = UnionFind(n)\n\nfriends = defaultdict(set)\nblock = defaultdict(set)\nchain = defaultdict(set)\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a].add(b)\n friends[b].add(a)\n uf.union(a, b)\n\nfor _ in range(k):\n c, d = map(int, input().split())\n block[c].add(d)\n block[d].add(c)\n\nfor i in range(1, n + 1):\n for j in range(1, n + 1):\n if uf.find(i) == uf.find(j):\n chain[i].add(j)\n chain[j].add(i)\n\nans = []\nfor i in range(1, n + 1):\n ans.append(len(chain[i] - friends[i] - block[i] - 1))\n\nprint(*ans)', "from collections import defaultdict\nfrom numba import jit\n\n\nclass UnionFind:\n def __init__(self, n):\n self.root = list(range(n + 1))\n self.size = [1] * (n + 1)\n\n def find(self, x):\n root = self.root\n while root[x] != x:\n root[x] = root[root[x]]\n x = root[x]\n return 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 sx, sy = self.size[x], self.size[y]\n if sx < sy:\n self.root[x] = y\n self.size[y] += sx\n else:\n self.root[y] = x\n self.size[x] += sy\n\n\nn, m, k = map(int, input().split())\n\n\n@jit('void(i8, i8, i8)')\ndef solve(n, m, k):\n uf = UnionFind(n)\n\n friends = defaultdict(int)\n chain = defaultdict(int)\n\n for _ in range(m):\n a, b = map(int, input().split())\n friends[a] += 1\n friends[b] += 1\n uf.union(a, b)\n\n for i in range(1, n + 1):\n for j in range(1, n + 1):\n if uf.find(i) == uf.find(j):\n chain[i] += 1\n\n for _ in range(k):\n c, d = map(int, input().split())\n if uf.find(c) == uf.find(d):\n friends[c] += 1\n friends[d] += 1\n\n ans = []\n for i in range(1, n + 1):\n ans.append(chain[i] - friends[i] - 1)\n\n print(*ans)\n\n\nsolve(n, m, k)", 'class UnionFind:\n def __init__(self, n):\n self.ps = [-1] * (n + 1)\n\n def find(self, x):\n if self.ps[x] < 0:\n return x\n else:\n self.ps[x] = self.find(self.ps[x])\n return self.ps[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return False\n if self.ps[x] > self.ps[y]:\n x, y = y, x\n self.ps[x] += self.ps[y]\n self.ps[y] = x\n return True\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n x = self.find(x)\n return -self.ps[x]\n\n\nn, m, k = map(int, input().split())\n\n\nuf = UnionFind(n)\n\nfriends = [0] * (n + 1)\nchain = [0] * (n + 1)\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a] += 1\n friends[b] += 1\n uf.union(a, b)\n\nfor _ in range(k):\n c, d = map(int, input().split())\n if uf.same(c, d):\n friends[c] += 1\n friends[d] += 1\n\nans = []\nfor i in range(1, n + 1):\n ans.append(uf.size(i) - friends[i] - 1)\n\nprint(*ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s075126996', 's963419380', 's985337485', 's524732508'] | [13628.0, 329892.0, 133672.0, 19288.0] | [31.0, 2213.0, 2209.0, 672.0] | [1154, 1232, 1366, 1085] |
p02762 | u872538555 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import deque\n \ndef dfs(friends, x):\n visited = [0] * n\n d = deque([x])\n ans = []\n while d:\n num = d.pop()\n \n #print(num, \'->\',end=\'\')\n \n if visited[num] == 1:\n #print(\'x\')\n continue\n \n visited[num] = 1\n ans.append(num)\n \n for a in friends[num]:\n d.append(a)\n \n #print()\n return ans\n \nif __name__ == "__main__": \n n, m, k = map(int, input().split())\n \n friends = [[] for _ in range(n)]\n for i in range(m):\n x, y = map(lambda z: int(z) - 1, input().split())\n friends[x].append(y)\n friends[y].append(x)\n \n blocks = [[] for _ in range(n)]\n for i in range(k):\n x, y = map(lambda z: int(z) - 1, input().split())\n blocks[x].append(y)\n blocks[y].append(x)\n \n #print(friends)\n #print(blocks)\n \n for i in range(n):\n vec = dfs(friends, i)\n ans = len(vec)\n \n ans -= len(friends[i])\n \n for b in blocks[i]:\n if b in vec:\n ans -= 1\n \n ans -= 1\n \n print(ans, end=\' \')', 'from collections import deque\n \ndef dfs(friends, x):\n visited = [0] * n\n d = deque([x])\n ans = []\n while d:\n num = d.pop()\n \n #print(num, \'->\',end=\'\')\n \n if visited[num] == 1:\n #print(\'x\')\n continue\n \n visited[num] = 1\n ans.append(num)\n \n for a in friends[num]:\n d.append(a)\n \n #print()\n return ans\n \nif __name__ == "__main__": \n n, m, k = map(int, input().split())\n \n friends = [[] for _ in range(n)]\n for i in range(m):\n x, y = map(lambda z: int(z) - 1, input().split())\n friends[x].append(y)\n friends[y].append(x)\n \n blocks = [[] for _ in range(n)]\n for i in range(k):\n x, y = map(lambda z: int(z) - 1, input().split())\n blocks[x].append(y)\n blocks[y].append(x)\n \n #print(friends)\n #print(blocks)\n \n for i in range(n):\n vec = dfs(friends, i)\n ans = len(vec)\n \n for f in friends[i]:\n if f in vec:\n ans -= 1\n \n for b in blocks[i]:\n if b in vec:\n ans -= 1\n \n ans -= 1\n \n print(ans, end=\' \')', 'from collections import deque\n\ndef dfs(friend, group, number, s):\n d = deque([s])\n \n while d:\n num = d.pop()\n if group[num] != 0:\n continue\n \n group[num] = number\n \n for n in friend[num]:\n d.append(n)\n \n return group\n \ndef main():\n n, m, k = map(int, input().split())\n \n friend = [[] for _ in range(n)]\n for _ in range(m):\n a, b = map(lambda x: int(x) - 1, input().split())\n friend[a].append(b)\n friend[b].append(a)\n \n block = [[] for _ in range(n)]\n for _ in range(k):\n a, b = map(lambda x: int(x) - 1, input().split())\n block[a].append(b)\n block[b].append(a)\n \n group = [0] * n\n number = 1\n for i in range(n):\n if group[i] != 0:\n continue\n \n group = dfs(friend, group, number, i)\n number += 1\n \n link = []\n for i in range(number + 1):\n link.append(group.count(i))\n \n for i in range(n):\n ans = 0\n ans += link[group[i]]\n ans -= len(friend)\n for b in block[i]:\n if group[i] == group[b]:\n ans -= 1\n \n print(ans, end=\' \')\n \nif __name__ == "__main__":\n main()', 'from collections import deque\n \ndef dfs(friends, x):\n visited = [0] * n\n d = deque([x])\n ans = []\n while d:\n num = d.pop()\n \n #print(num, \'->\',end=\'\')\n \n if visited[num] == 1:\n #print(\'x\')\n continue\n \n visited[num] = 1\n ans.append(num)\n \n for a in friends[num]:\n d.append(a)\n \n #print()\n return ans\n \nif __name__ == "__main__": \n n, m, k = map(int, input().split())\n \n friends = [[] for _ in range(n)]\n for i in range(m):\n x, y = map(lambda z: int(z) - 1, input().split())\n friends[x].append(y)\n friends[y].append(x)\n \n blocks = [[] for _ in range(n)]\n for i in range(k):\n x, y = map(lambda z: int(z) - 1, input().split())\n blocks[x].append(y)\n blocks[y].append(x)\n \n #print(friends)\n #print(blocks)\n \n label = [-1] * n\n vec_len = []\n num = 0\n for i in range(n):\n if label[i] != -1:\n continue\n \n vec = dfs(friends, i)\n vec_len.append(len(vec))\n for j in vec:\n label[j] = num\n \n num += 1\n \n for i in range(n):\n ans = 0\n ans += vec_len[label[i]]\n ans -= len(friends[i])\n \n for b in blocks[i]:\n if label[i] == label[b]:\n ans -= 1\n \n ans -= 1\n \n print(ans, end=\' \')', 'import sys\nsys.setrecursionlimit(10**5)\n\nclass UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n)]\n self.rank = [0] * n \n self.size = [1] * 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 same(self, x, y):\n return self.find(x) == self.find(y)\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.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] = self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n \n if self.rank[x] == self.rank[y]:\n self.rank[y] += 1\n \nn, m, k = map(int, input().split())\nfriends = [[] for _ in range(n)]\nblocks = [[] for _ in range(n)]\n\nfor i in range(m):\n x, y = map(lambda x: int(x) - 1, input().split())\n friends[x].append(y)\n friends[y].append(x)\n\nfor i in range(k):\n x, y = map(lambda x: int(x) - 1, input().split())\n blocks[x].append(y)\n blocks[y].append(x)\n\nuf = UnionFind(n)\nfor i in range(n):\n for f in friends[i]:\n uf.union(i, f)\n\n\nans = [uf.size[uf.find(i)] - 1 for i in range(n)]\n\nfor i in range(n):\n ans[i] -= len(friends[i])\n\nfor i in range(n):\n for b in blocks[i]:\n if uf.same(i, b):\n ans[i] -= 1\n\nprint(*ans)\n'] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Wrong Answer', 'Time Limit Exceeded', 'Accepted'] | ['s138149359', 's404632793', 's416651101', 's474192648', 's579036896'] | [43968.0, 43948.0, 42004.0, 43204.0, 54252.0] | [2107.0, 2106.0, 2109.0, 2106.0, 1859.0] | [1198, 1246, 1259, 1470, 1588] |
p02762 | u873927631 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['#!/usr/bin/env python3\nimport sys\nfrom collections import defaultdict\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n self.ranks = [0] * 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.ranks[x] < self.ranks[y]:\n self.parents[x] = y\n else:\n self.parents[y] = x\n if self.ranks[x] == self.ranks[y]:\n self.ranks[x]+=1\n\n # if self.parents[x] > self.parents[y]:\n \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 tup(a,b):\n return (min(a,b),max(a,b))\n\ndef solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]"):\n friends = set()\n group = UnionFind(N)\n for i in range(M):\n friends.add(tup(A[i]-1,B[i]-1))\n group.union(A[i]-1,B[i]-1)\n for i in range(K):\n friends.add(tup(C[i]-1,D[i]-1))\n result = ""\n isFirst = True\n roots = group.roots()\n rootSets = {r: [] for r in roots }\n for i in range(N):\n r = group.find(i)\n rootSets[r].append(i)\n for i in range(N):\n c = 0\n r = group.find(i)\n # for g in rootSets[r]:\n # if g != i and tup(i,g) not in friends:\n # c+= 1\n if not isFirst:\n result+=" "\n else:\n isFirst = False\n result+=str(c)\n print(result)\n return\n\n\n# Generated by 1.1.6 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 K = 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 C = [int()] * (K) # type: "List[int]"\n D = [int()] * (K) # type: "List[int]"\n for i in range(K):\n C[i] = int(next(tokens))\n D[i] = int(next(tokens))\n solve(N, M, K, A, B, C, D)\n\nif __name__ == \'__main__\':\n main()\n', '#!/usr/bin/env python3\nimport sys\nfrom collections import defaultdict\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n self.ranks = [0] * 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.ranks[x] < self.ranks[y]:\n self.parents[x] = y\n else:\n self.parents[y] = x\n if self.ranks[x] == self.ranks[y]:\n self.ranks[x]+=1\n\n # if self.parents[x] > self.parents[y]:\n \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 tup(a,b):\n return (min(a,b),max(a,b))\n\ndef solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]"):\n friends = defaultdict(bool)\n group = UnionFind(N)\n for i in range(M):\n friends[tup(A[i]-1,B[i]-1)] = True\n group.union(A[i]-1,B[i]-1)\n for i in range(K):\n friends[tup(C[i]-1,D[i]-1)] = True\n result = ""\n isFirst = True\n roots = group.roots()\n rootSets = {r: set() for r in roots }\n for i in range(N):\n r = group.find(i)\n rootSets[r].add(i)\n \n # c = 0\n # r = group.find(i)\n # for g in rootSets[r]:\n # if g != i and not friends[tup(i,g)]:\n # c+= 1\n # if not isFirst:\n # result+=" "\n # else:\n # isFirst = False\n # result+=str(c)\n print(result)\n return\n\n\n# Generated by 1.1.6 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 K = 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 C = [int()] * (K) # type: "List[int]"\n D = [int()] * (K) # type: "List[int]"\n for i in range(K):\n C[i] = int(next(tokens))\n D[i] = int(next(tokens))\n solve(N, M, K, A, B, C, D)\n\nif __name__ == \'__main__\':\n main()\n', '#!/usr/bin/env python3\nimport sys\nfrom collections import defaultdict\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n self.ranks = [0] * 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.ranks[x] < self.ranks[y]:\n self.parents[x] = y\n else:\n self.parents[y] = x\n if self.ranks[x] == self.ranks[y]:\n self.ranks[x]+=1\n\n # if self.parents[x] > self.parents[y]:\n \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 tup(a,b):\n return (min(a,b),max(a,b))\n\ndef solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]"):\n friends = set()\n fc = [0 for i in range(N)]\n group = UnionFind(N)\n for i in range(M):\n friends.add(tup(A[i]-1,B[i]-1))\n group.union(A[i]-1,B[i]-1)\n fc[A[i]-1]+=1\n fc[B[i]-1]+=1\n for i in range(K):\n friends.add(tup(C[i]-1,D[i]-1))\n if group.find(C[i]-1) == group.find(D[i]-1):\n fc[C[i]-1]+=1\n fc[D[i]-1]+=1\n result = ""\n isFirst = True\n roots = group.roots()\n rootSets = {r: [] for r in roots }\n for i in range(N):\n r = group.find(i)\n rootSets[r].append(i)\n for i in range(N):\n r = group.find(i)\n c = len(rootSets[r]) - fc[i] - 1\n if not isFirst:\n result+=" "\n else:\n isFirst = False\n result+=str(c)\n print(result)\n return\n\n\n# Generated by 1.1.6 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 K = 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 C = [int()] * (K) # type: "List[int]"\n D = [int()] * (K) # type: "List[int]"\n for i in range(K):\n C[i] = int(next(tokens))\n D[i] = int(next(tokens))\n solve(N, M, K, A, B, C, D)\n\nif __name__ == \'__main__\':\n main()\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s088405930', 's430803217', 's738452530'] | [80236.0, 99856.0, 81000.0] | [781.0, 714.0, 1077.0] | [3177, 3209, 3275] |
p02762 | u888092736 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\nfrom collections import defaultdict\n\nsys.setrecursionlimit(2147483647)\n\n\nclass Graph:\n def __init__(self):\n self.graph = defaultdict(set)\n\n def interconnect(self, u, v):\n self.graph[u].add(v)\n self.graph[v].add(u)\n\n def dfs(self, start):\n seen = set()\n return self.dfs_recurse(start, seen)\n\n def dfs_recurse(self, v, seen):\n seen.add(v)\n for u in self.graph[v] - seen:\n self.dfs_recurse(u, seen)\n return seen\n\n\nif __name__ == "__main__":\n n, m, k = map(int, input().split())\n\n friends = Graph()\n blocked = defaultdict(set)\n\n [friends.interconnect(*map(lambda x: int(x) - 1, input().split())) for _ in range(m)]\n for _ in range(k):\n c, d = map(lambda x: int(x) - 1, input().split())\n blocked[c - 1].add(d)\n blocked[d - 1].add(c)\n\n visited = [False] * n\n counts = [0] * n\n\n for v in range(n):\n if visited[v]:\n continue\n elems = friends.dfs(v)\n elems_cnt = len(elems)\n for i in elems:\n counts[i] = elems_cnt - len(elems & friends.graph[i]) - len(elems & blocked[i]) - 1\n visited[i] = True\n\n print(*counts)\n', "from collections import defaultdict\n\n\ndef dfs(graph, start):\n visited, stack = set(), [start]\n while stack:\n vertex = stack.pop()\n if vertex not in visited:\n visited.add(vertex)\n stack.extend(graph[vertex] - visited)\n return visited\n\nn, m, k = map(int, input().split())\nAB = [map(int, input().split()) for _ in range(m)]\nCD = [map(int, input().split()) for _ in range(k)]\n\ngraph_f = defaultdict(set)\ngraph_b = defaultdict(set)\n\nfor a, b in AB:\n graph_f[a].add(b)\n graph_f[b].add(a)\n\nfor c, d in CD:\n graph_b[c].add(d)\n graph_b[d].add(c)\n\nres = [0] * n\n\nfor i in range(n):\n reachables = dfs(graph_f, i)\n for j in range(n):\n if i == j:\n continue\n else:\n if j in reachables and j not in graph_f[i] and j not in graph_b[i]:\n res[i] += 1\n\nprint(' '.join(map(str, res)))", '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 same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n\nif __name__ == "__main__":\n n, m, k = map(int, input().split())\n\n u = UnionFind(n)\n f_cnts = [0] * n\n b_cnts = [0] * n\n\n for _ in range(m):\n x, y = map(lambda x: int(x) - 1, input().split())\n u.union(x, y)\n f_cnts[x] += 1\n f_cnts[y] += 1\n\n for _ in range(k):\n x, y = map(lambda x: int(x) - 1, input().split())\n if u.same(x, y):\n b_cnts[x] += 1\n b_cnts[y] += 1\n\n cnts = ((u.size(i) - f_cnts[i] - b_cnts[i] - 1) for i in range(n))\n print(\' \'.join(map(str, cnts)))\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s175068368', 's184981415', 's324984220'] | [98640.0, 142756.0, 15548.0] | [2105.0, 2112.0, 1120.0] | [1202, 878, 1228] |
p02762 | u891847179 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["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\n\nclass UnionFindLabel(UnionFind):\n def __init__(self, labels):\n assert len(labels) == len(set(labels))\n\n self.n = len(labels)\n self.parents = [-1] * self.n\n self.d = {x: i for i, x in enumerate(labels)}\n self.d_inv = {i: x for i, x in enumerate(labels)}\n\n def find_label(self, x):\n return self.d_inv[super().find(self.d[x])]\n\n def union(self, x, y):\n super().union(self.d[x], self.d[y])\n\n def size(self, x):\n return super().size(self.d[x])\n\n def same(self, x, y):\n return super().same(self.d[x], self.d[y])\n\n def members(self, x):\n root = self.find(self.d[x])\n return [self.d_inv[i] for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [self.d_inv[i] for i, x in enumerate(self.parents) if x < 0]\n\ndef MAP(): return map(int, input().split())\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\n\nN, M, K = list(map(int, input().split()))\nfriend_dict = {i: set() for i in range(1, N + 1)}\nblock_dict = {i: set() for i in range(1, N + 1)}\nfor i in range(M):\n node1, node2 = list(map(int, input().split()))\n friend_dict[node1].add(node2)\n friend_dict[node2].add(node1)\nfor i in range(K):\n node1, node2 = list(map(int, input().split()))\n block_dict[node1].add(node2)\n block_dict[node2].add(node1)\n\nuf = UnionFindLabel(range(1, N + 1))\nfor node, friends in friend_dict.items():\n for friend_node in friends:\n if not uf.same(node, friend_node):\n uf.union(node, friend_node)\n\nfor node in range(1, N + 1):\n cnt = 0\n for mem_node in uf.members(node):\n if mem_node != node and mem_node not in friend_dict[node] and mem_node not in block_dict[node]:\n cnt += 1\n print(cnt)\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\n\nclass UnionFindLabel(UnionFind):\n def __init__(self, labels):\n assert len(labels) == len(set(labels))\n\n self.n = len(labels)\n self.parents = [-1] * self.n\n self.d = {x: i for i, x in enumerate(labels)}\n self.d_inv = {i: x for i, x in enumerate(labels)}\n\n def find_label(self, x):\n return self.d_inv[super().find(self.d[x])]\n\n def union(self, x, y):\n super().union(self.d[x], self.d[y])\n\n def size(self, x):\n return super().size(self.d[x])\n\n def same(self, x, y):\n return super().same(self.d[x], self.d[y])\n\n def members(self, x):\n root = self.find(self.d[x])\n return [self.d_inv[i] for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [self.d_inv[i] for i, x in enumerate(self.parents) if x < 0]\n\ndef MAP(): return map(int, input().split())\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\n\nN, M, K = list(map(int, input().split()))\nans = [-1] * N\nuf = UnionFindLabel(range(1, N + 1))\nfor i in range(M):\n node1, node2 = list(map(int, input().split()))\n ans[node1 - 1] -= 1\n ans[node2 - 1] -= 1\n if not uf.same(node1, node2):\n uf.union(node1, node2)\nfor i in range(N):\n ans[i] += uf.size(i + 1)\nfor i in range(K):\n node1, node2 = list(map(int, input().split()))\n if uf.same(node1, node2):\n ans[node1 - 1] -= 1\n ans[node2 - 1] -= 1\nprint(*ans)\n"] | ['Time Limit Exceeded', 'Accepted'] | ['s665825941', 's095041546'] | [121800.0, 39544.0] | [2110.0, 1602.0] | [2898, 2561] |
p02762 | u896451538 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import math\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport bisect\nimport sys\nimport copy\n\nsys.setrecursionlimit(10**9)\nmod = 10**7+9\ninf = 10**20\n\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\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 if x == y:\n 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\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\nn,m,k = LI()\n\nab = [LI() for _ in range(m)]\ncd = [LI() for _ in range(k)]\nuf = UnionFind(n)\n\nfor a,b in ab:\n uf.union(a-1,b-1)\nans = [uf.size(i)-1 for i in range(n)]\nprint(uf.parents)\nfor a,b in ab:\n if uf.same(a-1,b-1):\n ans[a-1]-=1\n ans[b-1]-=1\nfor c,d in cd:\n if uf.same(c-1,d-1):\n ans[c-1]-=1\n ans[d-1]-=1\n\nprint(ans)', 'import math\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport bisect\nimport sys\nimport copy\n\nsys.setrecursionlimit(10**9)\nmod = 10**7+9\ninf = 10**20\n\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\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 if x == y:\n 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\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\nn,m,k = LI()\n\nab = [LI() for _ in range(m)]\ncd = [LI() for _ in range(k)]\nuf = UnionFind(n)\n\nfor a,b in ab:\n uf.union(a-1,b-1)\nans = [uf.size(i)-1 for i in range(n)]\nfor a,b in ab:\n if uf.same(a-1,b-1):\n ans[a-1]-=1\n ans[b-1]-=1\nfor c,d in cd:\n if uf.same(c-1,d-1):\n ans[c-1]-=1\n ans[d-1]-=1\n\nprint(*ans)'] | ['Wrong Answer', 'Accepted'] | ['s602570514', 's771332821'] | [65172.0, 64328.0] | [1045.0, 1087.0] | [1638, 1621] |
p02762 | u899308536 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['N,M,K = list(map(int,input().split()))\n\n\n\n\n\nG = [[] for _ in range(N)]\n# print(G)\n\nfor _ in range(M):\n a,b = list(map(int,input().split()))\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n# print(G)\n\nKG = [[] for _ in range(N)]\n\nfor _ in range(K):\n a,b = list(map(int,input().split()))\n KG[a-1].append(b-1)\n KG[b-1].append(a-1)\n\n\ndef dfs(G,v):\n global l\n \n seen[v] = 1\n l += 1\n # print(v+1)\n seenV.append(v)\n \n for next_v in G[v]:\n if seen[next_v] == 1:\n continue\n else:\n dfs(G,next_v)\n\nAdj_size = [0]*N\n\nAdj = [0]*N\nseen = [0]*N\nY = []\nfor v in range(N):\n l = 0\n seenV = []\n if seen[v] == 0:\n dfs(G,v)\n \n \n # print("l=",l)\n \n for v in seenV:\n Adj_size[v] = l\n Adj[v] = seenV\n # print(Adj_size)\n \n \n y = Adj_size[v] - len(G[v])-1\n for k in KG[v]:\n if k in Adj[v]:\n y += -1\n # print("v=",v+1,"y=",y)\n Y.append(str(y))\n\nprint(" ".join(Y))\n\n', 'N,M,K = list(map(int,input().split()))\n\n\n\n\n\nG = [[] for _ in range(N)]\n\nfor _ in range(M):\n a,b = list(map(int,input().split()))\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n# print("G:",G)\n\nKG = [[] for _ in range(N)]\n\nfor _ in range(K):\n a,b = list(map(int,input().split()))\n KG[a-1].append(b-1)\n KG[b-1].append(a-1)\n# print("KG:",KG)\n\n\n\n', 'N,M,K = list(map(int,input().split()))\n\n\n\n\n\nG = [[] for _ in range(N)]\n\nfor _ in range(M):\n a,b = list(map(int,input().split()))\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n# print("G:",G)\n\nKG = [[] for _ in range(N)]\n\nfor _ in range(K):\n a,b = list(map(int,input().split()))\n KG[a-1].append(b-1)\n KG[b-1].append(a-1)\n# print("KG:",KG)\n\n\n\ndef dfs(G,v):\n # global l\n \n seen[v] = 1\n # l += 1\n # print(v+1)\n seenV.append(v)\n \n for next_v in G[v]:\n if seen[next_v] == 1:\n continue\n else:\n dfs(G,next_v)\n\n# Adj_size = [0]*N\n\nAdj = [[] for _ in range(N)]\nseen = [0]*N\nY = []\nfor v in range(N):\n # l = 0\n if seen[v] == 0:\n \n seenV = []\n dfs(G,v)\n \n\n\n', 'N,M,K = list(map(int,input().split()))\n\n\n\n\n\nG = [[] for _ in range(N)]\n\nfor _ in range(M):\n a,b = list(map(int,input().split()))\n G[a-1].append(b-1)\n G[b-1].append(a-1)\nprint("G:",G)\n\nKG = [[] for _ in range(N)]\n\nfor _ in range(K):\n a,b = list(map(int,input().split()))\n KG[a-1].append(b-1)\n KG[b-1].append(a-1)\nprint("KG:",KG)\n\ndef dfs(G,v):\n global l\n \n seen[v] = 1\n l += 1\n # print(v+1)\n seenV.append(v)\n \n for next_v in G[v]:\n if seen[next_v] == 1:\n continue\n else:\n dfs(G,next_v)\n\nAdj_size = [0]*N\n\nAdj = [0]*N\nseen = [0]*N\nY = []\nfor v in range(N):\n l = 0\n seenV = []\n if seen[v] == 0:\n dfs(G,v)\n print("dfs done !!!")\n print("v=",v+1,"seen:",seen)\n print("l=",l)\n print(seenV)\n for sv in seenV:\n Adj_size[sv] = l\n Adj[sv] = seenV\n # print("Adj_size:",Adj_size)\n \n \n y = Adj_size[v] - len(G[v])-1\n for k in KG[v]:\n if k in Adj[v]:\n y += -1\n print("v=",v+1,"y=",y)\n Y.append(str(y))\n\nprint("ADj",Adj)\nprint("Y",Y)\nprint("G",G)\n\nprint(" ".join(Y))\n\n', 'N,M,K = list(map(int,input().split()))\n\n\n\n\n\nG = [[] for _ in range(N)]\n\nfor _ in range(M):\n a,b = list(map(int,input().split()))\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n# print("G:",G)\n\nKG = [[] for _ in range(N)]\n\nfor _ in range(K):\n a,b = list(map(int,input().split()))\n KG[a-1].append(b-1)\n KG[b-1].append(a-1)\n# print("KG:",KG)\n\n\n\ndef dfs(G,v):\n # global l\n \n seen[v] = 1\n # l += 1\n # print(v+1)\n seenV.append(v)\n \n for next_v in G[v]:\n if seen[next_v] == 1:\n continue\n else:\n dfs(G,next_v)\n\n# Adj_size = [0]*N\n\nAdj = [[] for _ in range(N)]\nseen = [0]*N\nY = []\nfor v in range(N):\n # l = 0\n seenV = []\n if seen[v] == 0:\n # dfs(G,v)\n pass\n \n \n \n # print("l=",l)\n \n \n for sv in seenV:\n Adj[sv] = seenV\n \n # print("Adj[",v,"] :",Adj[v])\n \n \n \n y = len(Adj[v]) - len(G[v]) - 1\n for k in KG[v]:\n if k in Adj[v]:\n y += -1\n # print("v=",v+1,"y=",y)\n Y.append(str(y))\n\n# print("ADj",Adj)\n\n# print("G",G)\n\nprint(" ".join(Y))\n\n\n', '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,y=find(x),find(y)\n if x!=y:\n if x>y:\n x,y=y,x\n par[x]+=par[y]\n par[y]=x\n \ndef same(x,y):\n return find(x)==find(y)\n \ndef size(x):\n return-par[find(x)]\n \nN,M,K = map(int,input().split())\npar=[-1]*N\nB = [set() for _ in range(N)]\nFF = [0]*N\nfor _ in range(M):\n a,b = map(int,input().split())\n unite(a-1,b-1)\n FF[a-1] += 1\n FF[b-1] += 1\n# print(F)\nfor j in range(K):\n a,b = map(int,input().split())\n B[a-1].add(b-1)\n B[b-1].add(a-1)\n\nY = []\nfor i in range(N):\n y = size(i) - FF[i] -1\n for b in B[i]:\n if same(i,b):\n y += -1\n Y.append(str(y))\nprint(" ".join(Y))\n'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s270618228', 's534966031', 's718465051', 's730661298', 's989665277', 's036652216'] | [56872.0, 48872.0, 57664.0, 115292.0, 64176.0, 46588.0] | [2107.0, 884.0, 1033.0, 2107.0, 1115.0, 1176.0] | [1339, 1424, 1493, 1340, 1464, 755] |
p02762 | u906501980 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\ninput = sys.stdin.buffer.readline\n\ndef main():\n n, m, k = map(int, input().split())\n parent_f = list(range(n+1))\n rank_f = [0]*(n+1)\n parent_b = list(range(n+1))\n rank_b = [0]*(n+1)\n group_f = [set() for _ in range(n+1)]\n group_b = [set() for _ in range(n+1)]\n group_index_f = [None]*(n+1)\n group_index_b = [None]*(n+1)\n friends = [set() for i in range(n+1)]\n blocks = [set() for i in range(n+1)]\n for _ in range(m):\n a, b = map(int, input().split())\n friends[a] |= {b}\n friends[b] |= {a}\n unite(a, b, parent_f, rank_f)\n for _ in range(k):\n c, d = map(int, input().split())\n blocks[c] |= {d}\n blocks[d] |= {c}\n unite(c, d, parent_b, rank_b)\n for i in range(1, n+1):\n rf = root(i, parent_f)\n rb = root(i, parent_b)\n group_f[rf] |= {i}\n group_b[rb] |= {i}\n group_index_f[i] = rf\n group_index_b[i] = rb\n for i in range(1, n+1):\n print(len(group_f[group_index_f[i]]-friends[i]-blocks[i]-{i}))\n \n \n\ndef root(x, parent):\n if parent[x] == x:\n return x\n parent[x] = root(parent[x], parent)\n return parent[x]\n\ndef unite(x, y, parent, rank):\n x = root(x, parent)\n y = root(y, parent)\n if x != y:\n if rank[x] > rank[y]:\n parent[y] = x\n elif rank[x] < rank[y]:\n parent[x] = y\n else:\n parent[y] = x\n rank[x] += 1\n\nif __name__ == "__main__":\n main()', 'def main():\n n, m, k = map(int, input().split())\n fb = [0]*(n+1)\n uf = UnionFind(n)\n for i in range(m):\n a, b = map(int, input().split())\n fb[a] += 1\n fb[b] += 1\n uf.unite(a, b)\n for i in range(k):\n c, d = map(int, input().split())\n \n if uf.same(c, d):\n fb[c] += 1\n fb[d] += 1\n ans = [uf.size(i)-1-fb[i] for i in range(1, n+1)]\n print(" ".join(list(map(str, ans))))\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\n\nif __name__ == "__main__":\n main()'] | ['Time Limit Exceeded', 'Accepted'] | ['s698453748', 's556443541'] | [139788.0, 15624.0] | [2112.0, 1017.0] | [1495, 1254] |
p02762 | u915066452 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['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,k=map(int, input().split())\nfriend=[[] for i in range(n+1)]\nblock_count=[0]*(n+1)\nuf=UnionFind(n+1)\nfor i in range(1,n+1):\n a,b=map(int, input().split())\n friend[a].append(b)\n uf.union(a,b)\n\nfor i in range(1,k+1):\n a,b=map(int, input().split())\n if uf.sama(a,b)==True:\n block_count[i]+=1\n\nanswer=[0]*(n)\nfor i in range(1,n+1):\n answer[i-1]==uf.size(i)-len(friend[i])-block_count[i]-1\n\nprint(" ".join(map(str, answer)))', '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,k=map(int, input().split())\nfriend=[[] for i in range(n+1)]\nblock_count=[0]*(n+1)\nuf=UnionFind(n+1)\nfor i in range(1,n+1):\n a,b=map(int, input().split())\n friend[a].append(b)\n uf.union(a,b)\n\nfor i in range(1,k+1):\n a,b=map(int, input().split())\n if uf.sama(a,b)==True:\n block_count[i]+=1\n\nanswer=[0]*(n+1)\nfor i in range(1,n+1):\n answer[i]==uf.size(i)-len(friend[i])-block_count[i]-1\n\nprint(" ".join(map(str, answer)))', "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,k=map(int, input().split())\nfriend=[[] for i in range(n+1)]\nblock_count=[0]*(n+1)\nuf=UnionFind(n+1)\nfor i in range(1,n+1):\n a,b=map(int, input().split())\n friend[a].append(b)\n uf.union(a,b)\n\nfor i in range(1,k+1):\n a,b=map(int, input().split())\n if uf.sama(a,b)==True:\n block_count[i]+=1\n\nanswer=[0]*(n)\nfor i in range(1,n+1):\n answer[i-1]==uf.size(i)-len(friend[i])-block_count[i]-1\n\nprint(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 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,k=map(int, input().split())\nfriend=[[] for i in range(n+1)]\nblock_count=[0]*(n+1)\nuf=UnionFind(n+1)\nfor i in range(1,m+1):\n a,b=map(int, input().split())\n friend[a].append(b)\n friend[b].append(a)\n uf.union(a,b)\n\nfor i in range(1,k+1):\n a,b=map(int, input().split())\n if uf.same(a,b)==True:\n block_count[a]+=1\n block_count[b] += 1\n\nanswer=[0]*(n)\nfor i in range(1,n+1):\n answer[i-1]=uf.size(i)-len(friend[i])-block_count[i]-1\n \n\nprint(" ".join(map(str,answer)))\n#print(friend)\n\n#print(block_count)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s204352644', 's602903535', 's964964441', 's754128614'] | [19248.0, 19248.0, 19248.0, 34544.0] | [526.0, 539.0, 551.0, 1158.0] | [1594, 1594, 1575, 1714] |
p02762 | u922965680 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["import sys\nfrom collections import defaultdict, Counter\n\n\nclass UnionFind(object):\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\ndef main():\n n, m, k = list(map(int, sys.stdin.readline().strip().split()))\n\n friends = defaultdict(set)\n blocks = defaultdict(set)\n\n for i in range(m):\n a, b = list(map(int, sys.stdin.readline().strip().split()))\n a -= 1\n b -= 1\n friends[a].add(b)\n friends[b].add(a)\n\n for i in range(k):\n c, d = list(map(int, sys.stdin.readline().strip().split()))\n c -= 1\n d -= 1\n blocks[c].add(d)\n blocks[d].add(c)\n\n uf = UnionFind(n)\n\n for f_key in friends:\n for child in friends[f_key]:\n # child_cur_group = parents[child]\n uf.union(f_key, child)\n\n \n \n \n # group_num_set[group].add(i)\n #\n # ans = [0] * n\n \n \n # friend_cand = group_num_set[group]\n # true_friend_cand = friend_cand.difference(blocks[i]).difference(friends[i])\n # ans[i] = len(true_friend_cand) - 1\n #\n # return ans\n return [0]\n\n\nresult = main()\nprint(' '.join([str(num) for num in result]))\n", "import sys\nfrom collections import defaultdict, Counter\n\n\nclass UnionFind(object):\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\ndef main():\n n, m, k = list(map(int, sys.stdin.readline().strip().split()))\n\n friends = defaultdict(set)\n blocks = defaultdict(set)\n\n for i in range(m):\n a, b = list(map(int, sys.stdin.readline().strip().split()))\n a -= 1\n b -= 1\n friends[a].add(b)\n friends[b].add(a)\n\n for i in range(k):\n c, d = list(map(int, sys.stdin.readline().strip().split()))\n c -= 1\n d -= 1\n blocks[c].add(d)\n blocks[d].add(c)\n\n uf = UnionFind(n)\n\n for f_key in friends:\n for child in friends[f_key]:\n # child_cur_group = parents[child]\n uf.union(f_key, child)\n\n group_num_set = defaultdict(set)\n for i in range(n):\n group = uf.find(i)\n group_num_set[group].add(i)\n #\n # ans = [0] * n\n \n \n # friend_cand = group_num_set[group]\n # true_friend_cand = friend_cand.difference(blocks[i]).difference(friends[i])\n # ans[i] = len(true_friend_cand) - 1\n #\n # return ans\n return [0]\n\n\nresult = main()\nprint(' '.join([str(num) for num in result]))\n", "import sys\nfrom collections import defaultdict, Counter\n\n\nclass UnionFind(object):\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\ndef main():\n n, m, k = list(map(int, sys.stdin.readline().strip().split()))\n\n friends = defaultdict(set)\n blocks = defaultdict(set)\n\n for i in range(m):\n a, b = list(map(int, sys.stdin.readline().strip().split()))\n a -= 1\n b -= 1\n friends[a].add(b)\n friends[b].add(a)\n\n for i in range(k):\n c, d = list(map(int, sys.stdin.readline().strip().split()))\n c -= 1\n d -= 1\n blocks[c].add(d)\n blocks[d].add(c)\n\n uf = UnionFind(n)\n\n for f_key in friends:\n for child in friends[f_key]:\n # child_cur_group = parents[child]\n uf.union(f_key, child)\n\n \n \n \n # group_num_set[group].add(i)\n\n ans = [0] * n\n for i in range(n):\n group = uf.find(i)\n size = uf.size(i) - 1\n size -= len(friends[i])\n for block in blocks[i]:\n block_group = uf.find(block)\n if block_group == group:\n size -= 1\n ans[i] = size\n\n\n # friend_cand = group_num_set[group]\n\n # true_friend_cand = friend_cand.difference(blocks[i]).difference(friends[i])\n # ans[i] = len(true_friend_cand) - 1\n\n return ans\n\n\nresult = main()\nprint(' '.join([str(num) for num in result]))\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s145424922', 's327274764', 's703372812'] | [73900.0, 83120.0, 88824.0] | [1048.0, 1060.0, 1340.0] | [1752, 1744, 2009] |
p02762 | u930705402 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["N,M,K=map(int,input().split())\npar=[i for i in range(N+1)]\nsiz=[1 for i in range(N+1)]\nfre=[0 for i in range(N+1)]\nblo=[0 for i in range(N+1)]\nrank=[0 for i in range(N+1)]\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\n\ndef union(a,b):\n a=find(a)\n b=find(b)\n if(a==b):\n return 0\n else:\n par[a]=b\n siz[b]+=siz[a]\n\ndef size(a):\n return siz[find(a)]\n\ndef same(a,b):\n return find(a)==find(b)\n\nfor i in range(M):\n A,B=map(int,input().split())\n union(A,B)\n fre[A]+=1\n fre[B]+=1\nfor i in range(K):\n C,D=map(int,input().split())\n if(same(C,D)):\n blo[C]+=1\n blo[D]+=1\n\nfor i in range(1,N+1):\n print(size(i)-fre[i]-blo[i]-1,end=' ')", "N,M,K=map(int,input().split())\npar=[i for i in range(N+10)]\nsiz=[1 for i in range(N+10)]\nfre=[0 for i in range(N+10)]\nblo=[0 for i in range(N+10)]\nrank=[0 for i in range(N+10)]\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\n\ndef union(a,b):\n a=find(a)\n b=find(b)\n if(a==b):\n return 0\n else:\n par[a]=b\n siz[b]+=siz[a]\n\ndef size(a):\n return siz[find(a)]\n\ndef same(a,b):\n return find(a)==find(b)\n\nfor i in range(M):\n A,B=map(int,input().split())\n union(A,B)\n fre[A]+=1\n fre[B]+=1\nfor i in range(K):\n C,D=map(int,input().split())\n if(same(C,D)):\n blo[C]+=1\n blo[D]+=1\n\nfor i in range(1,N+1):\n print(size(i)-fre[i]-blo[i]-1,end=' ')", 'N,M,K=map(int,input().split())\npar=[i for i in range(N)]\nsiz=[1 for _ in range(N)]\nrank=[0 for _ 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 union(a,b):\n a=find(a)\n b=find(b)\n if(a==b):\n return 0\n else:\n if rank[a]>rank[b]:\n par[b]=a\n siz[a]+=siz[b]\n else:\n par[a]=b\n siz[b]+=siz[a]\n if rank[a]==rank[b]:\n rank[b]+=1\n \n\ndef size(a):\n return siz[find(a)]\n\ndef same(a,b):\n return find(a)==find(b)\n\nans=[0 for i in range(N)]\nfor _ in range(M):\n A,B=map(int,input().split())\n A,B=A-1,B-1\n union(A,B)\n ans[A]-=1\n ans[B]-=1\nfor i in range(N):\n ans[i]+=size(i)-1\nfor _ in range(K):\n C,D=map(int,input().split())\n C,D=C-1,D-1\n if(same(C,D)):\n ans[C]-=1\n ans[D]-=1\n \nprint(*ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s744262137', 's768102178', 's885430897'] | [11088.0, 11072.0, 11816.0] | [1117.0, 1150.0, 1057.0] | [776, 781, 921] |
p02762 | u934529721 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["N, M, K = map(int, input().split())\nF = [[] for _ in range(N)]\nB = [[] for _ in range(N)]\n\nfor _ in range(M):\n a, b = map(int, input().split())\n a, b = a - 1, b - 1\n F[a].append(b)\n F[b].append(a)\n\nprint(F)\n\nfor _ in range(K):\n c, d = map(int, input().split())\n c, d = c - 1, d - 1\n B[c].append(d)\n B[d].append(c)\n\n\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n)]\n \n self.rank = [0] * n\n \n self.size = [1] * n\n\n \n def find(self, x):\n \n if self.par[x] == x:\n return x\n \n else:\n \n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\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.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n \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 \n def all_find(self):\n for n in range(len(self.par)):\n self.find(n)\n\n\nUF = UnionFind(N)\nfor iam in range(N):\n for friend in F[iam]: \n UF.union(iam, friend) \n\nans = [UF.size[UF.find(iam)] - 1 for iam in range(N)] \n\nfor iam in range(N):\n ans[iam] -= len(F[iam]) \n\nfor iam in range(N):\n for block in B[iam]:\n if UF.same(iam, block): \n ans[iam] -= 1\n\nprint(*ans, sep=' ')\n", "N, M, K = map(int, input().split())\nF = [[] for _ in range(N)]\nB = [[] for _ in range(N)]\n\nfor _ in range(M):\n a, b = map(int, input().split())\n a, b = a - 1, b - 1\n F[a].append(b)\n F[b].append(a)\n\nfor _ in range(K):\n c, d = map(int, input().split())\n c, d = c - 1, d - 1\n B[c].append(d)\n B[d].append(c)\n\n\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n)]\n \n self.rank = [0] * n\n \n self.size = [1] * n\n\n \n def find(self, x):\n \n if self.par[x] == x:\n return x\n \n else:\n \n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\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.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n \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\nUF = UnionFind(N)\nfor iam in range(N):\n for friend in F[iam]: \n UF.union(iam, friend) \n\nans = [UF.size[UF.find(iam)] - 1 for iam in range(N)] \n\nfor iam in range(N):\n ans[iam] -= len(F[iam]) \n\nfor iam in range(N):\n for block in B[iam]:\n if UF.same(iam, block): \n ans[iam] -= 1\n\nprint(*ans, sep=' ')\n"] | ['Wrong Answer', 'Accepted'] | ['s839931468', 's547269839'] | [49980.0, 48364.0] | [1731.0, 1618.0] | [2359, 2205] |
p02762 | u944643608 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['N, M, K = map(int, input().split())\nans = [0] * N\nfri = [[] for i in range(N)]\nblo = [[] for i in range(N)]\nfor i in range(M):\n a,b = map(int, input().split())\n fri[a-1].append(b-1)\n fri[b-1].append(a-1)\nfor i in range(K):\n c,d = map(int, input().split())\n blo[c-1].append(d-1)\n blo[d-1].append(c-1)\nzumi = []\nbefore = 0\nfor i in range(N):\n if i not in zumi:\n zumi.append(i)\n que = fri[i]\n after = before + len(fri[i])\n while que:\n tmp = que.pop()\n zumi.append(tmp)\n for x in fri[tmp]:\n if (x not in zumi) and (x not in que):\n que.append(x)\n after += 1\n for i in range(before, after+1):\n ans[zumi[i]] = after - before - len(fri[i])\n before = after + 1\n else:\n continue\nprint(*ans)\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 if x == y :\n 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 \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(roots())\n\ndef main(): \n n, m, k = map(int, input().split())\n uf = UnionFind(n)\n ans = [0] * n\n deg = [0] * n\n for _ in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n uf.union(a,b)\n deg[a] += 1\n deg[b] += 1\n for _ in range(k):\n c,d = map(int, input().split())\n c -= 1\n d -= 1\n if uf.same(c,d):\n deg[c] += 1\n deg[d] += 1\n for i in range(n):\n ans[i] = uf.size(i) - deg[i] - 1\n print(\' \'.join(map(str,ans)))\n\nif __name__ == "__main__":\n main()\n \n \n \n \n \n \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 if x == y :\n 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 \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\ndef main(): \n n, m, k = map(int, input().split())\n uf = UnionFind(n)\n ans = [0] * n\n deg = [0] * n\n for _ in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n uf.union(a,b)\n deg[a] += 1\n deg[b] += 1\n for _ in range(k):\n c,d = map(int, input().split())\n c -= 1\n d -= 1\n if uf.same(c,d):\n deg[c] += 1\n deg[d] += 1\n for i in range(n):\n ans[i] = uf.size(i) - deg[i] - 1\n print(' '.join(map(str,ans)))\n\nif __name__ == '__main__':\n main()", 'N, M, K = map(int, input().split())\nans = [0] * N\nfri = [[] for i in range(N)]\nblo = [[] for i in range(N)]\nfor i in range(M):\n a,b = map(int, input().split())\n fri[a-1].append(b-1)\n fri[b-1].append(a-1)\nfor i in range(K):\n c,d = map(int, input().split())\n blo[c-1].append(d-1)\n blo[d-1].append(c-1)\nzumi = []\nbefore = 0\nfor i in range(N):\n if i not in zumi:\n zumi.append(i)\n que = fri[i]\n after = before + len(fri[i])\n while que:\n tmp = que.pop()\n zumi.append(tmp)\n for x in fri[tmp]:\n if (x not in zumi) and (x not in que):\n que.append(x)\n after += 1\n for i in range(before, after+1):\n ans[zumi[i]] = after - before - len(fri[i])\n for j in range(before, after):\n for k in range(j+1, after + 1):\n if zumi[k] in blo[zumi[j]]:\n ans[zumi[k]] -= 1\n ans[zumi[j]] -= 1\n before = after + 1\n else:\n continue\nprint(*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 if x == y :\n 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 \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\ndef main(): \n n, m, k = map(int, input().split())\n uf = UnionFind(n)\n ans = [0] * n\n deg = [0] * n\n for _ in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n uf.union(a,b)\n deg[a] += 1\n deg[b] += 1\n for _ in range(k):\n c,d = map(int, input().split())\n c -= 1\n d -= 1\n if uf.same(c,d):\n deg[c] += 1\n deg[d] += 1\n for i in range(n):\n ans[i] = uf.size(i) - deg[i] - 1\n print(' '.join(map(str,ans)))\n\nmain()", 'N, M, K = map(int, input().split())\nans = [0] * N\nfri = [[] for i in range(N)]\nblo = [[] for i in range(N)]\nkouho =[[] for i in range(N)]\nfor i in range(M):\n a,b = map(int, input().split())\n fri[a-1].append(b-1)\n fri[b-1].append(a-1)\nfor i in range(K):\n c,d = map(int, input().split())\n blo[c-1].append(d-1)\n blo[d-1].append(c-1)\nfor i in range(N):\n zumi = [i]\n stack = fri[i]\n while stack:\n tmp = stack.pop()\n zumi.append(tmp)\n for k in fri[tmp]:\n if k not in zumi and k not in stack:\n stack.append(k)\n if k not in blo[i] and k not in fri[i]:\n kouho[i] += 1\nprint(*kouho)\n ', 'import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nsys.setrecursionlimit(10**8)\nINF = float(\'inf\')\nMOD = 10**9+7\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 \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 \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\ndef main(): \n n, m, k = map(int, input().split())\n uf = UnionFind(n)\n ans = [0] * n\n deg = [0] * n\n for _ in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n uf.union(a,b)\n deg[a] += 1\n deg[b] += 1\n for _ in range(k):\n c,d = map(int, input().split())\n c -= 1\n d -= 1\n if uf.same(c,d):\n deg[c] += 1\n deg[d] += 1\n for i in range(n):\n ans[i] = uf.size(i) - deg[i] - 1\n print(\' \'.join(map(str,ans)))\n\nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s074947277', 's476937339', 's692642120', 's827985054', 's947828068', 's954130938', 's119607067'] | [40496.0, 2940.0, 2940.0, 40516.0, 2940.0, 47592.0, 18760.0] | [2106.0, 17.0, 17.0, 2106.0, 17.0, 2106.0, 1054.0] | [755, 1371, 1089, 919, 1060, 621, 1863] |
p02762 | u945228737 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["import bisect\nfrom decorator import stop_watch\n\n\n@stop_watch\ndef solve(N, M, K, ABs, CDs):\n friend_map = [[] for _ in range(N + 1)]\n for a, b in ABs:\n friend_map[a].append(b)\n friend_map[b].append(a)\n\n block_map = [[] for _ in range(N + 1)]\n for c, d in CDs:\n block_map[c].append(d)\n block_map[d].append(c)\n\n # print('friend_map')\n \n # print(friend_map[i])\n #\n # print('block_map')\n \n # print(block_map[i])\n\n def dfs(group_num, members, now_n):\n belongs[now_n] = group_num\n members.append(now_n)\n for f in friend_map[now_n]:\n if belongs[f] == -1:\n members = dfs(group_num, members, f)\n return members\n\n friend_groups = []\n belongs = [-1] * (N + 1)\n for i in range(1, N + 1):\n if belongs[i] == -1:\n m = dfs(len(friend_groups), [], i)\n m.sort()\n friend_groups.append(m)\n\n # print('friend_groups')\n \n # print(friend_groups[i])\n\n # print('belongs')\n # print(belongs)\n ans = ''\n for n in range(1, N + 1):\n block = 0\n group = friend_groups[belongs[n]]\n for b in block_map[n]:\n \n # print(group)\n # print(n, b)\n # input()\n x = bisect.bisect_left(group, b)\n # if x < len(group) and b == group[x]:\n # block += 1\n if belongs[n] == belongs[b]:\n block += 1\n \n ans += ' ' + str(len(group) - len(friend_map[n]) - block - 1)\n print(ans[1:])\n\n\nif __name__ == '__main__':\n # # handmade test\n # N, M, K = 2 * 10 ** 5, 10 ** 5, 10 ** 5\n \n \n # while True:\n # import random\n # N, M, K = 20, 10, 10\n # ABs = []\n # while True:\n # if len(ABs) == M:\n # break\n # a = random.randint(1, N - 1)\n # b = random.randint(a + 1, N)\n # if not [a, b] in ABs:\n # ABs.append([a, b])\n # CDs = []\n # while True:\n # if len(CDs) == K:\n # break\n # c = random.randint(1, N - 1)\n # d = random.randint(c + 1, N)\n # if not [c, d] in ABs and not [c, d] in CDs:\n # CDs.append([c, d])\n \n # print(ABs)\n # print(CDs)\n # solve(N, M, K, ABs, CDs)\n\n N, M, K = map(int, input().split())\n ABs = [[int(i) for i in input().split()] for _ in range(M)]\n CDs = [[int(i) for i in input().split()] for _ in range(K)]\n solve(N, M, K, ABs, CDs)\n", "import sys\nsys.setrecursionlimit(10 ** 6)\n# from decorator import stop_watch\n#\n#\n# @stop_watch\ndef solve(N, M, K, ABs, CDs):\n friend_map = [[] for _ in range(N + 1)]\n for a, b in ABs:\n friend_map[a].append(b)\n friend_map[b].append(a)\n\n block_map = [[] for _ in range(N + 1)]\n for c, d in CDs:\n block_map[c].append(d)\n block_map[d].append(c)\n\n def dfs(group_num, members, now_n):\n belongs[now_n] = group_num\n members.append(now_n)\n for f in friend_map[now_n]:\n if belongs[f] == -1:\n members = dfs(group_num, members, f)\n return members\n\n friend_groups = []\n belongs = [-1] * (N + 1)\n for i in range(1, N + 1):\n if belongs[i] == -1:\n m = dfs(len(friend_groups), [], i)\n m.sort()\n friend_groups.append(m)\n\n ans = ''\n for n in range(1, N + 1):\n block = 0\n group = friend_groups[belongs[n]]\n for b in block_map[n]:\n if belongs[n] == belongs[b]:\n block += 1\n ans += ' ' + str(len(group) - len(friend_map[n]) - block - 1)\n print(ans[1:])\n\n\nif __name__ == '__main__':\n # # handmade test\n # N, M, K = 2 * 10 ** 5, 10 ** 5, 10 ** 5\n \n \n \n # # handmade random\n # import random\n # N, M, K = 20, 10, 10\n # ABs = []\n # while True:\n # if len(ABs) == M:\n # break\n # a = random.randint(1, N - 1)\n # b = random.randint(a + 1, N)\n # if not [a, b] in ABs:\n # ABs.append([a, b])\n # CDs = []\n # while True:\n # if len(CDs) == K:\n # break\n # c = random.randint(1, N - 1)\n # d = random.randint(c + 1, N)\n # if not [c, d] in ABs and not [c, d] in CDs:\n # CDs.append([c, d])\n \n # print(ABs)\n # print(CDs)\n\n N, M, K = map(int, input().split())\n ABs = [[int(i) for i in input().split()] for _ in range(M)]\n CDs = [[int(i) for i in input().split()] for _ in range(K)]\n solve(N, M, K, ABs, CDs)\n"] | ['Runtime Error', 'Accepted'] | ['s369835455', 's295171370'] | [5092.0, 91724.0] | [49.0, 1279.0] | [2915, 2144] |
p02762 | u946996108 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['from collections import defaultdict\nimport time\n\nN, M, K = [int(i) for i in input().split(" ")]\n\nfriend_dict = defaultdict(lambda:[])\nblock_dict = defaultdict(lambda:[])\nroot = {}\nnumroot = {}\nnext = 0\n\nfor i in range(M):\n s = input()\n a, b = s.split(" ")\n a = int(a) - 1\n b = int(b) - 1\n\n ab = a\n bb = b\n\n a = min(ab, bb)\n b = max(ab, bb)\n #print((a, b))\n\n for x, y in ((a, b), (b, a)):\n friend_dict[x].append(y)\n\n if b in root:\n root[a] = b\n else:\n root[b] = a\n\n#print(root)\n\nunion = dict(zip(range(N), range(N)))\nunionnum = defaultdict(lambda:1)\nfor before, rootnum in root.items():\n while rootnum in root:\n rootnum = root[rootnum]\n union[before] = rootnum\n unionnum[rootnum] += 1\n\n#print(union)\n\n\ntime.sleep(1)\n\nresult = []\nfor i in range(N):\n ret = unionnum[union[i]] -1\n\n #print(f"un={ret}")\n\n for friend in friend_dict[i]:\n if union[friend] == union[i]:\n ret -=1\n for block in block_dict[i]:\n if union[block] == union[i]:\n ret -=1\n result.append(ret)\n\n\n#print(union)\nprint(" ".join([str(i) for i in result]))', '\nN, M, K = [int(i) for i in input().split(" ")]\n\nfriend_list = []\nblock_list = []\nroot = {}\nnext = 0\n\nfor i in range(M):\n s = input()\n a, b = s.split(" ")\n a = int(a) - 1\n b = int(b) - 1\n\n ab = a\n bb = b\n\n a = min(ab, bb)\n b = max(ab, bb)\n print((a, b))\n\n friend_list.append((a, b))\n if b in root:\n root[a] = root[b]\n else:\n root[b] = a\n\nunion = []\nfor i in range(N):\n c_root = i\n while True:\n if c_root in root:\n c_root = root[c_root]\n else:\n union.append(c_root)\n break\n\n\nfor i in range(K):\n s = input()\n a, b = s.split(" ")\n a = int(a) - 1\n b = int(b) - 1\n block_list.append((a, b))\n\n\nresult = []\nfor i in range(N):\n ret = 0\n if union[i] is None:\n result.append(0)\n continue\n for j in range(N):\n if i == j:\n continue\n if union[i] != union[j]:\n continue\n if (i, j) in block_list:\n continue\n if (j, i) in block_list:\n continue\n if (i, j) in friend_list:\n continue\n if (j, i) in friend_list:\n continue\n ret += 1\n result.append(ret)\n\n#print(union)\nprint(" ".join([str(i) for i in result]))', 'from collections import defaultdict\nimport time\n\nN, M, K = [int(i) for i in input().split(" ")]\n\nfriend_dict = defaultdict(lambda:[])\nblock_dict = defaultdict(lambda:[])\nroot = {}\nnumroot = {}\nnext = 0\n\nfor i in range(M):\n s = input()\n a, b = s.split(" ")\n a = int(a) - 1\n b = int(b) - 1\n\n ab = a\n bb = b\n\n a = min(ab, bb)\n b = max(ab, bb)\n #print((a, b))\n\n for x, y in ((a, b), (b, a)):\n friend_dict[x].append(y)\n\n if b in root:\n root[a] = b\n else:\n root[b] = a\n\n#print(root)\n\nunion = dict(zip(range(N), range(N)))\nunionnum = defaultdict(lambda:1)\nfor before, rootnum in root.items():\n while rootnum in root:\n rootnum = root[rootnum]\n union[before] = rootnum\n unionnum[rootnum] += 1\n\n#print(union)\n\n\ntime.sleep(1)\n\nresult = []\nfor i in range(N):\n ret = unionnum[union[i]] -1\n\n #print(f"un={ret}")\n\n for friend in friend_dict[i]:\n if union[friend] == union[i]:\n ret -=1\n for block in block_dict[i]:\n if union[block] == union[i]:\n ret -=1\n result.append(ret)\n\n\n#print(union)\nprint(" ".join([str(i) for i in result]))', '\nN, M, K = [int(i) for i in input().split(" ")]\n\nfriend_list = []\nblock_list = []\nroot = {}\nnext = 0\n\nfor i in range(M):\n s = input()\n a, b = s.split(" ")\n a = int(a) - 1\n b = int(b) - 1\n\n ab = a\n bb = b\n\n a = min(ab, bb)\n b = max(ab, bb)\n print((a, b))\n\n friend_list.append((a, b))\n if b in root:\n root[a] = root[b]\n root[b] = a\n\nprint(root)\n\nunion = []\nfor i in range(N):\n c_root = i\n while True:\n if c_root in root:\n c_root = root[c_root]\n else:\n union.append(c_root)\n break\n\n\nfor i in range(K):\n s = input()\n a, b = s.split(" ")\n a = int(a) - 1\n b = int(b) - 1\n block_list.append((a, b))\n\n\nresult = []\nfor i in range(N):\n ret = 0\n if union[i] is None:\n result.append(0)\n continue\n for j in range(N):\n if i == j:\n continue\n if union[i] != union[j]:\n continue\n if (i, j) in block_list:\n continue\n if (j, i) in block_list:\n continue\n if (i, j) in friend_list:\n continue\n if (j, i) in friend_list:\n continue\n ret += 1\n result.append(ret)\n\nprint(root)\nprint(union)\nprint(" ".join([str(i) for i in result]))', '\nN, M, K = [int(i) for i in input().split(" ")]\n\nfriend_list = []\nblock_list = []\nroot = {}\nnext = 0\n\nfor i in range(M):\n s = input()\n a, b = s.split(" ")\n a = int(a) - 1\n b = int(b) - 1\n\n ab = a\n bb = b\n\n a = min(ab, bb)\n b = max(ab, bb)\n print((a, b))\n\n friend_list.append((a, b))\n if b in root:\n root[a] = root[b]\n else:\n root[b] = a\n\nunion = []\nfor i in range(N):\n c_root = i\n while True:\n if c_root in root:\n c_root = root[c_root]\n else:\n union.append(c_root)\n break\n\n\nfor i in range(K):\n s = input()\n a, b = s.split(" ")\n a = int(a) - 1\n b = int(b) - 1\n block_list.append((a, b))\n\n\nresult = []\nfor i in range(N):\n ret = 0\n if union[i] is None:\n result.append(0)\n continue\n for j in range(N):\n if i == j:\n continue\n if union[i] != union[j]:\n continue\n if (i, j) in block_list:\n continue\n if (j, i) in block_list:\n continue\n if (i, j) in friend_list:\n continue\n if (j, i) in friend_list:\n continue\n ret += 1\n result.append(ret)\n\n#print(union)\nprint(" ".join([str(i) for i in result]))', 'from collections import defaultdict\nimport sys\nimport time\n\nsys.setrecursionlimit(2000)\nN, M, K = [int(i) for i in input().split(" ")]\n\nt = time.time()\nclass UnionNode():\n def __init__(self, number):\n self.number = number\n self.volume = 1\n self.master = None\n\n @property\n def root(self):\n if self.master:\n self.master = self.master.root\n return self.master\n else:\n return self\n\n def unite(self, target):\n seroot = self.root\n taroot = target.root\n if seroot.number == taroot.number:\n pass\n else:\n #print(f"unite {target.rootnum}({target.root.volume}), {self.rootnum}({self.root.volume})")\n if seroot.volume > taroot.volume:\n seroot.volume += taroot.volume\n taroot.master = seroot\n else:\n taroot.volume += seroot.volume\n seroot.master = taroot\n\nnodes = [UnionNode(i) for i in range(N)]\n\noutlist = defaultdict(lambda :[])\n\nfor i in range(M):\n s = input()\n a, b = s.split(" ")\n a = int(a) - 1\n b = int(b) - 1\n nodes[a].unite(nodes[b])\n outlist[a].append(b)\n outlist[b].append(a)\n\nfor i in range(K):\n s = input()\n a, b = s.split(" ")\n a = int(a) - 1\n b = int(b) - 1\n outlist[a].append(b)\n outlist[b].append(a)\n\nresult = []\nfor i in range(N):\n rootnode = nodes[i].root\n ret = rootnode.volume - 1\n for out in outlist[i]:\n if nodes[out].root.number == rootnode.number:\n ret -=1\n result.append(ret)\n\n\n# print(result[i])\n\nprint(" ".join([str(i) for i in result]))\n\n#print(time.time() - t)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s174899689', 's394927359', 's674165464', 's763373891', 's979959030', 's444199357'] | [73564.0, 38284.0, 73564.0, 37008.0, 38288.0, 66624.0] | [2105.0, 2106.0, 2105.0, 2106.0, 2108.0, 1884.0] | [1155, 1247, 1155, 1257, 1247, 1683] |
p02762 | u959340534 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['class UnionFind():\n def __init__(self, n):\n self.n = n\n self.root = [-1]*n\n self.rank = [0]*n\n \n def find_root(self, e):\n if self.root[e] < 0:\n return e\n else:\n r = self.find_root(self.root[e])\n self.root[e] = r\n return r\n \n def combine(self, e1, e2):\n root1 = self.find_root(e1)\n root2 = self.find_root(e2)\n if root1 == root2:\n pass\n elif self.rank[root1] < self.rank[root2]:\n self.root[root1] += self.root[root2]\n self.root[root2] = root1\n self.rank[root1] = self.rank[root2] + 1\n elif self.rank[root2] < self.rank[root1]:\n self.root[root2] += self.root[root1]\n self.root[root1] = root2\n self.rank[root2] = self.rank[root1] + 1\n else:\n self.root[root2] += self.root[root1]\n self.root[root1] = root2\n self.rank[root2] += 1\n \n def in_the_same_group(self, e1, e2):\n r1 = self.find_root(e1)\n r2 = self.find_root(e2)\n if r1 == r2:\n return True\n return False\n \n\nNMK = input().split()\nN = int(NMK[0])\nM = int(NMK[1])\nK = int(NMK[2])\nuf = UnionFind(N)\nfrom collections import defaultdict\n\nfriend_list = [0]*n\nfor _ in range(M):\n AB = input().split()\n A = int(AB[0])-1\n B = int(AB[1])-1\n uf.combine(A,B)\n friend_list[A] += 1\n friend_list[B] += 1\n\nblock_list = [0]*n\nfor _ in range(K):\n CD = input().split()\n C = int(CD[0])-1\n D = int(CD[1])-1\n if uf.in_the_same_group(C, D):\n block_list[C] += 1\n block_list[D] += 1\n\ncnt = defaultdict(int)\nans = []\nfor i in range(N):\n cnt[i] = -uf.root[uf.find_root(i)] - 1 - friend_list[i] - block_list[i]\n ans.append(str(cnt[i]))\n\nprint(" ".join(ans))', 'from collections import defaultdict\n\nfriend_list = defaultdict(int)\nfor _ in range(M):\n AB = input().split()\n A = int(AB[0])-1\n B = int(AB[1])-1\n uf.combine(A,B)\n friend_list[A] += 1\n friend_list[B] += 1\n\nblock_list = defaultdict(int)\nfor _ in range(K):\n CD = input().split()\n C = int(CD[0])-1\n D = int(CD[1])-1\n if uf.in_the_same_group(C, D):\n block_list[C] += 1\n block_list[D] += 1\n\ncnt = defaultdict(int)\nans = []\nfor i in range(N):\n cnt[i] = -uf.root[uf.find_root(i)] - 1 - friend_list[i] - block_list[i]\n ans.append(str(cnt[i]))\n\nprint(" ".join(ans))', 'class UnionFind():\n def __init__(self, n):\n self.n = n\n self.root = [-1]*n\n self.rank = [0]*n\n \n def find_root(self, e):\n if self.root[e] < 0:\n return e\n else:\n r = self.find_root(self.root[e])\n self.root[e] = r\n return r\n \n def combine(self, e1, e2):\n root1 = self.find_root(e1)\n root2 = self.find_root(e2)\n if root1 == root2:\n pass\n elif self.rank[root1] < self.rank[root2]:\n self.root[root1] += self.root[root2]\n self.root[root2] = root1\n self.rank[root1] = self.rank[root2] + 1\n elif self.rank[root2] < self.rank[root1]:\n self.root[root2] += self.root[root1]\n self.root[root1] = root2\n self.rank[root2] = self.rank[root1] + 1\n else:\n self.root[root2] += self.root[root1]\n self.root[root1] = root2\n self.rank[root2] += 1\n \n def in_the_same_group(self, e1, e2):\n r1 = self.find_root(e1)\n r2 = self.find_root(e2)\n if r1 == r2:\n return True\n return False\n \n\nNMK = input().split()\nN = int(NMK[0])\nM = int(NMK[1])\nK = int(NMK[2])\nuf = UnionFind(N)\nfrom collections import defaultdict\nfriend_list = [0]*N\nfor _ in range(M):\n AB = input().split()\n A = int(AB[0])-1\n B = int(AB[1])-1\n uf.combine(A,B)\n friend_list[A] += 1\n friend_list[B] += 1\n\nblock_list = [0]*N\nfor _ in range(K):\n CD = input().split()\n C = int(CD[0])-1\n D = int(CD[1])-1\n if uf.in_the_same_group(C, D):\n block_list[C] += 1\n block_list[D] += 1\n\nblock_list*n\ncnt = defaultdict(int)\nans = []\nfor i in range(N):\n cnt[i] = -uf.root[uf.find_root(i)] - 1 - friend_list[i] - block_list[i]\n ans.append(str(cnt[i]))\n\nprint(" ".join(ans))', 'class UnionFind():\n def __init__(self,n):\n self.n=n\n self.root=[-1]*(n+1)\n self.rank=[0]*(n+1)\n def FindRoot(self,x):\n if self.root[x]<0:\n return x\n else:\n self.root[x]=self.FindRoot(self.root[x])\n return self.root[x]\n def Unite(self,x,y):\n x=self.FindRoot(x)\n y=self.FindRoot(y)\n if x==y:\n return\n else:\n if self.rank[x]>self.rank[y]:\n self.root[x]+=self.root[y]\n self.root[y]=x\n elif self.rank[x]<=self.rank[y]:\n self.root[y]+=self.root[x]\n self.root[x]=y\n if self.rank[x]==self.rank[y]:\n self.rank[y]+=1\n def isSameGroup(self,x,y):\n return self.FindRoot(x)==self.FindRoot(y)\n def Count(self,x):\n return -self.root[self.FindRoot(x)]\n \nn,m,k=map(int,input().split())\nt=UnionFind(n+1)\ncnt=[0]*(n+1) \nfor _ in range(m):\n a,b=map(int,input().split())\n cnt[a]+=1 \n cnt[b]+=1\n t.Unite(a,b)\nfor _ in range(k):\n a,b=map(int,input().split())\n if t.isSameGroup(a,b)==True:\n cnt[a]+=1 \n cnt[b]+=1\nans=[0]*(n+1)\nfor i in range(1,n+1):\n ans[i]=(t.Count(i)-1)-cnt[i] \nprint(*ans[1:])\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s397733538', 's909899950', 's926060779', 's814146750'] | [4852.0, 3316.0, 12960.0, 11828.0] | [26.0, 21.0, 1090.0, 1147.0] | [1643, 573, 1655, 1608] |
p02762 | u995062424 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["from collections import Counter\n\nclass Unionfind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * (n+1)\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, K = map(int, input().split())\nuf = Unionfind(N)\nf = [0 for _ in range(N)]\nn = [0 for _ in range(N)]\n\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n uf.union(a, b)\n \n f[a] += 1\n f[b] += 1\n \nfor _ in range(K):\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n if(uf.same(c, d)):\n n[c] += 1\n n[d] += 1\n \nans = []\nfor i in range(N):\n ans.append(uf.size(i)-f[i]-n[i]-1)\n \nprint(*ans)v", "class Unionfind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * (n+1)\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, K = map(int, input().split())\nuf = Unionfind(N)\nf = [0 for _ in range(N)]\nn = [0 for _ in range(N)]\n\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n uf.union(a, b)\n \n f[a] += 1\n f[b] += 1\n \nfor _ in range(K):\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n if(uf.same(c, d)):\n n[c] += 1\n n[d] += 1\n \nans = []\nfor i in range(N):\n ans.append(uf.size(i)-f[i]-n[i]-1)\n \nprint(*ans)"] | ['Runtime Error', 'Accepted'] | ['s830536874', 's494761818'] | [9200.0, 19024.0] | [26.0, 693.0] | [1726, 1692] |
p02762 | u996731299 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['class Unionfind():\n\n def __init__(self,n):\n self.n=n\n self.parents=[-1]*n\n\n def find(self,a):\n if self.parents[a]<0:\n return a\n else:\n self.parents[a]=self.find(self.parents[a])\n return self.parents[a]\n\n\n def union(self,x,y):\n x=self.find(x)\n y=self.find(y)\n if x==y:\n return\n else:\n if self.parents[x]<self.parents[y]:\n x,y=y,x\n self.parents[y]+=self.parents[x]\n self.parents[x]=y\n\n def size(self,x):\n return -self.parents[self.find(x)]\n\n def same(self,x,y):\n if self.find(x)==self.find(y):\n return True\n else:\n return False\n \nN,M,K=map(int,input().split())\nuf=Unionfind(N)\nfriend=[list(map(int,input().split())) for i in range(M)]\nblock=[list(map(int,input().split())) for i in range(K)]\nff=[[] for i in range(N)]\nbb=[[] for i in range(N)]\nans=[]\nfor i in range(M):\n uf.union(friend[i][0]-1,friend[i][1]-1)\n ff[friend[i][0]-1].append(friend[i][1]-1)\n ff[friend[i][1]-1].append(friend[i][0]-1)\nfor i in range(K):\n bb[block[i][0]-1].append(block[i][1]-1)\n bb[block[i][1]-1].append(block[i][0]-1)\nfor i in range(N):\n ans.append(uf.size(i)-1-(len(ff[i])))\n for j in bb[i]:\n if uf.same(j,i)==True:\n ans[i]-=1\nprint(ans)\n\n', 'class Unionfind():\n\n def __init__(self,n):\n self.n=n\n self.parents=[-1]*n\n\n def find(self,a):\n if self.parents[a]<0:\n return a\n else:\n self.parents[a]=self.find(self.parents[a])\n return self.parents[a]\n\n\n def union(self,x,y):\n x=self.find(x)\n y=self.find(y)\n if x==y:\n return\n else:\n if self.parents[x]<self.parents[y]:\n x,y=y,x\n self.parents[y]+=self.parents[x]\n self.parents[x]=y\n\n def size(self,x):\n return -self.parents[self.find(x)]\n\n def same(self,x,y):\n if self.find(x)==self.find(y):\n return True\n else:\n return False\n \nN,M,K=map(int,input().split())\nuf=Unionfind(N)\nfriend=[list(map(int,input().split())) for i in range(M)]\nblock=[list(map(int,input().split())) for i in range(K)]\nff=[[] for i in range(N)]\nbb=[[] for i in range(N)]\nans=[]\nfor i in range(M):\n uf.union(friend[i][0]-1,friend[i][1]-1)\n ff[friend[i][0]-1].append(friend[i][1]-1)\n ff[friend[i][1]-1].append(friend[i][0]-1)\nfor i in range(K):\n bb[block[i][0]-1].append(block[i][1]-1)\n bb[block[i][1]-1].append(block[i][0]-1)\nfor i in range(N):\n ans.append(uf.size(i)-1-(len(ff[i])))\n for j in bb[i]:\n if uf.same(j,i)==True:\n ans[i]-=1\nanswer=[str(ans[i]) for i in range(len(ans))]\nprint(" ".join(answer))'] | ['Wrong Answer', 'Accepted'] | ['s067029494', 's364656329'] | [86800.0, 92824.0] | [1657.0, 1664.0] | [1389, 1446] |
p02763 | u044220565 | 2,000 | 1,048,576 | You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: * Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) * Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | ['# coding: utf-8\nimport sys\n#from operator import itemgetter\nsysread = sys.stdin.readline\n#from heapq import heappop, heappush\nfrom collections import defaultdict\n#from itertools import combinations\nsys.setrecursionlimit(10**7)\n\ndef run():\n # import sys\n # A = list(map(int, sys.stdin.readline().split()))\n # all = sys.stdin.readlines()\n #N, *A = map(int, open(0))\n #N = int(input())\n ###\n def bin_search(A,low_val):\n high = len(A) -1\n low = 0\n current = high // 2\n while high-low >1:\n if A[current] >= low_val:\n high = current\n current = (low + current) //2\n else:\n low = current\n current = (current + high) // 2\n return A[high]\n\n N = int(sysread())A\n S = list(\'0\'+input())\n dic = defaultdict(lambda:[])\n for idx, s in enumerate(S[1:],1):\n dic[s].append(idx)\n\n Q = int(sysread())\n queries = []\n for _ in range(Q):\n queries.append(sysread().split())\n\n for q,i,c in queries:\n if q == \'1\':\n i = int(i)\n old = S[i]\n dic[old].remove(i)\n dic[c].append(i)\n dic[c] = sorted(dic[c])\n S[i] = c\n else:\n count = 0\n i,c = int(i), int(c)\n for key in dic.keys():\n tmp = dic[key]\n if bin_search(tmp, i) <= c:\n count += 1\n print(count)\n\nif __name__ == "__main__":\n run()', '# coding: utf-8\nimport sys\n#from operator import itemgetter\nsysread = sys.stdin.readline\n#from heapq import heappop, heappush\nfrom collections import defaultdict\n#from itertools import combinations\nsys.setrecursionlimit(10**7)\nimport math\nclass SegTree():\n \'\'\'\n input idx: 1-\n \'\'\'\n def __init__(self, n, init_val=0):\n self.n = n\n self.init_val = init_val\n self.n_leaf = 2 ** math.ceil(math.log2(n))\n self.bins = [init_val] * (self.n_leaf * 2)\n\n def val_append(self, A):\n \'\'\'\n :param A:\n :return:\n \'\'\'\n if len(A) != self.n:\n raise ValueError(\'The number of input should be same with n_leaf\')\n for i,a in enumerate(A):\n self.bins[self.n_leaf+i]=a\n self._calc()\n return None\n\n def _calc(self):\n \'\'\'\n Calculate all bins based on values of leaves\n \'\'\'\n i = self.n_leaf - 1\n while i > 0:\n self.bins[i] = self._criteria(self.bins[i*2], self.bins[i*2+1])\n i -= 1\n return None\n\n def _criteria(self, x, y):\n \'\'\'\n Define criteria between 2 nodes\n \'\'\'\n return x | y\n\n def eval_between(self, x, y):\n \n l, r = x + self.n_leaf - 1, y + self.n_leaf - 1\n ret = self._criteria(self.bins[l], self.bins[r])\n while l < r:\n if l % 2 == 1:\n ret = self._criteria(self.bins[l], ret)\n l += 1\n continue\n\n if r % 2 == 0:\n ret = self._criteria(self.bins[r], ret)\n r -= 1\n continue\n l = l//2\n r = r//2\n ret = self._criteria(self.bins[l], ret)\n ret = self._criteria(self.bins[r], ret)\n\n return ret\n\n def update(self, node, pro):\n \'\'\'\n Replacement of the value in a leaf\n \'\'\'\n current = node + self.n_leaf - 1\n self.bins[current] = pro\n current //= 2\n while current > 0:\n self.bins[current] = self._criteria(self.bins[current*2+1], self.bins[current*2])\n current //= 2\n return None\n\ndef run():\n N = int(input())\n S = list(input())\n Q = int(input())\n queries = [sysread().split() for _ in range(Q)]\n\n bins = [0] * N# a: ord(\'a\') - 97\n for i,s in enumerate(S):\n id = ord(s) - 97\n bins[i] = 1<<id\n\n segtree = SegTree(N)\n segtree.val_append(bins)\n\n for type, i,c in queries:\n if type == \'1\':\n c = 1 << (ord(c) - 97)\n segtree.update(int(i), c)\n else:\n i,c = int(i), int(c)\n tmp = segtree.eval_between(i,c)\n print(bin(tmp).count(\'1\'))\n\nif __name__ == "__main__":\n run()'] | ['Runtime Error', 'Accepted'] | ['s395154967', 's589687506'] | [2940.0, 57684.0] | [17.0, 886.0] | [1506, 2781] |
p02763 | u093861603 | 2,000 | 1,048,576 | You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: * Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) * Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | ['import bisect\nN=input()\nS=list(input())\nalphabet=[[] for _ in range(26)]\nfor i,s in enumerate(S):\n alphabet[ord(s)-ord(\'a\')].append(i)\nQ=int(input())\nfor _ in range(Q):\n Type,A,B=input().split()\n if Type=="1":\n A=int(A)\n s=S[A-1]\n if s==B:\n continue\n o=ord(s)-ord("a")\n alphabet[o].pop(bisect.bisect_left(alphabet[o],A-1))\n index=bisect.bisect(alphabet[B-1],A-1)\n alphabet[B-1].insert(index,A-1)\n S[A-1]=B\n else:\n A=int(A)\n B=int(B)\n ans=0\n for i in range(26):\n indexL=bisect.bisect_left(alphabet[i],A-1)\n \n #ans+=(indexL!=indexR)\n if indexL==len(alphabet[i]):\n continue\n ans+=(alphabet[i][indexL]<=B-1)\n print(ans)\n', 'import bisect\nN=input()\nS=list(input())\nalphabet=[[] for _ in range(26)]\nfor i,s in enumerate(S):\n alphabet[ord(s)-ord(\'a\')].append(i)\nQ=int(input())\nfor _ in range(Q):\n Type,A,B=input().split()\n if Type=="1":\n A=int(A)\n s=S[A-1]\n if s==B:\n continue\n o=ord(s)-ord("a")\n alphabet[o].pop(bisect.bisect_left(alphabet[o],A-1))\n index=bisect.bisect(alphabet[o],A-1)\n \n \n alphabet[B-1].insert(index,A-1)\n S[A-1]=B\n else:\n A=int(A)\n B=int(B)\n ans=0\n for i in range(26):\n indexL=bisect.bisect_left(alphabet[i],A-1)\n \n #ans+=(indexL!=indexR)\n if indexL==len(alphabet[i]):\n continue\n ans+=(alphabet[i][indexL]<=B-1)\n print(ans)\n', 'import bisect\nN=input()\nS=list(input())\nalphabet=[[] for _ in range(26)]\nfor i,s in enumerate(S):\n alphabet[ord(s)-ord(\'a\')].append(i)\nQ=int(input())\nfor _ in range(Q):\n Type,A,B=input().split()\n if Type=="1":\n A=int(A)\n s=S[A-1]\n if s==B:\n continue\n o=ord(s)-ord("a")\n alphabet[o].pop(bisect.bisect_left(alphabet[o],A-1))\n index=bisect.bisect(alphabet[ord(B)-ord("a")],A-1)\n alphabet[ord(B)-ord("a")].insert(index,A-1)\n S[A-1]=B\n else:\n A=int(A)\n B=int(B)\n ans=0\n for i in range(26):\n indexL=bisect.bisect_left(alphabet[i],A-1)\n \n #ans+=(indexL!=indexR)\n if indexL==len(alphabet[i]):\n continue\n ans+=(alphabet[i][indexL]<=B-1)\n print(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s281191029', 's659481311', 's462898520'] | [28552.0, 28552.0, 30472.0] | [1106.0, 1176.0, 1152.0] | [844, 949, 868] |
p02763 | u179169725 | 2,000 | 1,048,576 | You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: * Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) * Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | ["import sys\nread = sys.stdin.readline\n\n\ndef read_ints():\n return list(map(int, read().split()))\n\n\ndef read_a_int():\n return int(read())\n\n\ndef read_matrix(H):\n '''\n H is number of rows\n '''\n return [list(map(int, read().split())) for _ in range(H)]\n\n\ndef read_map(H):\n \n return [read()[:-1] for _ in range(H)]\n\n\ndef read_tuple(H):\n '''\n H is number of rows\n '''\n ret = []\n for _ in range(H):\n ret.append(tuple(map(int, read().split())))\n return ret\n\n\ndef read_col(H, n_cols):\n \n ret = [[] for _ in range(n_cols)]\n for _ in range(H):\n tmp = list(map(int, read().split()))\n for col in range(n_cols):\n ret[col].append(tmp[col])\n\n return ret\n\n\ndef index(a, x):\n 'Locate the leftmost value exactly equal to x'\n i = bisect_left(a, x)\n if i != len(a) and a[i] == x:\n return i\n raise ValueError\n\n\n\n\n\nγ«γ€γγ¦θγγ¦γΏγ\n\n\n\nN = read_a_int()\nS = read()[:-1]\n\nfrom collections import defaultdict\nfrom bisect import bisect_left, bisect_right, insort_left\nchar_idxs = defaultdict(lambda: [])\nfor i, s in enumerate(S):\n char_idxs[s].append(i)\n\n\ndef get_syurui(char_idxs, l, r):\n ret = 0\n for v in char_idxs.values():\n l_idx = bisect_left(v, l)\n r_idx = bisect_right(v, r)\n # print(v,l_idx,r_idx)\n if r_idx - l_idx > 0:\n ret += 1\n return ret\n\n\nQ = read_a_int()\nfor q in range(Q):\n com, a, b = read().split()\n if int(com) == 2:\n a, b = int(a) - 1, int(b) - 1\n print(get_syurui(char_idxs, a, b))\n else:\n i = int(a) - 1\n if S[i] == b:\n continue\n \n tmp = char_idxs[S[i]]\n del char_idxs[S[i]][index(tmp, i)]\n \n insort_left(char_idxs[b], i)\n", "\n\n\nimport sys\nread = sys.stdin.readline\n\n\ndef read_a_int():\n return int(read())\n\n\nclass SegmentTree:\n def __init__(self, ls: list, segfunc, identity_element):\n \n self.ide = identity_element\n self.func = segfunc\n n = len(ls)\n self.num = 2 ** (n - 1).bit_length() \n self.tree = [self.ide] * (2 * self.num - 1) \n for i, l in enumerate(ls): \n self.tree[i + self.num - 1] = l\n for i in range(self.num - 2, -1, -1): \n self.tree[i] = segfunc(self.tree[2 * i + 1], self.tree[2 * i + 2])\n\n def update(self, i, x):\n \n i += self.num - 1\n self.tree[i] = x\n while i: \n i = (i - 1) // 2\n self.tree[i] = self.func(self.tree[i * 2 + 1],\n self.tree[i * 2 + 2])\n\n def query(self, l, r):\n \n if r <= l:\n return ValueError('invalid index (l,rγγγγγͺγγ)')\n l += self.num\n r += self.num\n res = self.ide\n while r - l > 1: \n if l & 1:\n res = self.func(res, self.tree[l-1])\n l+=1\n if r & 1:\n r -= 1\n res = self.func(res, self.tree[r-1])\n l >>=1\n r >>=1\n return res\n\n\ndef segfunc(x, y):\n \n return x | y\n\n\ndef moji_to_bit(a):\n return 1 << (ord(a) - ord('a'))\n\n\ndef bit_to_sum(n):\n return sum([(n >> i) & 1 for i in range(n.bit_length())])\n\n\nN = read_a_int()\nS = read()[:-1]\nS_bit = [moji_to_bit(s) for s in S]\n\n\nst = SegmentTree(S_bit, segfunc, 0)\n\nQ = read_a_int()\nfor q in range(Q):\n com, a, b = read().split()\n if int(com) == 1:\n i, c = int(a) - 1, b\n st.update(i, moji_to_bit(c))\n else:\n l, r = int(a) - 1, int(b)\n print(bit_to_sum(st.query(l, r)))\n", "\n\n\nimport sys\nread = sys.stdin.readline\n\n\ndef read_a_int():\n return int(read())\n\n\nclass SegmentTree:\n def __init__(self, ls: list, segfunc, identity_element):\n \n self.ide = identity_element\n self.func = segfunc\n n = len(ls)\n self.num = 2 ** (n - 1).bit_length() \n self.tree = [self.ide] * (2 * self.num - 1) \n for i, l in enumerate(ls): \n self.tree[i + self.num - 1] = l\n for i in range(self.num - 2, -1, -1): \n self.tree[i] = segfunc(self.tree[2 * i + 1], self.tree[2 * i + 2])\n\n def update(self, i, x):\n \n i += self.num - 1\n self.tree[i] = x\n while i: \n i = (i - 1) // 2\n self.tree[i] = self.func(self.tree[i * 2 + 1],\n self.tree[i * 2 + 2])\n\n def query(self, l, r):\n \n if r <= l:\n return ValueError('invalid index (l,rγγγγγͺγγ)')\n l += self.num\n r += self.num\n res = self.ide\n while l<r: \n if l & 1:\n res = self.func(res, self.tree[l-1])\n l+=1\n if r & 1:\n r -= 1\n res = self.func(res, self.tree[r-1])\n l >>=1\n r >>=1\n return res\n\n\ndef segfunc(x, y):\n \n return x | y\n\n\ndef moji_to_bit(a):\n return 1 << (ord(a) - ord('a'))\n\n\ndef bit_to_sum(n):\n return sum([(n >> i) & 1 for i in range(n.bit_length())])\n\n\nN = read_a_int()\nS = read()[:-1]\nS_bit = [moji_to_bit(s) for s in S]\n\n\nst = SegmentTree(S_bit, segfunc, 0)\n\nQ = read_a_int()\nfor q in range(Q):\n com, a, b = read().split()\n if int(com) == 1:\n i, c = int(a) - 1, b\n st.update(i, moji_to_bit(c))\n else:\n l, r = int(a) - 1, int(b)\n print(bit_to_sum(st.query(l, r)))\n"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s177003909', 's736764642', 's633509061'] | [27252.0, 48460.0, 48460.0] | [1110.0, 815.0, 808.0] | [2202, 2867, 2861] |
p02763 | u223663729 | 2,000 | 1,048,576 | You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: * Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) * Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | ["\n# E - Simple String Queries\n\nfrom bisect import bisect_left, insort_left\nimport sys\ninput = sys.stdin.readline\nOFS = ord('a')\n_ = input()\nS = list(input()[:-1])\n\nD = [[] for _ in [0]*26]\nfor i, s in enumerate(S):\n D[s].append(i)\n\nfor _ in [0]*int(input()):\n Q = input()[:-1].split()\n if Q[0] == '1':\n i, c = int(Q[1])-1, Q[2]\n\n D[s].pop(bisect_left(D[S[i]], i))\n insort_left(D[ord(c)-OFS], i)\n S[i] = c\n\n else:\n l, r = int(Q[1])-1, int(Q[2])-1\n\n cnt = 0\n for L in D:\n i = bisect_left(L, l)\n if i < len(L) and L[i] <= r:\n cnt += 1\n\n print(cnt)\n", "\n# E - Simple String Queries\n\nfrom bisect import bisect_left, insort_left\nimport sys\ninput = sys.stdin.readline\nOFS = ord('a')\n_ = input()\nS = list(input()[:-1])\n\nD = [[] for _ in [0]*26]\nfor i, s in enumerate(S):\n D[ord(s)-OFS].append(i)\n\nfor _ in [0]*int(input()):\n Q = input()[:-1].split()\n if Q[0] == '1':\n i, c = int(Q[1])-1, Q[2]\n\n if S[i] != c:\n s = ord(S[i])-OFS\n D[s].pop(bisect_left(D[s], i))\n insort_left(D[ord(c)-OFS], i)\n S[i] = c\n\n else:\n l, r = int(Q[1])-1, int(Q[2])-1\n\n cnt = 0\n for L in D:\n i = bisect_left(L, l)\n if i < len(L) and L[i] <= r:\n cnt += 1\n\n print(cnt)\n"] | ['Runtime Error', 'Accepted'] | ['s866553195', 's571351160'] | [7816.0, 30856.0] | [28.0, 957.0] | [730, 800] |
p02763 | u230117534 | 2,000 | 1,048,576 | You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: * Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) * Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | ['class SegTree:\n def __init__(self, N, S):\n self.N = 2 ** ((N-1).bit_length())\n self.tree = [0 for i in range(self.N * 2 - 1)]\n for i in range(len(S)):\n self.tree[self.N - 1 + i] = 1 << (ord(S[i] - ord("a")))\n\n for i in range(self.N - 2, -1, -1):\n self.tree[i] = self.tree[i*2 + 1] | self.tree[i*2 + 2]\n\n def update(self, index, char):\n i = self.N - 1 + index\n \n self.tree[i] = 1 << (ord(char) - ord("a"))\n while i > 0:\n i = (i-1) // 2\n self.tree[i] = self.tree[i*2 + 1] | self.tree[i*2 + 2]\n\n def get(self, a, b):\n return self.query(a, b, 0, 0, self.N)\n\n \n \n \n def query(self, a, b, k, l, r):\n if r <= a or b <= l: \n return 0\n elif a <= l and r <= b: \n return self.tree[k]\n else: \n left = self.query(a, b, 2 * k + 1, l, (l+r)//2)\n right = self.query(a, b, 2 * k + 2, (l+r)//2, r)\n return left | right\n\ndef solve():\n N = int(input())\n S = list(input().strip())\n tree = SegTree(N, S)\n\n Q = int(input())\n for _ in range(Q):\n t_q, in_1, in_2 = input().split()\n if t_q == "1":\n i_q = int(in_1)\n c_q = in_2\n tree.update(i_q-1, c_q)\n else:\n l_q = int(in_1)\n r_q = int(in_2)\n print(bin(tree.get(l_q-1, r_q)).count(1))\n\nsolve()', 'class SegTree:\n def __init__(self, N, S):\n self.N = 2 ** ((N-1).bit_length())\n self.tree = [0 for i in range(self.N * 2 - 1)]\n for i in range(len(S)):\n self.tree[self.N - 1 + i] = 1 << (ord(S[i]) - ord("a"))\n\n for i in range(self.N - 2, -1, -1):\n self.tree[i] = self.tree[i*2 + 1] | self.tree[i*2 + 2]\n\n def update(self, index, char):\n i = self.N - 1 + index\n \n self.tree[i] = 1 << (ord(char) - ord("a"))\n while i > 0:\n i = (i-1) // 2\n self.tree[i] = self.tree[i*2 + 1] | self.tree[i*2 + 2]\n\n def get(self, a, b):\n return self.query(a, b, 0, 0, self.N)\n\n \n \n \n def query(self, a, b, k, l, r):\n if r <= a or b <= l: \n return 0\n elif a <= l and r <= b: \n return self.tree[k]\n else: \n left = self.query(a, b, 2 * k + 1, l, (l+r)//2)\n right = self.query(a, b, 2 * k + 2, (l+r)//2, r)\n return left | right\n\ndef solve():\n N = int(input())\n S = list(input().strip())\n tree = SegTree(N, S)\n\n Q = int(input())\n for _ in range(Q):\n t_q, in_1, in_2 = input().split()\n if t_q == "1":\n i_q = int(in_1)\n c_q = in_2\n tree.update(i_q-1, c_q)\n else:\n l_q = int(in_1)\n r_q = int(in_2)\n print(bin(tree.get(l_q-1, r_q)).count("1"))\n\nsolve()'] | ['Runtime Error', 'Accepted'] | ['s980250208', 's711333635'] | [16136.0, 47400.0] | [72.0, 1118.0] | [1662, 1664] |
p02763 | u265154666 | 2,000 | 1,048,576 | You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: * Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) * Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | ['# -*- coding: utf-8 -*-\n\n\n\n\n\n# from helper import elapsed_time\nfrom bisect import bisect_left, insort_left\n\n\nN = int(input())\ns = list(input())\nQ = int(input())\n\n\n# print()\n# print(len(s))\n\n\nd = {i: [] for i in range(26)}\nfor i, c in enumerate(s):\n d[ord(c) - ord("a")].append(i)\n# print(d)\n\n\n# @elapsed_time\ndef convert(d: dict, s: list, q1: int, q2: str):\n if s[q1] == q2:\n return d, s\n\n didx_before = ord(s[q1]) - ord("a")\n didx_after = ord(q2) - ord("a")\n\n idx = bisect_left(d[didx_before], q1)\n d[didx_before].pop(idx)\n s[q1] = q2\n insort_left(d[didx_after], q1)\n\n \n \n return d, s\n\n\n# @elapsed_time\ndef calc(d: dict, q1: int, q2: int):\n ans = 0\n for i in range(26):\n idx = bisect_left(d[i], q1)\n if d[i] and q1 <= d[i][-1] and d[i][idx] < q2:\n ans += 1\n \'\'\'\n st = time.time()\n temp1 = s[q1:q2 + 1]\n print(f\'>>- extract: {time.time()-st}\')\n\n st = time.time()\n temp2 = set(temp1)\n print(f\'>>- to set: {time.time()-st}\')\n ans = len(list(temp2))\n \'\'\'\n\n return ans\n\n\nfor _ in range(Q):\n q, q1, q2 = input().split()\n q = int(q)\n if q == 1:\n d, s = convert(d, s, int(q1) - 1, q2)\n if q == 2:\n print(calc(d, int(q1) - 1, int(q2) - 1))\n', '# -*- coding: utf-8 -*-\n\n\n\n\n\nfrom helper import elapsed_time\nfrom bisect import bisect_left, insort_left\n\n\nN = int(input())\ns = list(input())\nQ = int(input())\n\n\n# print()\n# print(len(s))\n\n\nd = {i: [] for i in range(26)}\nfor i, c in enumerate(s):\n d[ord(c) - ord("a")].append(i)\n# print(d)\n\n\n@elapsed_time\ndef convert(d: dict, s: list, q1: int, q2: str):\n if s[q1] == q2:\n return d, s\n\n didx_before = ord(s[q1]) - ord("a")\n didx_after = ord(q2) - ord("a")\n\n idx = bisect_left(d[didx_before], q1)\n d[didx_before].pop(idx)\n s[q1] = q2\n insort_left(d[didx_after], q1)\n\n \n \n return d, s\n\n\n@elapsed_time\ndef calc(d: dict, q1: int, q2: int):\n ans = 0\n for i in range(26):\n idx = bisect_left(d[i], q1)\n if d[i] and q1 <= d[i][-1] and d[i][idx] < q2:\n ans += 1\n \'\'\'\n st = time.time()\n temp1 = s[q1:q2 + 1]\n print(f\'>>- extract: {time.time()-st}\')\n\n st = time.time()\n temp2 = set(temp1)\n print(f\'>>- to set: {time.time()-st}\')\n ans = len(list(temp2))\n \'\'\'\n\n return ans\n\n\nfor _ in range(Q):\n q, q1, q2 = input().split()\n q = int(q)\n if q == 1:\n d, s = convert(d, s, int(q1) - 1, q2)\n if q == 2:\n print(calc(d, int(q1) - 1, int(q2) - 1))\n', '# -*- coding: utf-8 -*-\n\n\n\n# from helper import elapsed_time\nfrom bisect import bisect_left, insort_left\n\n\nN = int(input())\ns = list(input())\nQ = int(input())\n\n\nd = {i: [] for i in range(26)}\nfor i, c in enumerate(s):\n d[ord(c) - ord("a")].append(i)\n\n\n# @elapsed_time\ndef convert(d: dict, s: list, q1: int, q2: str):\n if s[q1] == q2:\n return d, s\n\n didx_before = ord(s[q1]) - ord("a")\n didx_after = ord(q2) - ord("a")\n\n idx = bisect_left(d[didx_before], q1)\n d[didx_before].pop(idx)\n s[q1] = q2\n insort_left(d[didx_after], q1)\n\n return d, s\n\n\n# @elapsed_time\ndef calc(d: dict, q1: int, q2: int):\n ans = 0\n for i in range(26):\n idx = bisect_left(d[i], q1)\n if d[i] and q1 <= d[i][-1] and d[i][idx] < q2 + 1:\n ans += 1\n\n return ans\n\n\nfor _ in range(Q):\n q, q1, q2 = input().split()\n q = int(q)\n if q == 1:\n d, s = convert(d, s, int(q1) - 1, q2)\n if q == 2:\n print(calc(d, int(q1) - 1, int(q2) - 1))\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s429906029', 's828076268', 's779552085'] | [28680.0, 3064.0, 28808.0] | [1112.0, 18.0, 1092.0] | [1642, 1636, 1146] |
p02763 | u306950978 | 2,000 | 1,048,576 | You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: * Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) * Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | ['from bisect import bisect_left,bisect\nn = int(input())\ns = list(input())\nq = int(input())\nal=[[] for i in range(26)]\nfor i in range(n):\n al[ord(s[i])-ord("a")].append(i)\n\nfor i in range(q):\n a , b , x = input().split()\n if a == "1":\n al[ord(s[int(b)-1])-ord("a")].pop(al[ord(s[int(b)-1])-ord("a")],int(b)-1)\n al[ord(x)-ord("a")].insert(bisect_left(al[ord(x)-ord("a")],int(b)-1),int(b)-1)\n s[int(b)-1] = x\n elif a == "2":\n b = int(b)-1\n x = int(x)-1\n cou = 0\n for j in range(26):\n l = bisect_left(al[j],b)\n r = bisect(al[j],x)\n if l != r:\n cou += 1\n print(cou)\n', 'def main():\n from bisect import bisect_left,bisect\n n = int(input())\n s = list(input())\n q = int(input())\n al=[[] for i in range(26)]\n for i in range(n):\n al[ord(s[i])-97].append(i)\n ans = []\n for i in range(q):\n a , b , x = input().split()\n if a == "1":\n al[ord(s[int(b)-1])-97].pop(bisect_left(al[ord(s[int(b)-1])-97],int(b)-1))\n al[ord(x)-97].insert(bisect_left(al[ord(x)-97],int(b)-1),int(b)-1)\n s[int(b)-1] = x\n elif a == "2":\n b = int(b)-1\n x = int(x)-1\n cou = 0\n for j in range(26):\n l = bisect_left(al[j],b)\n r = bisect(al[j],x)\n if l != r:\n cou += 1\n ans.append(cou)\n for i in ans:\n print(i)\n\nif __name__ == \'__main__\':\n main()'] | ['Runtime Error', 'Accepted'] | ['s620802652', 's832253006'] | [34772.0, 35140.0] | [940.0, 1947.0] | [676, 853] |
p02763 | u334365640 | 2,000 | 1,048,576 | You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: * Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) * Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | ['import math\n\nn = int(input())\ns = input()\nS = [ord(i) - 97 for i in s]\nq = int(input())\nHEIGHT = math.ceil(math.log(n) / math.log(2))\nSIZE = 1 << HEIGHT\n\ndef build_tree_for_letter(letter):\n tree = [False for _ in range(2 << HEIGHT)]\n for i in range(1 << HEIGHT):\n tree[i + (1 << HEIGHT)] = True if i < n and s[i] == chr(97 + letter) else False\n\n for i in range(HEIGHT - 1, -1, -1):\n for x in range(1<<i, 2<<i):\n tree[x] = any((tree[x<<1], tree[(x<<1)+1]))\n\n return tree\n\n\ndef build():\n return [build_tree_for_letter(letter) for letter in range(26)]\n\n\n\ndef update(x, letter, positive=True):\n trees[letter][x] = (positive == True)\n while x > 1:\n x >>= 1\n trees[letter][x] = any((trees[letter][x << 1], trees[letter][(x << 1) + 1]))\n\n\ndef query(ll, rr):\n\n # print("query: ", l, r)\n total = 0\n for letter in range(26):\n l, r = ll, rr\n is_letter = False\n while l < r:\n if l%(2) != 0:\n is_letter = any((is_letter, trees[letter][l]))\n l += 1\n l >>= 1\n if r%(2) != 0:\n r -= 1\n is_letter = any((is_letter, trees[letter][r]))\n r >>= 1\n total += is_letter\n return total\n\n\n\ntrees = build()\n\nfor i in range(q):\n a, b, c = input().split()\n b = int(b) - 1 + SIZE\n if int(a) == 1:\n c = ord(c) - 97\n update(b, S[b], positive=False)\n S[b] = c\n update(b, c, positive=True)\n else:\n print(query(b, int(c)+SIZE))\n\n\n\n\n\n\n', "import math\n\nn = int(input())\ns = input()\nS = [ord(i) - 97 for i in s]\nq = int(input())\nHEIGHT = math.ceil(math.log(n) / math.log(2))\nSIZE = 1 << HEIGHT\n\ndef build_tree():\n tree = [0 for _ in range(SIZE<<1)]\n\n for i, letter in enumerate(s):\n tree[i+SIZE] = 1<<(ord(letter)-97)\n\n for i in range(HEIGHT - 1, -1, -1):\n for x in range(1<<i, 2<<i):\n tree[x] = tree[x<<1] | tree[(x<<1)+1]\n\n return tree\n\n\n\n\ndef update(x, number):\n tree[x] = number\n while x > 1:\n x >>= 1\n tree[x] = tree[x << 1] | tree[(x << 1) + 1]\n\n\ndef query(l, r):\n total = 0\n while l < r:\n if l&1:\n total |= tree[l]\n l += 1\n l >>= 1\n if r&1:\n r -= 1\n total |= tree[r]\n r >>= 1\n return bin(total).count('1')\n\n\n\ntree = build_tree()\n\nfor i in range(q):\n a, b, c = input().split()\n b = int(b) - 1\n if int(a) == 1:\n update(b + SIZE, S[b])\n c = 1 << (ord(c) - 97)\n S[b] = c\n update(b + SIZE, c)\n else:\n print(query(b + SIZE, int(c)+SIZE))\n\n\n\n\n\n\n"] | ['Runtime Error', 'Accepted'] | ['s841533344', 's204706513'] | [65672.0, 48152.0] | [2107.0, 693.0] | [1548, 1089] |
p02763 | u340781749 | 2,000 | 1,048,576 | You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: * Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) * Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | ["import sys\n\n\nclass SegTreeSet:\n \n\n def __init__(self, n, initial=0):\n \n n2 = 1 << (n - 1).bit_length()\n self.offset = n2\n self.tree = [initial] * (n2 << 1)\n self.initial = initial\n\n def update(self, i, x):\n \n i += self.offset\n self.tree[i] ^= x\n while i > 1:\n self.tree[i >> 1] = self.tree[i] | self.tree[i ^ 1]\n i >>= 1\n\n def get_size(self, a, b):\n \n result = self.initial\n\n l = a + self.offset\n r = b + self.offset\n while l < r:\n if r & 1:\n result |= self.tree[r - 1]\n if l & 1:\n result |= self.tree[l]\n l += 1\n l >>= 1\n r >>= 1\n\n return bin(result).count('1')\n\n\nchar_mappings = {chr(i + 97): 1 << i for i in range(26)}\n\nn = int(input())\ns = input()\ns = list(s)\nst = SegTreeSet(n)\nq = int(input())\nans = []\nfor line in sys.stdin:\n i, j, k = line.rstrip().split()\n if i == '1':\n j = int(j) - 1\n if s[j] == k:\n continue\n b = char_mappings[k] | char_mappings[s[j]]\n st.update(j, b)\n s[j] = k\n else:\n l = int(j) - 1\n r = int(k)\n ans.append(st.get_size(l, r))\nprint('\\n'.join(map(str, ans)))\n", "import sys\n\n\nclass SegTreeSet:\n \n\n def __init__(self, n, initial=0):\n \n n2 = 1 << (n - 1).bit_length()\n self.offset = n2\n self.tree = [initial] * (n2 << 1)\n self.initial = initial\n\n def initial_construct(self, s):\n for i, x in enumerate(s, start=self.offset):\n self.tree[i] = x\n for i in range(self.offset - 1, 0, -1):\n self.tree[i] = self.tree[i << 1] | self.tree[(i << 1) + 1]\n\n def update(self, i, x):\n \n i += self.offset\n self.tree[i] ^= x\n while i > 1:\n self.tree[i >> 1] = self.tree[i] | self.tree[i ^ 1]\n i >>= 1\n\n def get_size(self, a, b):\n \n result = self.initial\n\n l = a + self.offset\n r = b + self.offset\n while l < r:\n if r & 1:\n result |= self.tree[r - 1]\n if l & 1:\n result |= self.tree[l]\n l += 1\n l >>= 1\n r >>= 1\n\n return bin(result).count('1')\n\n\nchar_mappings = {chr(i + 97): 1 << i for i in range(26)}\n\nn = int(input())\ns = input()\ns = list(s)\nst = SegTreeSet(n)\nst.initial_construct(map(char_mappings.get, s))\nq = int(input())\nans = []\nfor line in sys.stdin:\n i, j, k = line.rstrip().split()\n if i == '1':\n j = int(j) - 1\n if s[j] == k:\n continue\n b = char_mappings[k] | char_mappings[s[j]]\n st.update(j, b)\n s[j] = k\n else:\n l = int(j) - 1\n r = int(k)\n ans.append(st.get_size(l, r))\nprint('\\n'.join(map(str, ans)))\n"] | ['Wrong Answer', 'Accepted'] | ['s389192865', 's768499689'] | [18976.0, 32088.0] | [242.0, 490.0] | [1819, 2105] |
p02763 | u347640436 | 2,000 | 1,048,576 | You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: * Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) * Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | ["# Segment tree (Bitwise Or)\nfrom operator import or_\n\n\nclass SegmentTree:\n _f = None\n _data = None\n _offset = None\n _size = None\n\n def __init__(self, size, f):\n self._f = f\n self._size = size\n t = 1\n while t < size:\n t *= 2\n self._offset = t - 1\n self._data = [0] * (t * 2 - 1)\n\n def build(self, iterable):\n f = self._f\n data = self._data\n data[self._offset:self._offset + self._size] = iterable\n for i in range(self._offset - 1, -1, -1):\n data[i] = f(data[i * 2 + 1], data[i * 2 + 2])\n\n def update(self, index, value):\n f = self._f\n data = self._data\n i = self._offset + index\n data[i] = value\n while i >= 1:\n i = (i - 1) // 2\n data[i] = f(data[i * 2 + 1], data[i * 2 + 2])\n\n def query(self, start, stop):\n def iter_segments(data, l, r):\n while l < r:\n if l & 1 == 0:\n yield data[l]\n if r & 1 == 0:\n yield data[r - 1]\n l = l // 2\n r = (r - 1) // 2\n f = self._f\n it = iter_segments(self._data, start + self._offset,\n stop + self._offset)\n result = next(it)\n for e in it:\n result = f(result, e)\n return result\n\n\nN = int(input())\nS = input()\n\nst = SegmentTree(N, or_)\nst.build(S)\n\nQ = int(input())\nfor _ in range(Q):\n q = input().split()\n if q[0] == '1':\n i, c = q[1:]\n i = int(i) - 1\n st.update(i, c)\n elif q[0] == '2':\n l, r = map(int, q[1:])\n print(bin(st.query(l - 1, r)).count('1'))\n", "# Segment tree (Bitwise Or)\nfrom operator import or_\n\n\nclass SegmentTree:\n _f = None\n _data = None\n _offset = None\n _size = None\n\n def __init__(self, size, f):\n self._f = f\n self._size = size\n t = 1\n while t < size:\n t *= 2\n self._offset = t - 1\n self._data = [0] * (t * 2 - 1)\n\n def build(self, iterable):\n f = self._f\n data = self._data\n data[self._offset:self._offset + self._size] = iterable\n for i in range(self._offset - 1, -1, -1):\n data[i] = f(data[i * 2 + 1], data[i * 2 + 2])\n\n def update(self, index, value):\n f = self._f\n data = self._data\n i = self._offset + index\n data[i] = value\n while i >= 1:\n i = (i - 1) // 2\n data[i] = f(data[i * 2 + 1], data[i * 2 + 2])\n\n def query(self, start, stop):\n def iter_segments(data, l, r):\n while l < r:\n if l & 1 == 0:\n yield data[l]\n if r & 1 == 0:\n yield data[r - 1]\n l = l // 2\n r = (r - 1) // 2\n f = self._f\n it = iter_segments(self._data, start + self._offset,\n stop + self._offset)\n result = next(it)\n for e in it:\n result = f(result, e)\n return result\n\n\ndef conv(c):\n return 1 << (ord(c) - ord('a'))\n\n\nN = int(input())\nS = input()\n\nst = SegmentTree(N, or_)\nst.build(conv(c) for c in S)\n\nQ = int(input())\nfor _ in range(Q):\n q = input().split()\n if q[0] == '1':\n i, c = q[1:]\n i = int(i) - 1\n st.update(i, conv(c))\n elif q[0] == '2':\n l, r = map(int, q[1:])\n print(bin(st.query(l - 1, r)).count('1'))\n"] | ['Runtime Error', 'Accepted'] | ['s046089488', 's889155241'] | [25584.0, 49688.0] | [54.0, 455.0] | [1691, 1765] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.