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 |
|---|---|---|---|---|---|---|---|---|---|---|
p03108 | u864013199 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['class UnionFind():\n def __init__(self, n):\n self.parent = [-1 for _ in range(n)]\n \n\n def find(self, x):\n if self.parent[x] < 0:\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, y = self.find(x), self.find(y)\n if x == y:\n return False\n else:\n if self.size(x) < self.size(y):\n x, y = y, x\n self.parent[x] += self.parent[y]\n self.parent[y] = x\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.parent[x]\n\n def is_root(self, x):\n return self.parent[x] < 0\n\nN, M, *hashi = map(int, open(0).read().split()) \nuf = UnionFind(N)\nlis = [0]*M\nlis[M-1] = N*(N-1)//2\n\nfor i in range(M-2,-1,-1):\n x = hashi[i+1][0]-1\n y = hashi[i+1][1]-1\n if uf.same(x,y):\n lis[i] = tmp\n else:\n xs = uf.size(x)\n ys = uf.size(y)\n uf.unite(x,y)\n tmp = lis[i+1] - xs*ys\n lis[i] = tmp\n if not tmp:\n break \nfor i in range(M):\n print(lis[i])\n', 'class UnionFind():\n def __init__(self, n):\n self.parent = [-1 for _ in range(n)]\n \n\n def find(self, x):\n if self.parent[x] < 0:\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, y = self.find(x), self.find(y)\n if x == y:\n return False\n else:\n if self.size(x) < self.size(y):\n x, y = y, x\n self.parent[x] += self.parent[y]\n self.parent[y] = x\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.parent[x]\n\n def is_root(self, x):\n return self.parent[x] < 0\n\nN,M=map(int,input().split())\nuf = UnionFind(N)\nhashi = [list(map(int,input().split())) for _ in range(M)]\nlis = [0]*M\nlis[M-1] = N*(N-1)//2\n\nfor i in range(M-2,-1,-1):\n x = hashi[i+1][0]-1\n y = hashi[i+1][1]-1\n if uf.same(x,y):\n lis[i] = tmp\n else:\n xs = uf.size(x)\n ys = uf.size(y)\n uf.unite(x,y)\n tmp = lis[i+1] - xs*ys\n lis[i] = tmp\n if not tmp:\n break \nfor i in range(M):\n print(lis[i])\n'] | ['Runtime Error', 'Accepted'] | ['s856023606', 's127266753'] | [25332.0, 34620.0] | [69.0, 883.0] | [1359, 1292] |
p03108 | u868628468 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['n,m = map(int,input().split())\nedges = []\nfor _ in range(m):\n edges.append(list(map(int,input().split())))\nans = []\ncur = ((m-1)*m)//2\npar = {i:i for i in range(1,n+1)}\nsize = {i:1 for i in range(1,n+1)}\ndef find(x):\n if x != par[x]:\n par[x] = find(par[x])\n return par[x]\n\ndef union(x,y):\n px,py = find(x),find(y)\n res = 0\n if px != py:\n res = size[px]*size[py]\n par[py] = px\n size[px] += size[py]\n return res\n\nfor i in range(m-1,-1,-1):\n ans.append(cur)\n x,y = edges[i]\n cur -= union(x,y)\nfor i in range(m-1,-1,-1):\n print(ans[i])', 'n,m = map(int,input().split())\nedges = []\nfor _ in range(m):\n edges.append(list(map(int,input().split())))\nans = []\ncur = ((n-1)*n)//2\npar = {i:i for i in range(1,n+1)}\nsize = {i:1 for i in range(1,n+1)}\nrank = {i:0 for i in range(1,n+1)}\ndef find(x):\n if x != par[x]:\n par[x] = find(par[x])\n return par[x]\n\ndef union(x,y):\n px,py = find(x),find(y)\n res = 0\n if px != py:\n res = size[px] * size[py]\n if rank[px] < rank[py]:\n par[px] = py\n size[py] += size[px]\n else:\n par[py] = px\n size[px] += size[py]\n if rank[px] == rank[py]:\n rank[px] += 1\n return res\n\nfor i in range(m-1,-1,-1):\n ans.append(cur)\n x,y = edges[i]\n cur -= union(x,y)\nfor i in range(m-1,-1,-1):\n print(ans[i])'] | ['Runtime Error', 'Accepted'] | ['s604897419', 's810954193'] | [53872.0, 60332.0] | [501.0, 619.0] | [592, 808] |
p03108 | u870262604 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['import sys\nsys.setrecursionlimit(10**7)\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\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 II(): return int(sys.stdin.readline())\ndef SI(): return sys.stdin.readline().strip()\nINF = 10 ** 18\nMOD = 10 ** 9 + 7\n\nclass UnionFind:\n\n def __init__(self, n):\n self.parents = [i for i in range(n)]\n self.size_dict = {i:1 for i in range(n)}\n self.fuben = n * (n-1) / 2\n\n def merge(self, i, j):\n rooti = self.findroot(i)\n rootj = self.findroot(j)\n self.parents[rooti] = rootj\n sj = self.size_dict[rootj]\n si = self.size_dict[rooti]\n self.fuben -= sj*(n-sj)/2\n self.fuben -= si*(n-si)/2\n self.fuben += (sj+si)*(n-(sj+si))/2\n self.size_dict[rootj] += self.size_dict[rooti]\n self.size_dict[rooti] = 0\n\n def issame(self, i, j):\n rooti = self.findroot(i)\n rootj = self.findroot(j)\n return rooti == rootj\n\n def findroot(self, i, followed_indices=None):\n\n if i == self.parents[i]:\n return i\n else:\n root = self.findroot(self.parents[i])\n self.parents[i] = root \n return root\n \nn, m = LI()\nedge_list = []\nfor i in range(m):\n a, b = LI()\n edge_list.append((a-1, b-1))\n \nans = []\n\nuf = UnionFind(n)\nimport collections\n\nfor e in edge_list[::-1]:\n ans.append(int(uf.fuben))\n uf.merge(e[0], e[1])\n\nfor a in ans[::-1]:\n print(a)\n', 'import sys\nsys.setrecursionlimit(10**7)\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\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 II(): return int(sys.stdin.readline())\ndef SI(): return sys.stdin.readline().strip()\nINF = 10 ** 18\nMOD = 10 ** 9 + 7\n\nclass UnionFind:\n\n def __init__(self, n):\n self.parents = [i for i in range(n)]\n self.size_dict = {i:1 for i in range(n)}\n self.fuben = n * (n-1) / 2\n\n def merge(self, i, j):\n rooti = self.findroot(i)\n rootj = self.findroot(j)\n if rooti == rootj:\n return\n self.parents[rooti] = rootj\n sj = self.size_dict[rootj]\n si = self.size_dict[rooti]\n self.fuben -= sj*(n-sj)/2\n self.fuben -= si*(n-si)/2\n self.fuben += (sj+si)*(n-(sj+si))/2\n self.size_dict[rootj] += self.size_dict[rooti]\n self.size_dict[rooti] = 0\n\n def issame(self, i, j):\n rooti = self.findroot(i)\n rootj = self.findroot(j)\n return rooti == rootj\n\n def findroot(self, i, followed_indices=None):\n\n if i == self.parents[i]:\n return i\n else:\n root = self.findroot(self.parents[i])\n self.parents[i] = root \n return root\n \nn, m = LI()\nedge_list = []\nfor i in range(m):\n a, b = LI()\n edge_list.append((a-1, b-1))\n \nans = []\n\nuf = UnionFind(n)\nimport collections\n\nfor e in edge_list[::-1]:\n ans.append(int(uf.fuben))\n uf.merge(e[0], e[1])\n\nfor a in ans[::-1]:\n print(a)\n'] | ['Wrong Answer', 'Accepted'] | ['s592017773', 's710516333'] | [47064.0, 46960.0] | [657.0, 660.0] | [1614, 1658] |
p03108 | u875291233 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ["import sys\n\nclass UnionFind:\n def __init__(self, size):\n self.parent = [-1 for i in range(size)]\n\n def root(self, x): \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 merge(self, x, y): \n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.parent[x] > self.parent[y]: \n x,y=y,x\n self.parent[x] += self.parent[y] \n self.parent[y] = x \n return True\n\n def issame(self, x, y): \n return self.root(x) == self.root(y)\n \n def size(self,x): \n return -self.parent[self.root(x)]\n\n\nn, m = map(int, input().split())\nA=[[int(i)-1 for i in input().split()] for _ in range(m)]\nbridges.reverse()\nbuf = [n * (n - 1) // 2]\nuft = UnionFind(n)\nfor line in bridges[:-1]:\n a, b = map(int, line.split())\n if uft.issame(a, b):\n buf.append(buf[-1])\n continue\n ra = uft.size(a)\n rb = uft.size(b)\n buf.append(buf[-1] - ra * rb)\n uft.merge(a, b)\nbuf.reverse()\nprint('\\n'.join(map(str, buf)))\n \n \n \n \n \n\n\n\n", "import sys\n\nclass UnionFind:\n def __init__(self, size):\n self.parent = [-1 for i in range(size)]\n\n def root(self, x): \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 merge(self, x, y): \n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.parent[x] > self.parent[y]: \n x,y=y,x\n self.parent[x] += self.parent[y] \n self.parent[y] = x \n return True\n\n def issame(self, x, y): \n return self.root(x) == self.root(y)\n \n def size(self,x): \n return -self.parent[self.root(x)]\n\n\nn, m = map(int, input().split())\nbridges = list(sys.stdin)\nbridges.reverse()\nbuf = [n * (n - 1) // 2]\nuft = UnionFind(n)\nfor line in bridges[:-1]:\n a, b = map(int, line.split())\n a -= 1\n b -= 1\n if uft.find(a, b):\n buf.append(buf[-1])\n continue\n ra = uft.table[uft._root(a)]\n rb = uft.table[uft._root(b)]\n buf.append(buf[-1] - ra * rb)\n uft.union(a, b)\nbuf.reverse()\nprint('\\n'.join(map(str, buf)))\n \n \n \n \n \n\n\n\n", '# coding: utf-8\n# Your code here!\n\nclass UnionFind:\n def __init__(self, size):\n self.parent = [-1]*size\n\n def root(self, x): \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 merge(self, x, y): \n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.parent[x] > self.parent[y]: \n x,y=y,x\n self.parent[x] += self.parent[y] \n self.parent[y] = x \n return True\n\n def issame(self, x, y): \n return self.root(x) == self.root(y)\n \n def size(self,x): \n return -self.parent[self.root(x)]\n\n\nn,m=[int(i) for i in input().split()]\n\nA=[[int(i)-1 for i in input().split()] for _ in range(m)]\n\nans = [0]*(m+1)\na = n*(n-1)//2\nans[0] = a\n\nprint(a)\nuf = UnionFind(n)\nfor i in range(m-1):\n j = m-i-1\n v1 = A[j][0]\n v2 = A[j][1]\n# print(v1,v2)\n if not uf.issame(v1,v2):\n\n a -= uf.size(v1) * uf.size(v2)\n uf.merge(v1,v2)\n\n print(a)\n\n\n \n \n \n \n \n\n\n\n', 'import sys\ninput = sys.stdin.readline\n\nclass UnionFind:\n def __init__(self, size):\n self.parent = [-1 for i in range(size)]\n\n def root(self, x): \n if self.parent[x] < 0:\n return x\n elif self.parent[self.parent[x]] < 0:\n return self.parent[x]\n else:\n self.parent[x] = self.parent[self.parent[x]] = self.root(self.parent[self.parent[x]]) \n return self.parent[x]\n\n def merge(self, x, y): \n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.parent[x] > self.parent[y]: \n x,y=y,x\n self.parent[x] += self.parent[y] \n self.parent[y] = x \n return True\n\n def issame(self, x, y): \n return self.root(x) == self.root(y)\n \n def size(self,x): \n return -self.parent[self.root(x)]\n\n\nn,m=[int(i) for i in input().split()]\n\nA=[[int(i)-1 for i in input().split()] for _ in range(m)]\n\nans = [0]*(m+1)\na = n*(n-1)//2\nans[0] = a\n\nuf = UnionFind(n)\nfor i in range(m):\n j = m-i-1\n v1 = A[j][0]\n v2 = A[j][1]\n# print(v1,v2)\n if not uf.issame(v1,v2):\n\n a -= uf.size(v1) * uf.size(v2)\n uf.merge(v1,v2)\n\n ans[i+1]=a\n\nfor i in range(m):\n print(ans[m-i-1])\n \n \n \n \n \n \n\n\n\n', 'class UnionFind:\n def __init__(self, size):\n self.parent = [-1 for i in range(size)]\n\n def root(self, x): \n if self.parent[x] < 0:\n return x\n else:\n while self.parent[x] >= 0 and self.parent[self.parent[x]] >= 0:\n self.parent[x] = self.parent[self.parent[x]]\n x = self.parent[x]\n\n return self.parent[x]\n\n def merge(self, x, y): \n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.parent[x] > self.parent[y]: \n x,y=y,x\n self.parent[x] += self.parent[y] \n self.parent[y] = x \n return True\n\n def issame(self, x, y): \n return self.root(x) == self.root(y)\n \n def size(self,x): \n return -self.parent[self.root(x)]\n\n\nn,m=[int(i) for i in input().split()]\n\nA=[[int(i)-1 for i in input().split()] for _ in range(m)]\n\nans = [0]*(m+1)\na = n*(n-1)//2\nans[0] = a\n\nuf = UnionFind(n)\nfor i in range(m):\n j = m-i-1\n v1 = A[j][0]\n v2 = A[j][1]\n# print(v1,v2)\n if not uf.issame(v1,v2):\n\n a -= uf.size(v1) * uf.size(v2)\n uf.merge(v1,v2)\n\n ans[i+1]=a\n\nfor i in range(m):\n print(ans[m-i-1])\n \n \n \n \n \n \n\n\n\n', 'import sys\ninput = sys.stdin.readline\n\nclass UnionFind:\n def __init__(self, size):\n self.parent = [-1 for i in range(size)]\n\n def root(self, x): \n px=self.parent[x]\n if px < 0:\n return x\n if self.parent[px] < 0:\n return px\n self.parent[px] = self.parent[x] = self.root(self.parent[px]) \n return self.parent[x]\n\n def merge(self, x, y): \n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.parent[x] > self.parent[y]: \n x,y=y,x\n self.parent[x] += self.parent[y] \n self.parent[y] = x \n return True\n\n def issame(self, x, y): \n return self.root(x) == self.root(y)\n \n def size(self,x): \n return -self.parent[self.root(x)]\n\n\nn,m=[int(i) for i in input().split()]\n\nA=[[int(i)-1 for i in input().split()] for _ in range(m)]\n\nans = [0]*(m+1)\na = n*(n-1)//2\nans[0] = a\n\nuf = UnionFind(n)\nfor i in range(m):\n j = m-i-1\n v1 = A[j][0]\n v2 = A[j][1]\n# print(v1,v2)\n if not uf.issame(v1,v2):\n\n a -= uf.size(v1) * uf.size(v2)\n uf.merge(v1,v2)\n\n ans[i+1]=a\n\nfor i in range(m):\n print(ans[m-i-1])\n \n \n \n \n \n \n\n\n\n'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s212921356', 's447913701', 's660678270', 's663853405', 's806486627', 's776044188'] | [21184.0, 11820.0, 25296.0, 27196.0, 27368.0, 27196.0] | [338.0, 35.0, 794.0, 621.0, 2105.0, 589.0] | [1598, 1610, 1569, 1748, 1755, 1690] |
p03108 | u875361824 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['def main():\n \n N, M=map(int, input().split())\n A, B =[],[]\n for i in range(M):\n a,b=map(int, input().split())\n A.append(a-1)\n B.append(b-1)\n \n uf=UnionFind(N)\n cur = N * (N-1) // 2\n res =[]\n for a,b in zip(A[::-1],B[::-1]):\n res.append(cur)\n\n if uf.issame(a, b):\n continue\n \n sa = uf.size(a) * uf.size(b)\n cur -= sa * sb\n uf.merge(a, b)\n\n print(*res, sep="¥n")\n\n\nclass UnionFind:\n def __init__(self, n):\n self.par = [-1] * n\n # void init(int n) { par.assign(n, -1); }\n\n def root(self, x):\n if self.par[x] < 0:\n return x\n else:\n self.par[x] = self.root(self.par[x])\n return self.par[x]\n \n def issame(self, x, y):\n return self.root(x) == self.root(y)\n \n def merge(self, x, y):\n x, y = self.root(x), self.root(y)\n if x == y: return False\n if self.par[x] > self.par[y]:\n x, y = y, x \n self.par[x] += self.par[y]\n self.par[y] = x\n return True\n \n def size(self, x):\n return -self.par[self.root(x)]\n\nif __name__ == "__main__":\n main()', 'def main():\n \n N, M=map(int, input().split())\n A, B =[],[]\n for i in range(M):\n a,b=map(int, input().split())\n A.append(a-1)\n B.append(b-1)\n \n uf=UnionFind(N)\n cur = N * (N-1) // 2\n res =[]\n for a,b in zip(A[::-1],B[::-1]):\n res.append(cur)\n\n if uf.issame(a, b):\n continue\n \n sa = uf.size(a) * uf.size(b)\n cur -= sa * sb\n uf.merge(a, b)\n\n print(*res, sep="¥n")\n\n\nclass UnionFind:\n def __init__(self, n):\n self.par = [-1] * n\n # void init(int n) { par.assign(n, -1); }\n\n def root(self, x):\n if self.par[x] < 0:\n return x\n else:\n self.par[x] = self.root(self.par[x])\n return self.par[x]\n \n def issame(self, x, y):\n return self.root(x) == self.root(y)\n \n def merge(self, x, y):\n x, y = self.root(x), self.root(y)\n if x == y: return False\n if self.par[x] > self.par[y]:\n x, y = y, x \n self.par[x] += self.par[y]\n self.par[y] = x\n return True\n \n def size(self, x):\n return -self.par[self.root(x)]', 'def main():\n \n N, M=map(int, input().split())\n A, B =[],[]\n for i in range(M):\n a,b=map(int, input().split())\n A.append(a-1)\n B.append(b-1)\n \n uf=UnionFind(N)\n cur = N * (N-1) // 2\n res =[]\n for a,b in zip(A[::-1],B[::-1]):\n res.append(cur)\n\n if uf.issame(a, b):\n continue\n \n sa, sb = uf.size(a), uf.size(b)\n cur -= sa * sb\n uf.merge(a, b)\n\n print(*res[::-1], sep="\\n")\n\n\nclass UnionFind:\n def __init__(self, n):\n self.par = [-1] * n\n # void init(int n) { par.assign(n, -1); }\n\n def root(self, x):\n if self.par[x] < 0:\n return x\n else:\n self.par[x] = self.root(self.par[x])\n return self.par[x]\n \n def issame(self, x, y):\n return self.root(x) == self.root(y)\n \n def merge(self, x, y):\n x, y = self.root(x), self.root(y)\n if x == y: return False\n if self.par[x] > self.par[y]:\n x, y = y, x \n self.par[x] += self.par[y]\n self.par[y] = x\n return True\n \n def size(self, x):\n return -self.par[self.root(x)]\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s139464141', 's401175381', 's414054552'] | [13444.0, 3064.0, 19128.0] | [285.0, 21.0, 653.0] | [1271, 1232, 1281] |
p03108 | u877543650 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['class Unionfind():\n def __init__(self, progsize):\n self.table = [-1 for _ in range(progsize)]\n self.size = [1 for _ in range(progsize)]\n\n def find(self, x):\n while(self.table[x] >= 0):\n x = self.table[x]\n return x\n\n def union(self, x, y):\n xl = self.find(x)\n yl = self.find(y)\n if xl != yl:\n if self.table[xl] <= self.table[yl]:\n self.table[yl] = xl\n self.table[xl] -= 1\n self.size[xl] += self.size[yl]\n else:\n self.table[xl] = yl\n self.table[yl] -= 1\n self.size[yl] += self.size[xl]\n\nn, m = [int(x) for x in input().split()]\nb = [tuple(map(int, input().split())) for _ in range(m)]\nr = []\nt = n*(n-1)//2\nds = Unionfind(n)\nfor i in range(m):\n q, p = b[-i-1]\n r.insert(0, t)\n qq, pp = ds.find(p), ds.find(q)\n if pp != qq:\n t -= ds.size[pp] * ds.size[qq]\n ds.union(p, q)\nfor x in r:\n print(x)', 'class DisjointSet():\n def __init__(self, n):\n self._p = [x for x in range(n)]\n self._size = [-1 for x in range(n)]\n self._rank = [0 for x in range(n)]\n \n def find(self, p):\n if self._p[p] != p:\n self._p[p] = self.find(self._p[p])\n return self._p[p]\n\n def union(self, p, q):\n pp, qq = self.find(p), self.find(q)\n if pp != qq:\n if self._rank[pp] > self._rank[qq]:\n self._p[qq] = pp\n self._rank[pp] += 1\n self._size[pp] += self._size[qq]\n else:\n self._p[pp] = qq\n self._rank[qq] += 1\n self._size[qq] += self._size[pp]\n \n def size(self, p):\n return self._size[self.find(p)]\n\n\nn, m = [int(x) for x in input().split()]\nb = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]\nb.reverse()\nr = []\nt = n*(n-1)//2\nds = DisjointSet(n)\nfor q, p in b:\n r.append(t)\n qq, pp = ds.find(p), ds.find(q)\n if pp != qq:\n t -= ds.size(pp) * ds.size(qq)\n ds.union(p, q)\nfor x in reversed(r):\n print(x)'] | ['Runtime Error', 'Accepted'] | ['s674543047', 's490902524'] | [20872.0, 25208.0] | [2105.0, 851.0] | [980, 1101] |
p03108 | u879870653 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['def comb(N) :\n return N*(N+1)//2\n\nclass 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 self.size = [1] * N\n self.connection = 0\n def root(self,a):\n if self.parent[a] == a:\n return a\n else:\n self.parent[a] = self.root(self.parent[a])\n return self.parent[a]\n def is_same(self,a,b):\n return self.root(a) == self.root(b)\n def unite(self,a,b):\n ra = self.root(a)\n rb = self.root(b)\n if ra == rb: return\n self.connection -= (comb(self.size[ra]) + comb(self.size[rb]))\n self.connection += comb(self.size[ra] + self.size[rb])\n if self.rank[ra] < self.rank[rb]:\n self.size[rb] += self.size[ra]\n self.parent[ra] = rb\n else:\n self.size[ra] += self.size[rb]\n self.parent[rb] = ra\n if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1\n self.count += 1\n\nN,M = map(int,input().split())\nL = [list(map(int,input().split())) for i in range(M)]\n\nUF = UnionFind(N)\n\nans = [N*(N-1)//2]\n\nfor i in range(M-1,-1,-1) :\n a,b = L[i]\n a -= 1\n b -= 1\n UF.unite(a,b)\n ans.append(ans[0] - UF.connection)\n\nprint(*ans[::-1], sep="\\n")\n', 'def comb(N) :\n return N*(N+1)//2\n\nclass 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 self.size = [1] * N\n self.connection = 0\n def root(self,a):\n if self.parent[a] == a:\n return a\n else:\n self.parent[a] = self.root(self.parent[a])\n return self.parent[a]\n def is_same(self,a,b):\n return self.root(a) == self.root(b)\n def unite(self,a,b):\n ra = self.root(a)\n rb = self.root(b)\n if ra == rb: return\n self.connection -= (comb(self.size[ra]) + comb(self.size[rb]))\n self.connection += comb(self.size[ra] + self.size[rb])\n if self.rank[ra] < self.rank[rb]:\n self.size[rb] += self.size[ra]\n self.parent[ra] = rb\n else:\n self.size[ra] += self.size[rb]\n self.parent[rb] = ra\n if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1\n self.count += 1\n\nN,M = map(int,input().split())\nL = [list(map(int,input().split())) for i in range(M)]\n\nUF = UnionFind(N)\n\nans = [N*(N-1)//2]\n\nfor i in range(M-2,-1,-1) :\n a,b = L[i]\n a -= 1\n b -= 1\n UF.unite(a,b)\n ans.append(ans[0] - UF.connection)\n\nprint(*ans[::-1], sep="\\n")', 'def comb(N) :\n return N*(N+1)//2\n\nclass 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 self.size = [1] * N\n self.connection = 0\n def root(self,a):\n if self.parent[a] == a:\n return a\n else:\n self.parent[a] = self.root(self.parent[a])\n return self.parent[a]\n def is_same(self,a,b):\n return self.root(a) == self.root(b)\n def unite(self,a,b):\n ra = self.root(a)\n rb = self.root(b)\n if ra == rb: return\n self.connection -= (comb(self.size[ra]) + comb(self.size[rb]))\n self.connection += comb(self.size[ra] + self.size[rb])\n if self.rank[ra] < self.rank[rb]:\n self.size[rb] += self.size[ra]\n self.parent[ra] = rb\n else:\n self.size[ra] += self.size[rb]\n self.parent[rb] = ra\n if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1\n self.count += 1\n\nN,M = map(int,input().split())\nL = [list(map(int,input().split())) for i in range(M)]\n\nUF = UnionFind(N)\n\nans = [N*(N-1)//2]\n\nfor i in range(M-1,-1,-1) :\n a,b = L[i]\n a -= 1\n b -= 1\n UF.unite(a,b)\n ans.append(ans[0] - UF.connection)\n\nprint(*ans[::-1][1:], sep="\\n")\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s521845223', 's959062445', 's573493007'] | [37992.0, 37996.0, 37976.0] | [794.0, 794.0, 762.0] | [1295, 1294, 1299] |
p03108 | u884982181 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['import sys\ninput = sys.stdin.readline\nn,m = map(int,input().split())\na = [list(map(int,input().split())) for i in range(m)]\n\nclass UnionFind(object):\n\n def __init__(self, N):\n self.N = N\n self.parent = list(range(self.N))\n self.rank = [0] * self.N\n self.size = [1] * self.N\n\n def find(self, x):\n if self.parent[x] != x:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[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.rank[x] < self.rank[y]:\n x, y = y, x\n\n self.size[x] += self.size[y]\n self.parent[y] = x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def count(self, x):\n return self.size[self.find(x)]\n\nuni = UnionFind(n)\nans = []\nkota = n*(n-1)/2\nans.append(kota)\nfor i in range(m-1,0,-1):\n x,y = a[i]\n x-=1;y-=1\n xs = uni.count(x)\n ys = uni.count(y)\n uni.union(x,y)\n kota -= ys*xs\n ans.append(kota)\nfor i in ans[::-1]:\n print(int(i))', 'import sys\ninput = sys.stdin.readline\nn,m = map(int,input().split())\na = [list(map(int,input().split())) for i in range(m)]\n\nclass UnionFind(object):\n\n def __init__(self, N):\n self.N = N\n self.parent = list(range(self.N))\n self.rank = [0] * self.N\n self.size = [1] * self.N\n\n def find(self, x):\n if self.parent[x] != x:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[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.rank[x] < self.rank[y]:\n x, y = y, x\n\n self.size[x] += self.size[y]\n self.parent[y] = x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def count(self, x):\n return self.size[self.find(x)]\n\nuni = UnionFind(n)\nans = []\nkota = n*(n-1)/2\nans.append(kota)\nfor i in range(m-1,0,-1):\n x,y = a[i]\n x-=1;y-=1\n xs = uni.count(x)\n ys = uni.count(y)\n if uni.find(x) == uni.find(y):\n ans.append(kota)\n continue\n uni.union(x,y)\n kota -= ys*xs\n ans.append(kota)\nfor i in ans[::-1]:\n print(int(i))'] | ['Wrong Answer', 'Accepted'] | ['s840714103', 's809459404'] | [38052.0, 38060.0] | [667.0, 718.0] | [1153, 1226] |
p03108 | u888337853 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['import sys\n\n# import math\n\n\n# import copy\n# import heapq\n# from collections import deque\n\n\n\n# INF = sys.maxsize\n# MOD = 10 ** 9 + 7\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nns = lambda: stdin.readline()\n\n\n# ===CODE===\ndef main():\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, m = map(int, input().split())\n\n ans = 0\n d = []\n for i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n d.append((a, b))\n\n d.reverse()\n ans =[]\n que = UnionFind(n)\n for i in range(m + 1):\n tmp = list(que.all_group_members().values())\n cnt = 0\n for j in range(len(tmp)):\n for k in range(j + 1, len(tmp)):\n cnt += len(tmp[j]) * len(tmp[k])\n ans.append(cnt)\n\n if i == m:\n break\n\n que.union(d[i][0], d[i][1])\n\n ans.reverse()\n print(*ans, sep="\\n")\n\nif __name__ == \'__main__\':\n main()\n', "import sys\n\n# import math\n\n\n# import copy\n# import heapq\n# from collections import deque\n\n\n\n# INF = sys.maxsize\n# MOD = 10 ** 9 + 7\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nns = lambda: stdin.readline()\n\n\n# ===CODE===\ndef main():\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, m = map(int, input().split())\n\n d = []\n for i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n d.append((a, b))\n\n d.reverse()\n ans = []\n a = n*(n-1)//2\n que = UnionFind(n)\n\n for i in range(m):\n ans.append(a)\n x,y = d[i]\n if not que.same(x,y):\n a -= que.size(x)*que.size(y)\n que.union(x,y)\n\n ans.reverse()\n for tmp_a in ans:\n print(tmp_a)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s719050855', 's553917011'] | [21416.0, 22520.0] | [2105.0, 714.0] | [2270, 2136] |
p03108 | u890183245 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['import sys\ninput = sys.stdin.readlineN,M = map(int,input().split())\nAB = [[int(x) for x in input().split()] for _ in range(M)]\n \nroot = list(range(N+1))\ncomp_size = [1] * (N+1)\n \ndef find_root(x):\n y = root[x]\n if x == y:\n return x\n z = find_root(y)\n root[x] = z\n return z\n \ndef merge(x,y):\n rx = find_root(x)\n ry = find_root(y)\n if rx == ry:\n return 0\n sx = comp_size[rx]\n sy = comp_size[ry]\n if sx > sy:\n root[ry] = rx\n comp_size[rx] += sy\n else:\n root[rx] = ry\n comp_size[ry] += sx\n return sx * sy\n \nanswer = []\nx = N*(N-1)//2\nfor a,b in AB[::-1]:\n answer.append(x)\n x -= merge(a,b)\n \nfor a in answer[::-1]:\n print(a)\nimport sys\ninput = sys.stdin.readline\n\n\n\n\nN,M = map(int,input().split())\nAB = [[int(x) for x in input().split()] for _ in range(M)]\n\nroot = list(range(N+1))\ncomp_size = [1] * (N+1)\n\ndef find_root(x):\n y = root[x]\n if x == y:\n return x\n z = find_root(y)\n root[x] = z\n return z\n\ndef merge(x,y):\n rx = find_root(x)\n ry = find_root(y)\n if rx == ry:\n return 0\n sx = comp_size[rx]\n sy = comp_size[ry]\n if sx > sy:\n root[ry] = rx\n comp_size[rx] += sy\n else:\n root[rx] = ry\n comp_size[ry] += sx\n return sx * sy\n\nanswer = []\nx = N*(N-1)//2\nfor a,b in AB[::-1]:\n answer.append(x)\n x -= merge(a,b)\n\nfor a in answer[::-1]:\n print(a)\n提出情報\n\n', 'import sys\ninput = sys.stdin.readlineN,M = map(int,input().split())\nAB = [[int(x) for x in input().split()] for _ in range(M)]\n \nroot = list(range(N+1))\ncomp_size = [1] * (N+1)\n \ndef find_root(x):\n y = root[x]\n if x == y:\n return x\n z = find_root(y)\n root[x] = z\n return z\n \ndef merge(x,y):\n rx = find_root(x)\n ry = find_root(y)\n if rx == ry:\n return 0\n sx = comp_size[rx]\n sy = comp_size[ry]\n if sx > sy:\n root[ry] = rx\n comp_size[rx] += sy\n else:\n root[rx] = ry\n comp_size[ry] += sx\n return sx * sy\n \nanswer = []\nx = N*(N-1)//2\nfor a,b in AB[::-1]:\n answer.append(x)\n x -= merge(a,b)\n \nfor a in answer[::-1]:\n print(a)\nimport sys\ninput = sys.stdin.readline\n\n\n\n\nN,M = map(int,input().split())\nAB = [[int(x) for x in input().split()] for _ in range(M)]\n\nroot = list(range(N+1))\ncomp_size = [1] * (N+1)\n\ndef find_root(x):\n y = root[x]\n if x == y:\n return x\n z = find_root(y)\n root[x] = z\n return z\n\ndef merge(x,y):\n rx = find_root(x)\n ry = find_root(y)\n if rx == ry:\n return 0\n sx = comp_size[rx]\n sy = comp_size[ry]\n if sx > sy:\n root[ry] = rx\n comp_size[rx] += sy\n else:\n root[rx] = ry\n comp_size[ry] += sx\n return sx * sy\n\nanswer = []\nx = N*(N-1)//2\nfor a,b in AB[::-1]:\n answer.append(x)\n x -= merge(a,b)\nfor a in answer[::-1]:\n print(a)', 'import sys\ninput = sys.stdin.readlineN,M = map(int,input().split())\nAB = [[int(x) for x in input().split()] for _ in range(M)]\n \nroot = list(range(N+1))\ncomp_size = [1] * (N+1)\n \ndef find_root(x):\n y = root[x]\n if x == y:\n return x\n z = find_root(y)\n root[x] = z\n return z\n \ndef merge(x,y):\n rx = find_root(x)\n ry = find_root(y)\n if rx == ry:\n return 0\n sx = comp_size[rx]\n sy = comp_size[ry]\n if sx > sy:\n root[ry] = rx\n comp_size[rx] += sy\n else:\n root[rx] = ry\n comp_size[ry] += sx\n return sx * sy\n \nanswer = []\nx = N*(N-1)//2\nfor a,b in AB[::-1]:\n answer.append(x)\n x -= merge(a,b)\n \nfor a in answer[::-1]:\n print(a)\nimport sys\ninput = sys.stdin.readline\n\n\n\n\nN,M = map(int,input().split())\nAB = [[int(x) for x in input().split()] for _ in range(M)]\n\nroot = list(range(N+1))\ncomp_size = [1] * (N+1)\n\ndef find_root(x):\n y = root[x]\n if x == y:\n return x\n z = find_root(y)\n root[x] = z\n return z\n\ndef merge(x,y):\n rx = find_root(x)\n ry = find_root(y)\n if rx == ry:\n return 0\n sx = comp_size[rx]\n sy = comp_size[ry]\n if sx > sy:\n root[ry] = rx\n comp_size[rx] += sy\n else:\n root[rx] = ry\n comp_size[ry] += sx\n return sx * sy\n\nanswer = []\nx = N*(N-1)//2\nfor a,b in AB[::-1]:\n answer.append(x)\n x -= merge(a,b)\n\nfor a in answer[::-1]:\n print(a)', 'import sys\ninput = sys.stdin.readline\n \nN,M = map(int,input().split())\nAB = [[int(x) for x in input().split()] for _ in range(M)]\n \nroot = list(range(N+1))\ncomp_size = [1] * (N+1)\n \ndef find_root(x):\n y = root[x]\n if x == y:\n return x\n z = find_root(y)\n root[x] = z\n return z\n \ndef merge(x,y):\n rx = find_root(x)\n ry = find_root(y)\n if rx == ry:\n return 0\n sx = comp_size[rx]\n sy = comp_size[ry]\n if sx > sy:\n root[ry] = rx\n comp_size[rx] += sy\n else:\n root[rx] = ry\n comp_size[ry] += sx\n return sx * sy\n \nanswer = []\nx = N*(N-1)//2\nfor a,b in AB[::-1]:\n answer.append(x)\n x -= merge(a,b)\nfor a in answer[::-1]:\n print(a)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s185956305', 's193736528', 's460743019', 's054248853'] | [3192.0, 3192.0, 3192.0, 28720.0] | [18.0, 22.0, 18.0, 392.0] | [1379, 1363, 1364, 655] |
p03108 | u898967808 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['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\nn,m = map(int,input().split())\nuf = UnionFind(n)\n\nA = [0]*m\nB = [0]*m\n\nfor i in range(m):\n a,b = map(int,input().split())\n A[i],B[i] = a-1, b-1\n\ntotal = n*(n-1)//2 \nans = [] \ncost = 0\n\nfor a,b in zip(A[::-1],B[::-1]): \n if uf.size(a) == n and uf.size(b) == n: \n ans.append(0)\n continue\n \n ans.append(total - cost)\n \n if uf.same(a,b): \n c = 0\n else:\n c = 1\n \n cost += c \n uf.union(a,b)\n \nfor i in range(m):\n print(ans[i])', '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\nn,m = map(int,input().split())\nuf = UnionFind(n)\n\nA = [0]*m\nB = [0]*m\n\nfor i in range(m):\n a,b = map(int,input().split())\n A[i],B[i] = a-1, b-1\n\ntotal = n*(n-1)//2 \nans = [total] \ncost = 0\n\nfor a,b in zip(A[::-1],B[::-1]): \n if uf.same(a,b):\n ans.append(ans[-1])\n else:\n ans.append(ans[-1] - uf.size(a)*uf.size(b))\n \n uf.union(a,b)\n\nans.pop()\nfor a in ans[::-1]:\n print(a)'] | ['Wrong Answer', 'Accepted'] | ['s486642557', 's284875730'] | [17372.0, 17708.0] | [699.0, 755.0] | [1141, 1072] |
p03108 | u903460784 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['class UnionFind:\n def __init__(self,n):\n self.parent=[i for i in range(n+1)]\n self.size=[1 for _ in range(n+1)]\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 union(self,x,y):\n x=self.find(x)\n y=self.find(y)\n if x==y:\n return\n if self.size[x]<self.size[y]:\n x,y=y,x\n self.size[x]+=self.size[y]\n self.parent[y]=x\n\nn,m=map(int,input().split())\nbridge=[list(map(int,input().split())) for _ in range(m)]\nbridge.reverse()\nuf=UnionFind(n)\ndis=n*(n-1)//2\nans=[dis]\nfor a,b in bridge:\n pa,pb=uf.parent[a],uf.parent[b]\n if pa!=pb:\n dis-=uf.size[pa]*uf.size[pb]\n ans.append(dis)\n uf.union(a,b)\nfor a in reversed(ans[:-1]):\n print(a)\n', 'class UnionFind:\n def __init__(self,n):\n self.parent=[i for i in range(n+1)]\n self.size=[1 for _ in range(n+1)]\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 union(self,x,y):\n x=self.find(x)\n y=self.find(y)\n if x==y:\n return\n if self.size[x]<self.size[y]:\n x,y=y,x\n self.size[x]+=self.size[y]\n self.parent[y]=x\n\nn,m=map(int,input().split())\nbridge=[list(map(int,input().split())) for _ in range(m)]\nbridge.reverse()\nuf=UnionFind(n)\ndis=n*(n-1)//2\nans=[dis]\nfor a,b in bridge:\n pa,pb=uf.find(a),uf.find(b)\n if pa!=pb:\n dis-=uf.size[pa]*uf.size[pb]\n ans.append(dis)\n uf.union(a,b)\nfor a in reversed(ans[:-1]):\n print(a)'] | ['Wrong Answer', 'Accepted'] | ['s528000236', 's100787133'] | [35032.0, 34976.0] | [702.0, 725.0] | [923, 918] |
p03108 | u905203728 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['class UnionFind():\n def __init__(self,n):\n self.n=n\n self.root=[-1]*n\n self.rank=[-1]*n\n\n def Find_Root(self,x):\n if self.root[x]<0:return x\n else:\n self.root[x]=self.Find_Root(self.root[x])\n return self.root[x]\n\n def Unite(self,x,y):\n x=self.Find_Root(x)\n y=self.Find_Root(y)\n\n if x==y:return\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 isSameGroup(self,x,y):\n return self.Find_Root(x)==self.Find_Root(y)\n\n def Count(self,x):\n return -self.root[self.Find_Root(x)]\n\n def members(self,x):\n root=self.Find_Root(x)\n return [i for i in range(self.n) if self.Find_Root(i)==root]\n\n def address(self):\n return[i for i,j in enumerate(self.root) if j<0]\n\n def group_members(self):\n return {i:self.members(i) for i in self.address()}\n\n def size(self,x):\n return -self.root[self.Find_Root(x)]\n\n\nn,m=map(int,input().split())\nAB=[list(map(int,input().split())) for i in range(m)]\nUnionFind=UnionFind(n)\nN=n*(n-1)//2\ncount=[N]\n\nfor a,b in AB[::-1]:\n s,t=UnionFind.size(a-1),UnionFind.size(b-1)\n count.append(count[-1]-s*t)\n UnionFind.Unite(a-1,b-1)\n\ncount=count[::-1]\nfor i in range(1,m+1):\n print(count[i])', 'class UnionFind():\n def __init__(self,n):\n self.n=n\n self.root=[-1]*n\n self.rank=[-1]*n\n\n def Find_Root(self,x):\n if self.root[x]<0:return x\n else:\n self.root[x]=self.Find_Root(self.root[x])\n return self.root[x]\n\n def Unite(self,x,y):\n x=self.Find_Root(x)\n y=self.Find_Root(y)\n\n if x==y:return\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 isSameGroup(self,x,y):\n return self.Find_Root(x)==self.Find_Root(y)\n\n def size(self,x):\n return -self.root[self.Find_Root(x)]\n\n\nn,m=map(int,input().split())\nAB=[list(map(int,input().split())) for i in range(m)]\nUnionFind=UnionFind(n)\ncount=[n*(n-1)//2]\n\nfor a,b in AB[::-1]:\n if UnionFind.isSameGroup(a-1,b-1):\n count.append(count[-1])\n else:\n s,t=UnionFind.size(a-1),UnionFind.size(b-1)\n count.append(count[-1]-s*t)\n UnionFind.Unite(a-1,b-1)\n\nfor i in count[::-1][1:]:\n print(i)'] | ['Wrong Answer', 'Accepted'] | ['s802724379', 's239489878'] | [37372.0, 38772.0] | [811.0, 836.0] | [1485, 1183] |
p03108 | u911575040 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['n, m = map(int, input().split())\ne = [[int(x) for x in input().split()] for _ in range(m)]\n\nu = [-1]*(n+1)\n\ndef find(x):\n return x if u[x] < 0 else find(u[x])\n\nt = n*(n-1)// 2\ns = []\n\nfor i in range(m-1,0,-1):\n a = find(e[i][0])\n b = find(e[i][1])\n if a > b:\n a, b = b, a\n if a != b:\n t -= u[a]*u[b]\n u[a] += u[b]\n u[b] = a\n s.append(t)\n\nfor i in reversed(s):\n print(i)\n', 'n, m = map(int, input().split())\ne = [[int(x) for x in input().split()] for _ in range(m)]\n\nu = [-1]*(n+1)\n\ndef find(x):\n return x if u[x] < 0 else find(u[x])\n\nt = n*(n-1)// 2\ns = [t]\n\nfor i in range(m-1,0,-1):\n a = find(e[i][0])\n b = find(e[i][1])\n if a > b:\n a, b = b, a\n if a != b:\n t -= u[a]*u[b]\n u[a] += u[b]\n u[b] = a\n s.append(t)\n\nfor i in reversed(s):\n print(i)\n'] | ['Wrong Answer', 'Accepted'] | ['s882651929', 's664233471'] | [27172.0, 27176.0] | [715.0, 705.0] | [389, 390] |
p03108 | u912862653 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['import sys\ninput = sys.stdin.readline\n\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 \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 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 \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\n\nN, M = map(int, input().split())\n A = []\n B = []\n for _ in range(M):\n a, b = map(int, input().split())\n A.append(a)\n B.append(b)\n \n T = UnionFind(N)\n ans = [0]*M\n ans[M-1] = N*(N-1)//2\n for i in reversed(range(M-1)):\n a = A[i+1]\n b = B[i+1]\n if T.isSameGroup(a, b):\n ans[i] = ans[i+1]\n else:\n ans[i] = ans[i+1] - T.Count(a) * T.Count(b)\n T.Unite(a, b)\n\n for i in range(M):\n print(ans[i])\n', 'import sys\ninput = sys.stdin.readline\n\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 \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 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 \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\n\nN, M = map(int, input().split())\nA = []\nB = []\nfor _ in range(M):\n a, b = map(int, input().split())\n A.append(a)\n B.append(b)\n\nT = UnionFind(N)\nans = [0]*M\nans[M-1] = N*(N-1)//2\nfor i in reversed(range(M-1)):\n a = A[i+1]\n b = B[i+1]\n if T.isSameGroup(a, b):\n ans[i] = ans[i+1]\n else:\n ans[i] = ans[i+1] - T.Count(a) * T.Count(b)\n T.Unite(a, b)\n\nfor i in range(M):\n print(ans[i])\n'] | ['Runtime Error', 'Accepted'] | ['s079351677', 's957061472'] | [3064.0, 17844.0] | [17.0, 654.0] | [2312, 2232] |
p03108 | u915355756 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['6 5\n2 3\n1 2\n5 6\n3 4\n4 5', '# -*- coding: utf-8 -*-\n\n# -*- coding: utf-8 -*-\n\n\nclass UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n+1)]\n self.rank = [1]* (n+1)\n self.size = [1]* (n+1)\n \n # search parents of tree\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 # union tree\n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n # parent same\n if x == y:\n return False\n \n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n return True\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 return True\n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n # size\n def sizes(self, x):\n x = self.find(x)\n return self.size[x]\n \n#[N,M] = [6,5]\n#A = [2, 1, 5, 3, 4]\n#B = [3, 2, 6, 4, 5]\n[N,M] = list(map(int,input().split()))\nA = [0]*M\nB = [0]*M\nfor i in range(M):\n [a,b] = list(map(int,input().split()))\n A[i], B[i] = a, b\n\nA.reverse()\nB.reverse()\nuf = UnionFind(N)\nans_list = [0]*M\nans_list[0] = (N*(N-1))//2\nans = ans_list[0]\nfor i in range(M-1):\n if uf.same(A[i], B[i]) == True:\n ans = ans\n else:\n ans = ans - uf.sizes(A[i])*uf.sizes(B[i])\n uf.unite(A[i],B[i])\n ans_list[i+1] = ans\n \nans_list.reverse()\nfor i in range(M):\n print(ans_list[i])'] | ['Runtime Error', 'Accepted'] | ['s604486053', 's598970040'] | [2940.0, 18504.0] | [17.0, 821.0] | [23, 1631] |
p03108 | u917733926 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['\n\n\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n+1)]\n \n self.rank = [0] * (n+1)\n \n self.size = [0] + [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 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,*t=map(int,open(0).read().split())\n\nA = [0] + t[0::2]\n\n\nB = [0] + t[1::2]\n\n\nout_ans = [0] * (M + 1)\n\n\n\nUF = UnionFind(N)\n\n\nsm=N*(N-1)//2\n\n\nout_ans[M] = sm\n\nfor i in range(M, 0, -1):\n # out_ans[i] = (ans(i, UF))\n if not UF.same_check(A[i], B[i]):\n root_a = UF.find(A[i])\n root_b = UF.find(B[i])\n UF.union(A[i], B[i])\n tmp = UF.size[root_a] + UF.size[root_b]\n UF.size[root_a] = tmp\n UF.size[root_b] = tmp\n out_ans[i-1] = sm\n\n[print(tmp) for tmp in out_ans[1:]]', '\n\n\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n+1)]\n \n self.rank = [0] * (n+1)\n \n self.size = [0] + [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 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 \n def get_size(self, x):\n return self.size[x]\n\n\nN,M,*t=map(int,open(0).read().split())\n\nA = [0] + t[0::2]\n\n\nB = [0] + t[1::2]\n\n\nout_ans = [0] * (M + 1)\n\n\n\nUF = UnionFind(N)\n\n\nsm=N*(N-1)//2\n\n\nout_ans[M] = sm\n\nfor i in range(M, 0, -1):\n # out_ans[i] = (ans(i, UF))\n if not UF.same_check(A[i], B[i]):\n root_a = UF.find(A[i])\n root_b = UF.find(B[i])\n UF.union(A[i], B[i])\n sm -= UF.get_size(root_a) * UF.get_size(root_b)\n UF.size[root_a] = UF.size[root_b] = UF.size[root_a] * UF.size[root_b] \n out_ans[i-1] = sm\n\n[print(tmp) for tmp in out_ans[1:]]', '\n\n\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n+1)]\n \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 \n def size(self, x):\n return -self.par[self.find(x)]\n\n\nN,M,*t=map(int,open(0).read().split())\n\nA = [0] + t[0::2]\n\n\nB = [0] + t[1::2]\n\n\nout_ans = [0] * (M + 1)\n\n\n\n\nUF = UnionFind(N)\n\n\ndef ans(i, UF):\n global N,A,B,out_ans\n if UF.same_check(A[i+1], B[i+1]):\n return out_ans[i+1]\n else:\n n1 = UF.size(A[i+1])\n n2 = UF.size(B[i+1])\n UF.union(A[i+1], B[i+1])\n return out_ans[i+1] - (n1 * n2)\n\n\n\nout_ans[M] = ( (N * (N - 1) )// 2)\n\nfor i in range(M-1, 0, -1):\n out_ans[i] = (ans(i, UF))\n\nfor tmp in out_ans[1:]:\n print(tmp)', '\n\n\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n+1)]\n \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 \n def size(self, x):\n return self.par.count(self.find(x))\n\n\nN,M,*t=map(int,open(0).read().split())\n\nA = [0] + t[0::2]\n\n\nB = [0] + t[1::2]\n\n\nout_ans = [0] * (M + 1)\n\n\n\n\nUF = UnionFind(N)\n\n\ndef ans(i, UF):\n global N,A,B,out_ans\n if UF.same_check(A[i+1], B[i+1]):\n return out_ans[i+1]\n else:\n n1 = UF.size(A[i+1])\n n2 = UF.size(B[i+1])\n UF.union(A[i+1], B[i+1])\n return out_ans[i+1] - (n1 * n2)\n\n\n\nout_ans[M] = (N * (N - 1) // 2)\n\nfor i in range(M-1, 0, -1):\n out_ans[i] = (ans(i, UF))\n\nfor tmp in out_ans:\n print(tmp)', '\n\n\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n+1)]\n \n self.rank = [0] * (n+1)\n \n self.size = [0] + [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 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 \n def get_size(self, x):\n return self.size[x]\n\n\nN,M,*t=map(int,open(0).read().split())\n\nA = [0] + t[0::2]\n\n\nB = [0] + t[1::2]\n\n\nout_ans = [0] * (M + 1)\n\n\n\n\nUF = UnionFind(N)\n\n\n# def ans(i, UF):\n# global N,A,B,out_ans\n# if UF.same_check(A[i+1], B[i+1]):\n# return out_ans[i+1]\n# else:\n# n1 = UF.get_size(A[i+1])\n# n2 = UF.get_size(B[i+1])\n# UF.union(A[i+1], B[i+1])\n# return out_ans[i+1] - (n1 * n2)\n\n\n\nsm=N*(N-1)//2\n\nout_ans[M] = sm\n\ngroup=[1]*(N+1)\n\nfor i in range(M-1, 0, -1):\n # out_ans[i] = (ans(i, UF))\n if not UF.same_check(A[i], B[i]):\n grpa = UF.find(A[i])\n grpb = UF.find(B[i])\n UF.union(A[i], B[i])\n sm -= group[grpa] * group[grpb]\n group[grpa] = group[grpb] = group[grpa] + group[grpb]\n out_ans[i] = sm\n\n[print(tmp) for tmp in out_ans]', '\n\n\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n+1)]\n \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 \n def size(self, x):\n return -self.parent[self.find(x)]\n\n\nN,M,*t=map(int,open(0).read().split())\n\nA = [0] + t[0::2]\n\n\nB = [0] + t[1::2]\n\n\nout_ans = [0] * (M + 1)\n\n\n\n\nUF = UnionFind(N)\n\n\ndef ans(i, UF):\n global N,A,B,out_ans\n if UF.same_check(A[i+1], B[i+1]):\n return out_ans[i+1]\n else:\n n1 = UF.size(A[i+1])\n n2 = UF.size(B[i+1])\n UF.union(A[i+1], B[i+1])\n return out_ans[i+1] - (n1 * n2)\n\n\n\nout_ans[M] = ( (N * (N - 1) )// 2)\n\nfor i in range(M-1, 0, -1):\n out_ans[i] = (ans(i, UF))\n\nfor tmp in out_ans[1:]:\n print(tmp)', '\n\n\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [i for i in range(n+1)]\n \n self.rank = [0] * (n+1)\n \n self.size = [0] + [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 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,*t=map(int,open(0).read().split())\n\nA = [0] + t[0::2]\n\n\nB = [0] + t[1::2]\n\n\nout_ans = [0] * (M + 1)\n\n\n\nUF = UnionFind(N)\n\n\nsum=N*(N-1)//2\n\n\nout_ans[M] = sum\n\nfor i in range(M, 0, -1):\n # out_ans[i] = (ans(i, UF))\n if not UF.same_check(A[i], B[i]):\n root_a = UF.find(A[i])\n root_b = UF.find(B[i])\n UF.union(A[i], B[i])\n sum -= UF.size[root_a] * UF.size[root_b]\n tmp = UF.size[root_a] + UF.size[root_b]\n UF.size[root_a] = tmp\n UF.size[root_b] = tmp\n out_ans[i-1] = sum\n\n[print(tmp) for tmp in out_ans[1:]]'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s091441379', 's122158054', 's154378092', 's366043046', 's549505468', 's680694393', 's731447495'] | [25332.0, 25260.0, 25332.0, 25260.0, 25360.0, 25308.0, 25416.0] | [516.0, 636.0, 551.0, 2105.0, 571.0, 78.0, 569.0] | [1833, 1959, 1885, 1883, 2237, 1888, 1885] |
p03108 | u918935103 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['def find(parent,i):\n t = parent[i]\n if t < 0:\n return i\n else:\n t = find(parent,i)\n parent[i] = t\n return t\ndef unite(parent,i,j):\n i = find(parent,i)\n j = find(parent,j)\n if i == j:\n return\n else:\n parent[j] += parent[i]\n parent[i] = j\nn,m = map(int,input().split())\nparent = [-1] * n\nans = n*(n-1)//2\nansl = []\nl0 = []\nfor i in range(m):\n ab = list(map(int,input().split()))\n l0.append(ab)\nl0.reverse()\nfor i in range(m):\n ansl.append(ans)\n if find(parent,l0[i][0]) != find(parent,l0[i][1]):\n ans -= parent[find(parent,l0[i][0])] * parent[find(parent,l0[i][1])]\n unite(parent,l0[i][0],l0[i][1])\nansl.reverse()\nfor i in range(m):\n print(ansl[i])', 'import sys\nsys.setrecursionlimit(10 ** 5)\ndef find(parent,i):\n t = parent[i]\n if t < 0:\n return i\n t = find(parent,t)\n parent[i] = t\n return t\ndef unite(parent,i,j):\n i = find(parent,i)\n j = find(parent,j)\n if i == j:\n return\n parent[j] += parent[i]\n parent[i] = j\nn,m = map(int,input().split())\nparent = [-1] * n\nans = n*(n-1)//2\nansl = []\nl0 = []\nfor i in range(m):\n ab = list(map(int,input().split()))\n ab[0] -= 1\n ab[1] -= 1\n l0.append(ab)\nl0.reverse()\nfor i in range(m):\n ansl.append(ans)\n a,b = l0[i]\n if find(parent,a) != find(parent,b):\n ans -= parent[find(parent,a)] * parent[find(parent,b)]\n unite(parent,a,b)\nansl.reverse()\nfor i in range(m):\n print(ansl[i])'] | ['Runtime Error', 'Accepted'] | ['s928229545', 's255538483'] | [29108.0, 44324.0] | [432.0, 754.0] | [741, 747] |
p03108 | u922901775 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['#!/usr/bin/env python3\nimport sys\n\n\nclass UnionFind(object):\n __slots__ = ["nodes"]\n\n def __init__(self, n: int):\n self.nodes = [-1]*n \n\n def find(self, x: int) -> int:\n if self.nodes[x] < 0:\n return x\n else:\n self.nodes[x] = self.find(self.nodes[x]) # compression\n return self.nodes[x]\n\n def has_same_root(self, x, y) -> bool:\n return self.find(x) == self.find(y)\n \n def size(self, x) -> int:\n return -self.nodes(self.find(x))\n\n def unite(self, x: int, y: int) -> None:\n if self.has_same_root(x, y):\n return\n\n root_x, root_y = self.find(x), self.find(y)\n if self.nodes[root_x] < self.nodes[root_y]:\n bigroot, smallroot = (root_x, root_y)\n else: \n bigroot, smallroot = (root_y, root_x)\n self.nodes[bigroot] += self.nodes[smallroot]\n self.nodes[smallroot] = bigroot\n\n\ndef solve(N: int, M: int, A: "List[int]", B: "List[int]"):\n count = [0] \n UFT = UnionFind(N)\n\n for i in range(1, M+1):\n a, b = A[-i], B[-i]\n if UFT.has_same_root(a, b):\n count.append(count[-1])\n continue\n count.append(count[-1] + UFT.size(a) * UFT.size(b))\n UFT.unite(a, b)\n\n for i in range(M):\n print(count[-1] - count[-(i+2)])\n return\n\n\n# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n M = int(next(tokens)) # type: int\n A = [int()] * (M) # type: "List[int]" \n B = [int()] * (M) # type: "List[int]" \n for i in range(M):\n A[i] = int(next(tokens))-1\n B[i] = int(next(tokens))-1\n solve(N, M, A, B)\n\nif __name__ == \'__main__\':\n main()\n', '#!/usr/bin/env python3\nimport sys\n\n\nclass UnionFind(object):\n __slots__ = ["nodes"]\n\n def __init__(self, n: int):\n self.nodes = [-1]*n \n\n def find(self, x: int) -> int:\n if self.nodes[x] < 0:\n return x\n else:\n self.nodes[x] = self.find(self.nodes[x]) # compression\n return self.nodes[x]\n\n def has_same_root(self, x, y) -> bool:\n return self.find(x) == self.find(y)\n \n def size(self, x) -> int:\n return -self.nodes[self.find(x)]\n\n def unite(self, x: int, y: int) -> None:\n if self.has_same_root(x, y):\n return\n\n root_x, root_y = self.find(x), self.find(y)\n if self.nodes[root_x] < self.nodes[root_y]:\n bigroot, smallroot = (root_x, root_y)\n else: \n bigroot, smallroot = (root_y, root_x)\n self.nodes[bigroot] += self.nodes[smallroot]\n self.nodes[smallroot] = bigroot\n\n\ndef solve(N: int, M: int, A: "List[int]", B: "List[int]"):\n count = [0] \n UFT = UnionFind(N)\n\n for i in range(1, M+1):\n a, b = A[-i], B[-i]\n if UFT.has_same_root(a, b):\n count.append(count[-1])\n continue\n count.append(count[-1] + UFT.size(a) * UFT.size(b))\n UFT.unite(a, b)\n\n for i in range(M):\n print(count[-1] - count[-(i+2)])\n return\n\n\n# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n M = int(next(tokens)) # type: int\n A = [int()] * (M) # type: "List[int]" \n B = [int()] * (M) # type: "List[int]" \n for i in range(M):\n A[i] = int(next(tokens))-1\n B[i] = int(next(tokens))-1\n solve(N, M, A, B)\n\nif __name__ == \'__main__\':\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s489677001', 's905157807'] | [11764.0, 17632.0] | [132.0, 633.0] | [2173, 2173] |
p03108 | u923341003 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['N, M = list(map(int,input().split()))\nA = []\nB = []\nfor i in range(M):\n A1,B1=[int(i) for i in input().split()]\n A.append(A1)\n B.append(B1)\nA.reverse()\nB.reverse()\n\nclass UnionFind(object):\n def __init__(self, n=1):\n self.par = [i for i in range(n+1)]\n self.rank = [0 for _ in range(n+1)]\n self.size = [1 for _ in range(n+1)]\n \n def find(self, x):\n \n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def union(self, x, y):\n \n x = self.find(x)\n y = self.find(y)\n if x != y:\n x_size = self.size[x]\n y_size = self.size[y]\n sum_size = x_size + y_size\n self.size[x] = sum_size\n self.size[y] = sum_size\n \n if self.rank[x] < self.rank[y]:\n x, y = y, x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n self.par[y] = x\n\n def is_same(self, x, y):\n \n return self.find(x) == self.find(y)\n \n def get_size(self, a):\n x = self.find(a)\n return self.size[x]\n\nuf = UnionFind(N)\nanses = []\nans = int(N * (N-1) / 2)\nanses.append(ans)\n\nfor k in range(len(A)-1):\n if uf.is_same(A[k], B[k]):\n anses.append(anses[k])\n print(anses)\n else:\n N1 = uf.get_size(A[k])\n N2 = uf.get_size(B[k])\n ans = anses[k] - (N1 * N2)\n if ans < 0:\n ans = 0\n uf.union(A[k], B[k])\n anses.append(ans)\n \nfor ans in reversed(anses):\n print(ans)', 'N, M = list(map(int,input().split()))\nA = []\nB = []\nfor i in range(M):\n A1,B1=[int(i) for i in input().split()]\n A.append(A1)\n B.append(B1)\nA.reverse()\nB.reverse()\n\nclass UnionFind(object):\n def __init__(self, n=1):\n self.par = [i for i in range(n+1)]\n self.rank = [0 for _ in range(n+1)]\n self.size = [1 for _ in range(n+1)]\n \n def find(self, x):\n \n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def union(self, x, y):\n \n x = self.find(x)\n y = self.find(y)\n if x != y:\n x_size = self.size[x]\n y_size = self.size[y]\n sum_size = x_size + y_size\n self.size[x] = sum_size\n self.size[y] = sum_size\n \n if self.rank[x] < self.rank[y]:\n x, y = y, x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n self.par[y] = x\n\n def is_same(self, x, y):\n \n return self.find(x) == self.find(y)\n \n def get_size(self, a):\n x = self.find(a)\n return self.size[x]\n \nuf = UnionFind(N)\nanses = []\nans = int(N * (N-1) / 2)\nanses.append(ans)\n\nfor k in range(len(A)-1):\n if uf.is_same(A[k], B[k]):\n anses.append(anses[k])\n print(anses)\n else:\n N1 = uf.get_size(A[k])\n N2 = uf.get_size(B[k])\n ans = anses[k] - (N1 * N2)\n if ans < 0:\n ans = 0\n uf.union(A[k], B[k])\n anses.append(ans)\n \nfor ans in reversed(anses):\n print(ans)', 'N, M = list(map(int,input().split()))\nA = []\nB = []\nfor i in range(M):\n A1,B1=[int(i) for i in input().split()]\n A.append(A1)\n B.append(B1)\nA.reverse()\nB.reverse()\n\nuf = UnionFind(N)\nanses = []\nans = int(N * (N-1) / 2)\nanses.append(ans)\n\nfor k in range(len(A)-1):\n if uf.is_same(A[k], B[k]):\n anses.append(anses[k])\n print(anses)\n else:\n N1 = uf.get_size(A[k])\n N2 = uf.get_size(B[k])\n ans = anses[k] - (N1 * N2)\n if ans < 0:\n ans = 0\n uf.union(A[k], B[k])\n anses.append(ans)\n \nfor ans in reversed(anses):\n print(ans)', 'N, M = list(map(int,input().split()))\nA = []\nB = []\nfor i in range(M):\n A1,B1=[int(i) for i in input().split()]\n A.append(A1)\n B.append(B1)\nA.reverse()\nB.reverse()\n\nclass UnionFind(object):\n def __init__(self, n=1):\n self.par = [i for i in range(n+1)]\n self.rank = [0 for _ in range(n+1)]\n self.size = [1 for _ in range(n+1)]\n \n def find(self, x):\n \n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def union(self, x, y):\n \n x = self.find(x)\n y = self.find(y)\n if x != y:\n x_size = self.size[x]\n y_size = self.size[y]\n sum_size = x_size + y_size\n self.size[x] = sum_size\n self.size[y] = sum_size\n \n if self.rank[x] < self.rank[y]:\n x, y = y, x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n self.par[y] = x\n\n def is_same(self, x, y):\n \n return self.find(x) == self.find(y)\n \n def get_size(self, a):\n x = self.find(a)\n return self.size[x]\n\nuf = UnionFind(N)\nanses = []\nans = int(N * (N-1) / 2)\nanses.append(ans)\n\nfor k in range(len(A)-1):\n if uf.is_same(A[k], B[k]):\n anses.append(anses[k])\n else:\n N1 = uf.get_size(A[k])\n N2 = uf.get_size(B[k])\n ans = anses[k] - (N1 * N2)\n if ans < 0:\n ans = 0\n uf.union(A[k], B[k])\n anses.append(ans)\n \nfor ans in reversed(anses):\n print(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s489660652', 's710644347', 's892058327', 's087142132'] | [147036.0, 147052.0, 11068.0, 21628.0] | [2105.0, 2105.0, 318.0, 841.0] | [1802, 1808, 613, 1781] |
p03108 | u940102677 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | [',m = map(int,input().split())\na = [0]*m\nb = [0]*m\nfor i in range(m):\n a[i], b[i] = map(int,input().split())\n\nd = [0]*(n+1)\nfor i in range(1,n+1):\n d[i] = i\n \ns = [0] + [1]*n\n\ng=[ [0] ]*(n+1)\nfor i in range(1,n+1):\n g[i] = [i]\ng[0] = []\n#print(g)\n#quit()\n\nc = n*(n-1)//2\nans = []\nans.append(c)\n\nfor i in range(1,m)[::-1]:\n x = d[a[i]]\n y = d[b[i]]\n if x == y:\n ans.append(c)\n continue\n c -= s[x]*s[y]\n #print(c, "x")\n ans.append(c)\n s[x] += s[y]\n s[y] = 0\n for i in g[y]:\n d[i] = x\n g[x] = g[x] + g[y]\n g[y] = []\nfor t in ans[::-1]:\n print(t)\n ', 'n,m = map(int,input().split())\na = [0]*m\nb = [0]*m\nfor i in range(m):\n a[i], b[i] = map(int,input().split())\n\nd = list(range(n+1))\ng = [[i] for i in range(n+1)]\n\nc = n*(n-1)//2\nans = [c]\n\nfor i in range(1,m)[::-1]:\n x = d[a[i]]\n y = d[b[i]]\n x,y = max(x,y),min(x,y)\n if x > y:\n c -= len(g[x])*len(g[y])\n for i in g[y]:\n d[i] = x\n g[x] += g[y]\n ans.append(c)\n\nfor t in ans[::-1]:\n print(t)'] | ['Runtime Error', 'Accepted'] | ['s288743294', 's046537072'] | [2940.0, 39796.0] | [18.0, 720.0] | [569, 409] |
p03108 | u946996108 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['mod = 10 ** 9 + 7\nmod2 = 2 ** 61 + 1\nfrom collections import deque\nimport heapq\nfrom bisect import bisect_left, insort_left, bisect_right\n\n_NUMINT_ALL = list(range(10))\n\n\ndef main():\n ans = solve()\n\n if ans is True or ans is False:\n YesNo(ans)\n elif ans is not None:\n print(ans)\n\nclass UfNode():\n def __init__(self, id):\n self.parent = None\n self.id = id\n self._size = 1\n\n @property\n def size(self):\n if not self.parent:\n return self._size\n else:\n return self.root()._size\n\n def root(self):\n if not self.parent:\n return self\n else:\n return self.parent.root()\n\n def sizeup(self, n):\n if not self.parent:\n self._size += n\n else:\n self.root().sizeup(n)\n\n def unite(self, target):\n sr = self.root().id\n tr = target.root().id\n if sr == tr:\n return False\n elif sr > tr:\n target.sizeup(self.size)\n self.root().parent = target.root()\n else:\n self.sizeup(target.size)\n target.root().parent = self.root()\n\nclass UfTree():\n def __init__(self, maxnum):\n self.parent = [None for _ in range(maxnum)]\n self._size = [1 for _ in range(maxnum)]\n\n def size(self, a):\n return self._size[self.root(a)]\n\n def root(self, a):\n cur = a\n path = []\n while True:\n if self.parent[cur] is None:\n for i in path: \n self.parent[i] = cur\n return cur\n else:\n cur = self.parent[cur]\n path.append(cur)\n\n def unite(self, a, b):\n ra = self.root(a)\n rb = self.root(b)\n if ra == rb:\n return self\n r1, r2 = (min(ra, rb), max(ra, rb))\n self._size[r1] += self._size[r2]\n self.parent[r2] = r1\n\n\n\ndef solve():\n N, M = iip(False)\n AB = iipt(M)\n AB.reverse()\n\n nroot = {}\n\n uf = UfTree(N)\n benlist = [0]\n\n cur = 0\n for a, b in AB:\n a -= 1\n b -= 1\n c1 = uf.size(a)\n c2 = uf.size(b)\n uf.unite(a, b)\n if c2 != uf.size(a):\n cur += c1*c2\n benlist.append(cur)\n\n t = benlist.pop()\n benlist.reverse()\n \n\n ans = [t - i for i in benlist]\n split_print_enter(ans)\n\n\n\n\n\n\ndef kiriage_warizan(a, b):\n return -(-a//b)\n\n\ndef iip(listed=True): \n d = input().split()\n try:\n ret = [int(i) for i in d]\n except:\n ret = [int(i) if i in _NUMINT_ALL else i for i in d]\n if len(ret) == 1:\n return ret[0]\n\n if len(ret) == 1 and not listed:\n return ret[0]\n return ret\n\ndef iipt(l, listed=False, num_only=True): \n ret = []\n for i in range(l):\n ret.append(iip(listed=listed))\n return ret\n\n\ndef saidai_kouyakusuu(A): \n l = len(A)\n while True:\n m = min(A)\n mx = max(A)\n if m == mx:\n return m\n\n for i in range(l):\n if A[i] % m == 0:\n A[i] = m\n else:\n A[i] %= m\n\n\ndef make_graph_edge_flat(N): \n ret = []\n for i in range(N-1):\n a, b, c = iip()\n a -= 1\n b -= 1\n ret[a].append((b, c))\n ret[b].append((a, c))\n return ret\n\n\ndef sort_tuples(l, index): \n if isinstance(l, list):\n l.sort(key=lambda x: x[index])\n return l\n else:\n l = list(l)\n return sorted(l, key=lambda x: x[index])\n\n\ndef count_elements(l): \n d = {}\n for i in l:\n if i in d:\n d[i] += 1\n else:\n d[i] = 1\n return d\n\n\ndef safeget(l, index, default="exception"): \n if index >= len(l): \n if default == "exception":\n raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))\n else:\n return default\n elif index < 0:\n if default == "exception":\n raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))\n else:\n return default\n else:\n return l[index]\n\n\ndef sortstr(s): \n return "".join(sorted(s))\n\n\ndef iip_ord(startcode="a"): \n if isinstance(startcode, str):\n startcode = ord(startcode)\n return [ord(i) - startcode for i in input()]\n\n\ndef YesNo(s): \n if s:\n print("Yes")\n else:\n print("No")\n\n\ndef fprint(s): \n for i in s:\n print(i)\n\n\ndef bitall(N): \n ret = []\n for i in range(2 ** N):\n a = []\n for j in range(N):\n a.append(i % 2)\n i //= 2\n ret.append(a)\n return ret\n\ndef split_print_space(s): \n print(" ".join([str(i) for i in s]))\n\n\ndef split_print_enter(s): \n print("\\n".join([str(i) for i in s]))\n\n\ndef soinsuu_bunkai(n): \n ret = []\n for i in range(2, int(n ** 0.5) + 1):\n while n % i == 0:\n n //= i\n ret.append(i)\n if i > n:\n break\n if n != 1:\n ret.append(n)\n return ret\n\n\ndef conbination(n, r, mod, test=False): \n if n <= 0:\n return 0\n if r == 0:\n return 1\n if r < 0:\n return 0\n if r == 1:\n return n\n ret = 1\n for i in range(n - r + 1, n + 1):\n ret *= i\n ret = ret % mod\n\n bunbo = 1\n for i in range(1, r + 1):\n bunbo *= i\n bunbo = bunbo % mod\n\n ret = (ret * inv(bunbo, mod)) % mod\n if test:\n # print(f"{n}C{r} = {ret}")\n pass\n return ret\n\n\ndef inv(n, mod): \n return power(n, mod - 2)\n\n\ndef power(n, p, mod_=mod): \n if p == 0:\n return 1\n if p % 2 == 0:\n return (power(n, p // 2, mod_) ** 2) % mod_\n if p % 2 == 1:\n return (n * power(n, p - 1, mod_)) % mod_\n\n\ndef nibutan_func(func, target, left, right, side="left"): \n l = left\n r = right\n while r-l > 1:\n x = (l+r)//2\n if func(x) == target:\n return x\n elif func(x) > target:\n r = x\n else:\n l = x\n\n if side == "left" or func(x) == target:\n return l\n else:\n return r\n\n\ndef nibutan_list(list_, target, side="left"): \n if not isinstance(list_, list):\n list_ = list(list_)\n\n l = 0\n r = len(list_)\n while r-l > 1:\n x = (l+r)//2\n if list_[x] == target:\n return x\n elif list_[x] > target:\n r = x\n else:\n l = x\n\n if side == "left" or list_[x] == target:\n return l\n else:\n return r\n\nif __name__ == "__main__":\n main()\n', 'mod = 10 ** 9 + 7\nmod2 = 2 ** 61 + 1\nfrom collections import deque\nimport heapq\nfrom bisect import bisect_left, insort_left, bisect_right\n\n_NUMINT_ALL = list(range(10))\n\n\ndef main():\n ans = solve()\n\n if ans is True or ans is False:\n YesNo(ans)\n elif ans is not None:\n print(ans)\n\nclass UfNode():\n def __init__(self, id):\n self.parent = None\n self.id = id\n self._size = 1\n\n @property\n def size(self):\n if not self.parent:\n return self.root().size\n else:\n self._size\n\n def root(self):\n if not self.parent:\n return self\n else:\n return self.parent.root()\n\n def sizeup(self, n):\n if not self.parent:\n self._size += n\n else:\n self.root().sizeup(n)\n\n def unite(self, target):\n sr = self.root().id\n tr = target.root().id\n if sr == tr:\n return\n elif sr > tr:\n target.sizeup(self.size())\n self.root().parent = target.root()\n else:\n self.sizeup(target.size())\n target.root().parent = self.root()\n\n\ndef solve():\n N, M = iip(False)\n AB = iipt(M)\n AB.reverse()\n\n nroot = {}\n\n nodes = [UfNode(i) for i in range(N)]\n benlist = [0]\n\n cur = 0\n for a, b in AB:\n a -= 1\n b -= 1\n c1 = nodes[a].size\n c2 = nodes[b].size\n nodes[b].unite(nodes[a])\n if c2 != nodes[b].size:\n cur += c1*c2\n benlist.append(cur)\n\n t = benlist.pop()\n benlist.reverse()\n \n\n ans = [t - i for i in benlist]\n split_print_enter(ans)\n\n\n\n\n\n\ndef kiriage_warizan(a, b):\n return -(-a//b)\n\n\ndef iip(listed=True): \n d = input().split()\n try:\n ret = [int(i) for i in d]\n except:\n ret = [int(i) if i in _NUMINT_ALL else i for i in d]\n if len(ret) == 1:\n return ret[0]\n\n if len(ret) == 1 and not listed:\n return ret[0]\n return ret\n\ndef iipt(l, listed=False, num_only=True): \n ret = []\n for i in range(l):\n ret.append(iip(listed=listed))\n return ret\n\n\ndef saidai_kouyakusuu(A): \n l = len(A)\n while True:\n m = min(A)\n mx = max(A)\n if m == mx:\n return m\n\n for i in range(l):\n if A[i] % m == 0:\n A[i] = m\n else:\n A[i] %= m\n\n\ndef make_graph_edge_flat(N): \n ret = []\n for i in range(N-1):\n a, b, c = iip()\n a -= 1\n b -= 1\n ret[a].append((b, c))\n ret[b].append((a, c))\n return ret\n\n\ndef sort_tuples(l, index): \n if isinstance(l, list):\n l.sort(key=lambda x: x[index])\n return l\n else:\n l = list(l)\n return sorted(l, key=lambda x: x[index])\n\n\ndef count_elements(l): \n d = {}\n for i in l:\n if i in d:\n d[i] += 1\n else:\n d[i] = 1\n return d\n\n\ndef safeget(l, index, default="exception"): \n if index >= len(l): \n if default == "exception":\n raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))\n else:\n return default\n elif index < 0:\n if default == "exception":\n raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))\n else:\n return default\n else:\n return l[index]\n\n\ndef sortstr(s): \n return "".join(sorted(s))\n\n\ndef iip_ord(startcode="a"): \n if isinstance(startcode, str):\n startcode = ord(startcode)\n return [ord(i) - startcode for i in input()]\n\n\ndef YesNo(s): \n if s:\n print("Yes")\n else:\n print("No")\n\n\ndef fprint(s): \n for i in s:\n print(i)\n\n\ndef bitall(N): \n ret = []\n for i in range(2 ** N):\n a = []\n for j in range(N):\n a.append(i % 2)\n i //= 2\n ret.append(a)\n return ret\n\ndef split_print_space(s): \n print(" ".join([str(i) for i in s]))\n\n\ndef split_print_enter(s): \n print("\\n".join([str(i) for i in s]))\n\n\ndef soinsuu_bunkai(n): \n ret = []\n for i in range(2, int(n ** 0.5) + 1):\n while n % i == 0:\n n //= i\n ret.append(i)\n if i > n:\n break\n if n != 1:\n ret.append(n)\n return ret\n\n\ndef conbination(n, r, mod, test=False): \n if n <= 0:\n return 0\n if r == 0:\n return 1\n if r < 0:\n return 0\n if r == 1:\n return n\n ret = 1\n for i in range(n - r + 1, n + 1):\n ret *= i\n ret = ret % mod\n\n bunbo = 1\n for i in range(1, r + 1):\n bunbo *= i\n bunbo = bunbo % mod\n\n ret = (ret * inv(bunbo, mod)) % mod\n if test:\n # print(f"{n}C{r} = {ret}")\n pass\n return ret\n\n\ndef inv(n, mod): \n return power(n, mod - 2)\n\n\ndef power(n, p, mod_=mod): \n if p == 0:\n return 1\n if p % 2 == 0:\n return (power(n, p // 2, mod_) ** 2) % mod_\n if p % 2 == 1:\n return (n * power(n, p - 1, mod_)) % mod_\n\n\ndef nibutan_func(func, target, left, right, side="left"): \n l = left\n r = right\n while r-l > 1:\n x = (l+r)//2\n if func(x) == target:\n return x\n elif func(x) > target:\n r = x\n else:\n l = x\n\n if side == "left" or func(x) == target:\n return l\n else:\n return r\n\n\ndef nibutan_list(list_, target, side="left"): \n if not isinstance(list_, list):\n list_ = list(list_)\n\n l = 0\n r = len(list_)\n while r-l > 1:\n x = (l+r)//2\n if list_[x] == target:\n return x\n elif list_[x] > target:\n r = x\n else:\n l = x\n\n if side == "left" or list_[x] == target:\n return l\n else:\n return r\n\nif __name__ == "__main__":\n main()\n', 'mod = 10 ** 9 + 7\nmod2 = 2 ** 61 + 1\nfrom collections import deque\nimport heapq\nimport time\nfrom bisect import bisect_left, insort_left, bisect_right\nimport sys\n\ninput = sys.stdin.readline\n_NUMINT_ALL = list(range(10))\n\n\ndef main():\n ans = solve()\n\n if ans is True or ans is False:\n YesNo(ans)\n elif ans is not None:\n print(ans)\n\n\ndef solve():\n N, M = iip(False)\n\n AB = iipt(M)\n AB.reverse()\n uf = UfTree(N)\n\n benlist = [0]\n\n cur = 0\n for a, b in AB:\n a -= 1\n b -= 1\n c1 = uf.size(a)\n c2 = uf.size(b)\n uf.unite(a, b)\n if c2 != uf.size(a):\n cur += c1*c2\n benlist.append(cur)\n\n t = benlist.pop()\n benlist.reverse()\n \n\n ans = [t - i for i in benlist]\n\n split_print_enter(ans)\n\n\n\n\ndef kiriage_warizan(a, b):\n return -(-a//b)\n\n\ndef iip(listed=True): \n d = input().rstrip("\\n").split()\n try:\n ret = [int(i) for i in d]\n except:\n ret = [int(i) if i in _NUMINT_ALL else i for i in d]\n if len(ret) == 1:\n return ret[0]\n\n if len(ret) == 1 and not listed:\n return ret[0]\n return ret\n\ndef iipt(l, listed=False, num_only=True): \n ret = []\n for i in range(l):\n ret.append(iip(listed=listed))\n return ret\n\n\ndef saidai_kouyakusuu(A): \n l = len(A)\n while True:\n m = min(A)\n mx = max(A)\n if m == mx:\n return m\n\n for i in range(l):\n if A[i] % m == 0:\n A[i] = m\n else:\n A[i] %= m\n\n\ndef make_graph_edge_flat(N): \n ret = []\n for i in range(N-1):\n a, b, c = iip()\n a -= 1\n b -= 1\n ret[a].append((b, c))\n ret[b].append((a, c))\n return ret\n\n\ndef sort_tuples(l, index): \n if isinstance(l, list):\n l.sort(key=lambda x: x[index])\n return l\n else:\n l = list(l)\n return sorted(l, key=lambda x: x[index])\n\n\ndef count_elements(l): \n d = {}\n for i in l:\n if i in d:\n d[i] += 1\n else:\n d[i] = 1\n return d\n\n\ndef safeget(l, index, default="exception"): \n if index >= len(l): \n if default == "exception":\n raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))\n else:\n return default\n elif index < 0:\n if default == "exception":\n raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))\n else:\n return default\n else:\n return l[index]\n\n\ndef sortstr(s): \n return "".join(sorted(s))\n\n\ndef iip_ord(startcode="a"): \n if isinstance(startcode, str):\n startcode = ord(startcode)\n return [ord(i) - startcode for i in input()]\n\n\ndef YesNo(s): \n if s:\n print("Yes")\n else:\n print("No")\n\n\ndef fprint(s): \n for i in s:\n print(i)\n\n\ndef bitall(N): \n ret = []\n for i in range(2 ** N):\n a = []\n for j in range(N):\n a.append(i % 2)\n i //= 2\n ret.append(a)\n return ret\n\ndef split_print_space(s): \n print(" ".join([str(i) for i in s]))\n\n\ndef split_print_enter(s): \n print("\\n".join([str(i) for i in s]))\n\n\ndef soinsuu_bunkai(n): \n ret = []\n for i in range(2, int(n ** 0.5) + 1):\n while n % i == 0:\n n //= i\n ret.append(i)\n if i > n:\n break\n if n != 1:\n ret.append(n)\n return ret\n\n\ndef conbination(n, r, mod, test=False): \n if n <= 0:\n return 0\n if r == 0:\n return 1\n if r < 0:\n return 0\n if r == 1:\n return n\n ret = 1\n for i in range(n - r + 1, n + 1):\n ret *= i\n ret = ret % mod\n\n bunbo = 1\n for i in range(1, r + 1):\n bunbo *= i\n bunbo = bunbo % mod\n\n ret = (ret * inv(bunbo, mod)) % mod\n if test:\n # print(f"{n}C{r} = {ret}")\n pass\n return ret\n\n\ndef inv(n, mod): \n return power(n, mod - 2)\n\n\ndef power(n, p, mod_=mod): \n if p == 0:\n return 1\n if p % 2 == 0:\n return (power(n, p // 2, mod_) ** 2) % mod_\n if p % 2 == 1:\n return (n * power(n, p - 1, mod_)) % mod_\n\n\ndef nibutan_func(func, target, left, right, side="left"): \n l = left\n r = right\n x = (l + r) // 2\n while r-l > 1:\n x = (l+r)//2\n if func(x) == target:\n return x\n elif func(x) > target:\n r = x\n else:\n l = x\n\n if side == "left" or func(x) == target:\n return l\n else:\n return r\n\n\ndef nibutan_list(list_, target, side="left"): \n if not isinstance(list_, list):\n list_ = list(list_)\n\n l = 0\n r = len(list_)\n x = (l + r) // 2\n while r-l > 1:\n x = (l+r)//2\n if list_[x] == target:\n return x\n elif list_[x] > target:\n r = x\n else:\n l = x\n\n if side == "left" or list_[x] == target:\n return l\n else:\n return r\n\n\nclass UfTree():\n def __init__(self, maxnum):\n self.parent = list(range(maxnum))\n self._size = [1] * maxnum\n self.rank = [0] * maxnum\n\n def size(self, a):\n return self._size[self.root(a)]\n\n def root(self, a):\n rank = 0\n cur = a\n while True:\n if self.parent[cur] == cur:\n \n # self.parent[i] = cur\n return cur\n else:\n self.parent[cur] = self.parent[self.parent[cur]]\n cur = self.parent[cur]\n rank += 1\n\n def unite(self, a, b):\n ra = self.root(a)\n rb = self.root(b)\n if ra == rb:\n return self\n\n self._size[ra] += self._size[rb]\n self.parent[rb] = ra\n return self\n\nif __name__ == "__main__":\n main()\n'] | ['Time Limit Exceeded', 'Runtime Error', 'Accepted'] | ['s107396813', 's178364387', 's209642754'] | [112648.0, 42880.0, 45044.0] | [2110.0, 473.0, 608.0] | [7794, 7050, 7074] |
p03108 | u962819039 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['N, M = map(int, input().split())\nA = []\nB = []\nfor _ in range(M):\n a, b = map(int, input().split())\n A.append(a)\n B.append(b)\nans = []\nans.append(N * (N - 1) / 2)\n\nn = [-1 for i in range(N)]\n\ndef find(x):\n if n[x] < 0:\n return x\n n[x] = find(n[x])\n return n[x]\n\ndef size(x):\n return -n[find(x)]\n\ndef unite(x, y):\n x = find(x)\n y = find(y)\n if x == y:\n return 0\n if size(x) < size(y):\n x, y = y, x\n n[x] += n[y]\n n[y] = x\n return 1\n\nfor i in range(1, M + 1):\n sab = size(A[-i] - 1) * size(B[-i] - 1)\n if unite(A[-i] - 1, B[-i] - 1) == 0:\n ans.append(ans[i - 1])\n else:\n ans.append(ans[i - 1] - sab)\nfor i in range(1, M + 2):\n print(int(ans[-i]))\n', 'N, M = map(int, input().split())\nA = []\nB = []\nfor _ in range(M):\n a, b = map(int, input().split())\n A.append(a)\n B.append(b)\nans = []\nans.append(N * (N - 1) / 2)\n\nn = [-1 for i in range(N)]\n\ndef find(x):\n if n[x] < 0:\n return x\n return n[x] = find(n[x])\n\ndef size(x):\n return -n[find(x)]\n\ndef unite(x, y):\n x = find(x)\n y = find(y)\n if x == y:\n return 0\n n[x] += n[y]\n n[y] = x\n return 1\n\nfor i in range(1, M):\n if unite(A[-i], B[-i]) == 0:\n ans.append(ans[i])\n else:\n ans.append(ans[i] - size(A[-i]) * size(B[-i]))\nfor i in range(M):\n print(ans[-i])\n', 'N, M = map(int, input().split())\nA = []\nB = []\nfor _ in range(M):\n a, b = map(int, input().split())\n A.append(a)\n B.append(b)\nans = []\nans.append(N * (N - 1) / 2)\n\nn = [-1 for i in range(N)]\n\ndef find(x):\n if n[x] < 0:\n return x\n n[x] = find(n[x])\n return n[x]\n\ndef size(x):\n return -n[find(x)]\n\ndef unite(x, y):\n x = find(x)\n y = find(y)\n if x == y:\n return 0\n if size(x) < size(y):\n x, y = y, x\n n[x] += n[y]\n n[y] = x\n return 1\n\nfor i in range(1, M + 1):\n sab = size(A[-i] - 1) * size(B[-i] - 1)\n if unite(A[-i] - 1, B[-i] - 1) == 0:\n ans.append(ans[i - 1])\n else:\n ans.append(ans[i - 1] - sab)\nfor i in range(1, M + 2):\n print(ans[-i])\n', 'N, M = map(int, input().split())\nA = []\nB = []\nfor _ in range(M):\n a, b = map(int, input().split())\n A.append(a)\n B.append(b)\nans = []\nans.append(N * (N - 1) / 2)\n\nn = [-1 for i in range(N)]\n\ndef find(x):\n if n[x] < 0:\n return x\n n[x] = find(n[x])\n return n[x]\n\ndef size(x):\n return -n[find(x)]\n\ndef unite(x, y):\n x = find(x)\n y = find(y)\n if x == y:\n return 0\n if size(x) < size(y):\n x, y = y, x\n n[x] += n[y]\n n[y] = x\n return 1\n\nfor i in range(1, M):\n sab = size(A[-i] - 1) * size(B[-i] - 1)\n if unite(A[-i] - 1, B[-i] - 1) == 0:\n ans.append(ans[i - 1])\n else:\n ans.append(ans[i - 1] - sab)\nfor i in range(1, M + 1):\n print(int(ans[-i]))\n'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s779878295', 's831454888', 's835072704', 's984813720'] | [17700.0, 2940.0, 17876.0, 17652.0] | [701.0, 18.0, 700.0, 696.0] | [735, 626, 730, 731] |
p03108 | u963903527 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['N, M = map(int, input().split())\n\ndef find_root(components, n):\n print(components, n)\n if components[n] == n:\n return n\n else:\n components[n] = find_root(components, components[n])\n return components[n]\n\nbridges = []\nfor i in range(M):\n bridges.append([int(s) - 1 for s in input().split()])\n\ncomponents = [i for i in range(N)]\ncomponents_len = [1] * N\ninconv = [int(N * (N-1) / 2)]\n\nprint(bridges)\nfor i in range(M-1, -1, -1):\n a, b = bridges[i]\n a_root, b_root = find_root(components, a), find_root(components, b)\n print(a_root, b_root)\n if a_root != b_root:\n inconv.append(inconv[-1] - components_len[a_root] * components_len[b_root])\n if components_len[a_root] < components_len[b_root]:\n a_root, b_root = b_root, a_root\n components_len[a_root] += components_len[b_root]\n components_len[b_root] = a_root\n else:\n inconv.append(inconv[-1])\n\n', "class UnionFind:\n def __init__(self, n):\n self.parent = [-1 for _ in range(n)]\n\n def root(self, x):\n \n if self.parent[x] < 0:\n return x\n self.parent[x] = self.root(self.parent[x])\n return self.parent[x]\n\n def size(self, x):\n \n return -self.parent[self.root(x)]\n\n def marge(self, x, y):\n \n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n if self.size(x) < self.size(y):\n x, y = y, x\n self.parent[x] += self.parent[y]\n self.parent[y] = x \n return True\n\nn, m = map(int, input().split())\nbridges = []\nfor i in range(m):\n bridges.append([int(s) - 1 for s in input().split()])\n\nans = [n * (n-1) // 2]\nuf = UnionFind(n)\nfor i in range(m-1, 0, -1):\n a, b = bridges[i]\n if uf.root(a) == uf.root(b):\n ans.append(ans[-1])\n else:\n size_a = uf.size(a)\n size_b = uf.size(b)\n ans.append(ans[-1] - size_a * size_b)\n uf.marge(a, b)\nans.reverse()\nprint('\\n'.join(map(str, ans)))"] | ['Runtime Error', 'Accepted'] | ['s587189430', 's943167405'] | [159004.0, 34260.0] | [2105.0, 792.0] | [935, 1203] |
p03108 | u968846084 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ["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\nn,m=map(int,input().split())\nA=[0]*m\nB=[0]*m\nfor i in range(m-1,-1,-1):\n A[i],B[i]=map(int,input().split())\n A[i]=A[i]-1\n B[i]=B[i]-1\nD=[n*(n-1)//2]\nC=UnionFind(n)\nfor i in range(m-1):\n D.append(D[-1]-C.size(A[i])*C.size(B[i]))\n C.union(A[i],B[i])\nfor i in range(m-1,-1,-1):\n print(D[i])", "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\nn,m=map(int,input().split())\nA=[0]*m\nB=[0]*m\nfor i in range(m-1,-1,-1):\n A[i],B[i]=map(int,input().split())\n A[i]=A[i]-1\n B[i]=B[i]-1\nD=[n*(n-1)//2]\nC=UnionFind(n)\nfor i in range(m-1):\n if D[-1]==0:\n D.append(0)\n elif C.find(A[i])!=C.find(B[i]):\n D.append(D[-1]-C.size(A[i])*C.size(B[i]))\n C.union(A[i],B[i])\n else:\n D.append(D[-1])\nfor i in range(m-1,-1,-1):\n print(D[i])"] | ['Wrong Answer', 'Accepted'] | ['s558391897', 's830401830'] | [17164.0, 17004.0] | [682.0, 765.0] | [1442, 1540] |
p03108 | u977389981 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['n, m = map(int, input().split())\nAB = [[int(i) for i in input().split()] for i in range(m)]\n\nclass UnionFind:\n def __init__(self, n):\n self.n = n\n self.par = [-1 for _ in range(n)]\n \n def same(self, x, y):\n return self.root(x)==self.root(y)\n \n def root(self, x):\n if self.par[x]<0:\n return x\n self.par[x] = self.root(self.par[x])\n return self.par[x]\n \n def unite(self,x,y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n \n if self.par[x] > self.par[y]:\n x,y = y,x\n \n self.par[x] += self.par[y]\n self.par[y] = x\n \n def size(self,x):\n return -self.par[self.root(x)]\n \nuf = UnionFind(n)\n\nC = []\ntmp = n * (n - 1) // 2\nC.append(tmp)\nfor i in range(m - 1, 0, -1):\n a, b = AB[i]\n a -= 1\n b -= 1\n if uf.same(a, b):\n continue\n else:\n tmp -= uf.size(a) * uf.size(b)\n C.append(tmp)\n uf.unite(a, b)\n #print(C)\n \nC.reverse()\nfor c in C:\n print(c)', 'N, M = map(int, input().split())\nN += 1\nA = [[int(i) for i in input().split()] for i in range(M)]\n \ndef dfs(x):\n if vis[x]:\n return\n vis[x] = True\n for i in range(N):\n if G[x][i]:\n dfs(i)\n \nfor i in range(M):\n vis = [False] * N\n del A[0]\n G = [[0] * N for i in range(N)]\n for i, j in A:\n G[i][j] = 1\n G[j][i] = 1\n \n cnt = 0\n for i in range(1, N):\n dfs(i)\n for i in vis[1:]:\n if i == False:\n cnt += 1\n print(cnt)', 'n, m = map(int, input().split())\nAB = [[int(i) for i in input().split()] for i in range(m)]\n\nclass UnionFind:\n def __init__(self, n):\n self.n = n\n self.par = [-1 for _ in range(n)]\n \n def same(self, x, y):\n return self.root(x)==self.root(y)\n \n def root(self, x):\n if self.par[x]<0:\n return x\n self.par[x] = self.root(self.par[x])\n return self.par[x]\n \n def unite(self,x,y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n \n if self.par[x] > self.par[y]:\n x,y = y,x\n \n self.par[x] += self.par[y]\n self.par[y] = x\n \n def size(self,x):\n return -self.par[self.root(x)]\n \nuf = UnionFind(n)\n\nC = []\ntmp = n * (n - 1) // 2\nfor i in range(m - 1, -1, -1):\n C.append(tmp)\n a, b = AB[i]\n a -= 1\n b -= 1\n if uf.same(a, b):\n continue\n else:\n tmp -= uf.size(a) * uf.size(b)\n uf.unite(a, b)\n #print(C)\n \nC.reverse()\nfor c in C:\n print(c)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s581659976', 's650806063', 's501919286'] | [28472.0, 1782260.0, 28412.0] | [782.0, 2213.0, 799.0] | [1038, 541, 1021] |
p03108 | u978313283 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['N,M=map(int,input().split())\nAB=[[0,0] for i in range(M)]\nfor i in range(M):\n AB[i][0],AB[i][1]=map(int,input().split())\npar=[i for i in range(N+1)]\nrank=[1 for i in range(N+1)]\ndef Union_Find_find(x):\n global par\n if par[x]==x:\n return x\n else:\n return Union_Find_find(par[x])\ndef Union_Find_unite(x,y):\n global par\n x=Union_Find_find(x)\n y=Union_Find_find(y)\n if x!=y:\n par[y]=x\n rank[x]=rank[x]+rank[y]\n rank[y]=1\ndef Union_Find_same(x,y):\n global par\n return Union_Find_find(x)==Union_Find_find(y)\n\ndef ncr(n):\n return n*(n-1)//2\nres=[]\nres.append(ncr(N))\nfor i in reversed(range(M)):\n if res[-1]!=0:\n if not(Union_Find_same(A,B)):\n A,B=AB[i][0],AB[i][1]\n res.append(res[-1]-rank[par[A]]*rank[par[B]])\n Union_Find_unite(A,B)\n else:\n res.append(res[-1])\n if res[-1]==0:\n res.append(0)\nfor i in reversed(range(M)):\n print(res[i])\n', 'N,M=map(int,input().split())\nAB=[[0,0] for i in range(M)]\nfor i in range(M):\n AB[i][0],AB[i][1]=map(int,input().split())\npar=[i for i in range(N+1)]\nrank=[1 for i in range(N+1)]\ndef Union_Find_find(x):\n global par\n if par[x]==x:\n return x\n else:\n return Union_Find_find(par[x])\ndef Union_Find_unite(x,y):\n global par\n x=Union_Find_find(x)\n y=Union_Find_find(y)\n if x!=y:\n par[y]=x\n rank[x]=rank[x]+rank[y]\n rank[y]=1\ndef ncr(n):\n return n*(n-1)//2\nres=[]\nres.append(ncr(N))\nfor i in reversed(range(M)):\n if res[-1]!=0:\n if !(Union_Find_same(A,B)):\n A,B=AB[i][0],AB[i][1]\n res.append(res[-1]-rank[par[A]]*rank[par[B]])\n Union_Find_unite(A,B)\n if res[-1]==0:\n res.append(0)\nfor i in reversed(range(M)):\n print(res[i])\n', 'N,M=map(int,input().split())\nAB=[[0,0] for i in range(M)]\nfor i in range(M):\n AB[i][0],AB[i][1]=map(int,input().split())\npar=[i for i in range(N+1)]\nrank=[1 for i in range(N+1)]\ndef Union_Find_find(x):\n global par\n if par[x]==x:\n return x\n else:\n return Union_Find_find(par[x])\ndef Union_Find_unite(x,y):\n global par\n x=Union_Find_find(x)\n y=Union_Find_find(y)\n if x!=y:\n par[y]=x\n rank[x]=rank[x]+rank[y]\n rank[y]=1\ndef ncr(n):\n return n*(n-1)//2\nres=[]\nres.append(ncr(N))\nfor i in reversed(range(M)):\n if res[-1]!=0:\n if !(Union_Find_unite(A,B)):\n A,B=AB[i][0],AB[i][1]\n res.append(res[-1]-rank[par[A]]*rank[par[B]])\n Union_Find_unite(A,B)\n if res[-1]==0:\n res.append(0)\nfor i in reversed(range(M)):\n print(res[i])\n', 'N,M=map(int,input().split())\nAB=[[0,0] for i in range(M)]\nfor i in range(M):\n AB[i][0],AB[i][1]=map(int,input().split())\npar=[i for i in range(N+1)]\nrank=[1 for i in range(N+1)]\ndef Union_Find_find(x):\n global par\n if par[x]==x:\n return x\n else:\n return Union_Find_find(par[x])\ndef Union_Find_unite(x,y):\n global par\n x=Union_Find_find(x)\n y=Union_Find_find(y)\n if x!=y:\n par[y]=x\n rank[x]=rank[x]+rank[y]\n rank[y]=1\n\ndef ncr(n):\n return n*(n-1)//2\nres=[]\nres.append(ncr(N))\nfor i in reversed(range(M)):\n if res[-1]!=0:\n if not(Union_Find_same(A,B)):\n A,B=AB[i][0],AB[i][1]\n res.append(res[-1]-rank[par[A]]*rank[par[B]])\n Union_Find_unite(A,B)\n else:\n res.append(res[-1])\n if res[-1]==0:\n res.append(0)\nfor i in reversed(range(M)):\n print(res[i])\n', 'N,M=map(int,input().split())\nAB=[[0,0] for i in range(M)]\nfor i in range(M):\n AB[i][0],AB[i][1]=map(int,input().split())\npar=[i for i in range(N+1)]\nrank=[1 for i in range(N+1)]\nhight=[1 for i in range(N+1)]\ndef Union_Find_find(x):\n global par,rank,hight\n if par[x]==x:\n return x\n else:\n return Union_Find_find(par[x])\ndef Union_Find_unite(x,y):\n global par,rank,hight\n x=Union_Find_find(x)\n y=Union_Find_find(y)\n if x!=y:\n if hight[x]>hight[y]:\n par[y]=x\n rank[x]=rank[x]+rank[y]\n rank[y]=rank[x]\n else:\n par[x]=y\n rank[x]=rank[x]+rank[y]\n rank[y]=rank[x]\n if hight[x]==hight[y]:\n hight[y]+=1\ndef Union_Find_same(x,y):\n global par,rank,hight\n return Union_Find_find(x)==Union_Find_find(y)\ndef ncr(n):\n return n*(n-1)//2\nres=[]\nres.append(ncr(N))\nfor i in reversed(range(M)):\n A,B=AB[i][0],AB[i][1]\n if res[-1]!=0:\n if Union_Find_same(A,B):\n res.append(res[-1])\n else:\n res.append(res[-1]-rank[A]*rank[B])\n Union_Find_unite(A,B)\n else:\n res.append(0)\nfor i in reversed(range(M)):\n print(res[i])\n', 'N,M=map(int,input().split())\nAB=[[0,0] for i in range(M)]\nfor i in range(M):\n AB[i][0],AB[i][1]=map(int,input().split())\npar=[i for i in range(N+1)]\nrank=[1 for i in range(N+1)]\ndef Union_Find_find(x):\n global par\n if par[x]==x:\n return x\n else:\n return Union_Find_find(par[x])\ndef Union_Find_unite(x,y):\n global par\n x=Union_Find_find(x)\n y=Union_Find_find(y)\n if x!=y:\n par[y]=x\n rank[x]=rank[x]+rank[y]\n rank[y]=1\n\ndef ncr(n):\n return n*(n-1)//2\nres=[]\nres.append(ncr(N))\nfor i in reversed(range(M)):\n if res[-1]!=0:\n if not(Union_Find_same(A,B)):\n A,B=AB[i][0],AB[i][1]\n res.append(res[-1]-rank[par[A]]*rank[par[B]])\n Union_Find_unite(A,B)\n if res[-1]==0:\n res.append(0)\nfor i in reversed(range(M)):\n print(res[i])\n', 'N,M=map(int,input().split())\nAB=[[0,0] for i in range(M)]\nfor i in range(M):\n AB[i][0],AB[i][1]=map(int,input().split())\npar=[i for i in range(N+1)]\nrank=[1 for i in range(N+1)]\ndef Union_Find_find(x):\n global par\n if par[x]==x:\n return x\n else:\n return Union_Find_find(par[x])\ndef Union_Find_unite(x,y):\n global par\n x=Union_Find_find(x)\n y=Union_Find_find(y)\n if x!=y:\n par[y]=x\n rank[x]=rank[x]+rank[y]\n rank[y]=1\ndef ncr(n):\n return n*(n-1)//2\nres=[]\nres.append(ncr(N))\nfor i in reversed(range(M)):\n if res[-1]!=0:\n if !(Union_Find_unite(A,B)):\n A,B=AB[i][0],AB[i][1]\n res.append(res[-1]-rank[par[A]]*rank[par[B]])\n Union_Find_unite(A,B)\n if res[-1]==0:\n res.append(0)\nfor i in reversed(range(M)):\n print(res[i])\n', 'N,M=map(int,input().split())\nAB=[[0,0] for i in range(M)]\nfor i in range(M):\n AB[i][0],AB[i][1]=map(int,input().split())\npar=[i for i in range(N+1)]\nrank=[1 for i in range(N+1)]\nhight=[1 for i in range(N+1)]\ndef Union_Find_find(x):\n global par,rank,hight\n if par[x]==x:\n return x\n else:\n return Union_Find_find(par[x])\ndef Union_Find_unite(x,y):\n global par,rank,hight\n x=Union_Find_find(x)\n y=Union_Find_find(y)\n if x!=y:\n if hight[x]>hight[y]:\n par[y]=x\n rank[x]=rank[x]+rank[y]\n rank[y]=rank[x]\n else:\n par[x]=y\n rank[x]=rank[x]+rank[y]\n rank[y]=rank[x]\n if hight[x]==hight[y]:\n hight[y]+=1\ndef Union_Find_same(x,y):\n global par,rank,hight\n return Union_Find_find(x)==Union_Find_find(y)\ndef ncr(n):\n return n*(n-1)//2\nres=[]\nres.append(ncr(N))\nfor i in reversed(range(M)):\n A,B=AB[i][0],AB[i][1]\n if res[-1]!=0:\n if Union_Find_same(A,B):\n res.append(res[-1])\n else:\n res.append(res[-1]-rank[Union_Find_find(A)]*rank[Union_Find_find(B)])\n Union_Find_unite(A,B)\n else:\n res.append(0)\nfor i in reversed(range(M)):\n print(res[i])\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s192380131', 's220619836', 's367717246', 's721741644', 's727871343', 's860374628', 's945552937', 's763356506'] | [24412.0, 3064.0, 3064.0, 24472.0, 3064.0, 24412.0, 3064.0, 30256.0] | [333.0, 17.0, 17.0, 342.0, 17.0, 335.0, 17.0, 715.0] | [974, 834, 835, 883, 1216, 837, 835, 1248] |
p03108 | u982594421 | 2,000 | 1,048,576 | There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge. Let the **inconvenience** be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining. For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses. | ['def find_index_by_value(a, val):\n for i, items in enumerate(a):\n if val in items:\n return i\n return -1\n\n\ndef num_reachable(n):\n return n * (n - 1) // 2\n\n\nn, m = map(int, input().split())\nedges = []\n\nfor _ in range(m):\n a, b = map(int, input().split())\n edges.append((a, b))\n\nsize = [1 for _ in range(n + 1)]\ngroup = [i for i in range(n + 1)]\n\n\ndef find_group(x):\n p = x\n while True:\n pp = group[p]\n if pp == p:\n break\n return pp\n\nans = []\nnot_reachable = n * (n - 1) // 2\nreachable_node = []\nans.append(not_reachable)\n\ncount = not_reachable\nreachable = 0\nfor _ in range(m - 1):\n a, b = edges.pop()\n if count > 0:\n ra = find_group(a)\n rb = find_group(b)\n if rb != ra:\n s_ra = size[ra]\n s_rb = size[rb]\n new_size = s_ra + s_rb\n reachable += num_reachable(new_size) - num_reachable(s_ra) - num_reachable(s_rb)\n size[ra] = new_size\n group[rb] = ra\n count = not_reachable - reachable\n ans.append(count)\n\nfor _ in range(len(ans)):\n print(ans.pop())', 'def find_index_by_value(a, val):\n for i, items in enumerate(a):\n if val in items:\n return i\n return -1\n\n\ndef num_reachable(n):\n return n * (n - 1) // 2\n\n\nn, m = map(int, input().split())\nedges = []\n\nfor _ in range(m):\n a, b = map(int, input().split())\n edges.append((a, b))\n\nsize = [1 for _ in range(n + 1)]\ngroup = [i for i in range(n + 1)]\n\n\ndef find_group(x):\n c = []\n p = x\n while True:\n pp = group[p]\n if pp == p:\n break\n else:\n c.append(p)\n p = pp\n for i in c:\n group[i] = pp\n return pp\n\n\n\nans = []\nnot_reachable = n * (n - 1) // 2\nreachable_node = []\nans.append(not_reachable)\n\ncount = not_reachable\nreachable = 0\nfor _ in range(m - 1):\n a, b = edges.pop()\n if count > 0:\n ra = find_group(a)\n rb = find_group(b)\n if rb != ra:\n s_ra = size[ra]\n s_rb = size[rb]\n new_size = s_ra + s_rb\n reachable += num_reachable(new_size) - num_reachable(s_ra) - num_reachable(s_rb)\n size[ra] = new_size\n group[rb] = ra\n count = not_reachable - reachable\n ans.append(count)\n\nfor _ in range(len(ans)):\n print(ans.pop())'] | ['Time Limit Exceeded', 'Accepted'] | ['s626929618', 's931452931'] | [21288.0, 21864.0] | [2105.0, 685.0] | [1115, 1292] |
p03109 | u000557170 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['# -*- coding: utf-8 -*-\n\nimport sys\n\ndef parse_input(lines_as_string = None):\n\n lines = []\n if lines_as_string is None:\n for line in sys.stdin:\n lines.append(line)\n else:\n lines = [e for e in lines_as_string.split("\\n")][1:-1]\n\n params = lines[0].split(" ")\n a = params[0]\n\n return (a)\n\n\ndef solve(s):\n\n result = "TBD"\n if s <= "2019/04/30":\n result = "Heisei"\n else:\n result = "TBD"\n\n return result\n\ndef main():\n \n\n print("%s" % solve(parse_input()))\n\nif __name__ == \'__main__\':\n\n main()\n', '# -*- coding: utf-8 -*-\n\nimport sys\n\ndef parse_input(lines_as_string = None):\n \n lines = []\n lines.append(input())\n\n params = lines[0].split(" ")\n a = params[0]\n\n return (a)\n\n\ndef solve(s):\n\n result = "TBD"\n if s <= "2019/04/30":\n result = "Heisei"\n else:\n result = "TBD"\n\n return result\n\ndef main():\n \n\n print("%s" % solve(parse_input()))\n\nif __name__ == \'__main__\':\n\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s115842161', 's216378203'] | [3060.0, 2940.0] | [17.0, 17.0] | [575, 438] |
p03109 | u002459665 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n string s;\n cin >> s;\n\n if (s <= "2019/04/30") {\n cout << "Heisei" << endl;\n } else {\n cout << "TBD" << endl;\n }\n}\n', 'def main():\n s = input()\n if s <= "2019/04/30":\n print("Heisei")\n else:\n print("TBD")\n\n\nif __name__ == \'__main__\':\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s448109510', 's757101775'] | [2940.0, 2940.0] | [17.0, 18.0] | [186, 149] |
p03109 | u003501233 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s=input()\nif s <= 2019/04/30:\n print("Heisei")\nelse:\n print("TBD")', 'import datetime\n\ns=input()\nh=datetime.date(2019,4,30)\n\nif s <= h:\n print("Heisei")\nelse:\n print("TBD")', 's=input()\nif s <= "2019/04/30":\n print("Heisei")\nelse:\n print("TBD")'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s667208579', 's734366330', 's495277504'] | [2940.0, 3440.0, 2940.0] | [17.0, 21.0, 17.0] | [68, 104, 70] |
p03109 | u007263493 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["S = input()\nYMD = S/split('/')\nMD = int(''.join(YMD[1:]))\n\nans = 'Heisei' if MD <= 430 else 'TBD'\nprint(ans)", "S = input()\nYMD = S.split('/')\nMD = int(''.join(YMD[1:]))\n\nans = 'Heisei' if MD <= 430 else 'TBD'\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s836633132', 's230606861'] | [2940.0, 2940.0] | [17.0, 17.0] | [108, 108] |
p03109 | u008273826 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s = input()\n\nl = s.split("/")\n\nn1 = int(l[0])\nn2 = int(l[1])\n\nif n1>2019:\n print("Heisei")\nelif n1<2019:\n print("TBD")\nelif n2>4:\n print("Heisei")\nelif n2<=4:\n print("TBD")\n', 's = input()\n\nl = s.split("/")\n\nn1 = int(l[0])\nn2 = int(l[1])\n\nif n1<2019:\n print("Heisei")\nelif n1>2019:\n print("TBD")\nelif n2<=4:\n print("Heisei")\nelif n2>4:\n print("TBD")\n'] | ['Wrong Answer', 'Accepted'] | ['s533102631', 's255052023'] | [3060.0, 2940.0] | [19.0, 19.0] | [185, 185] |
p03109 | u009348313 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['import datetime\nS = input()\nif datetime.datetime.strptime(S, "%Y/%m/%d") <= datetime.datetime(2019, 4, 30, 0 ,0 ,0):\n print(\'Heisei\')\nelse:\n print(\'TBD\'', 'import datetime\nS = input()\nif datetime.datetime.strptime(S, "%Y/%m/%d") <= datetime.datetime(2019, 4, 30, 0 ,0 ,0):\n print(\'Heisei\')\nelse:\n print(\'TBD\')'] | ['Runtime Error', 'Accepted'] | ['s830617683', 's588894392'] | [2940.0, 4432.0] | [17.0, 33.0] | [154, 155] |
p03109 | u011212399 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s = input()\ns = s.replace("/","")\nprint("Heisei" if s <= 20190430 else "TBD")', 's = input()\ns = s.replace("/","")\ns = int(s)\nprint("Heisei" if s <= 20190430 else "TBD")'] | ['Runtime Error', 'Accepted'] | ['s322693812', 's946398574'] | [2940.0, 2940.0] | [17.0, 18.0] | [77, 88] |
p03109 | u011634450 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\ndef dfs(cur, a, b, c):\n\tif cur == N:\n\t\treturn abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n\tret0 = dfs(cur + 1, a, b, c)\n\tret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n\tret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n\tret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n\treturn min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))', 'import datetime\nraw = input()\ndate_formatted = datetime.datetime.strptime(raw, "%Y/%m/%d")\nif date_formatted <= datetime.datetime(2019, 4, 30):\n print("Heisei")\nelse:\n print("TBD")'] | ['Runtime Error', 'Accepted'] | ['s480857685', 's415120107'] | [3064.0, 4720.0] | [18.0, 41.0] | [427, 186] |
p03109 | u013605408 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['_,m,_ = map(int,input().split("/"))\nprint("Heisei" if m > 4 else "TBD")', '_,m,_ = map(int,input().split("/"))\nprint("TBD" if m > 4 else "Heisei")'] | ['Wrong Answer', 'Accepted'] | ['s589602858', 's015685953'] | [2940.0, 2940.0] | [17.0, 17.0] | [71, 71] |
p03109 | u014139588 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s = map(str,input().split())\nif int(s[5]) == 1:\n print("TBD")\nelif int(s[6]) <= 4:\n print("Heisei")\nelse:\n print("TBD")', 's = input()\nif int(s[5]) == 1:\n print("TBD")\nelif int(s[6]) <= 4:\n print("Heisei")\nelse:\n print("TBD")'] | ['Runtime Error', 'Accepted'] | ['s426310759', 's964826928'] | [8944.0, 9084.0] | [28.0, 28.0] | [122, 105] |
p03109 | u015993380 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['y,m,d = input().split()\nprint("Heisei" if int(y+m+d) <= 20190430 else "TBD")', 's = tuple(map(int,input().split(\'/\')))\nt = tuple(2019,4,30)\nprint("Heisei" if s <= t else "TBD")', 'print("Heisei" if input() <= \'2019/04/30\' else "TBD")'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s048013326', 's073177896', 's518301374'] | [2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0] | [76, 96, 53] |
p03109 | u016182925 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['a = input()\ndate = list(a)\nyear = int(date[0])*1000 + int(date[1])*100 + int(date[2])*10 + int(date[3])\nmon = int(date[4])*10 + int(date[5])\nday = int(date[6])*10 + int(date[7])\nif year < 2019 and mon < 5 :\n print("Heise")\nelse :\n print("TBD")\n \n', 'a = input()\ndate = list(a)\nyear = int(date[0])*1000 + int(date[1])*100 + int(date[2])*10 + int(date[3])\nmon = int(date[5])*10 + int(date[6])\nday = int(date[8])*10 + int(date[9])\nif year < 2019 and mon < 5 :\n print("Heise")\nelse :\n print("TBD")\n \n', 'a = input()\ndate = list(a)\nyear = int(date[0])*1000 + int(date[1])*100 + int(date[2])*10 + int(date[3])\nmon = int(date[5])*10 + int(date[6])\nday = int(date[8])*10 + int(date[9])\nif year < 2019 or mon < 5 :\n print("Heise")\nelse :\n print("TBD")\n \n', 'a = input()\ndate = list(a)\nyear = int(date[0])*1000 + int(date[1])*100 + int(date[2])*10 + int(date[3])\nmon = int(date[5])*10 + int(date[6])\nday = int(date[8])*10 + int(date[9])\nif year < 2019 or mon < 5 :\n print("Heisei")\nelse :\n print("TBD")\n \n'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s661432093', 's898437968', 's910469413', 's921609741'] | [3060.0, 3060.0, 3060.0, 3060.0] | [18.0, 18.0, 17.0, 18.0] | [248, 248, 247, 248] |
p03109 | u016567570 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['from datetime import datetime as dt\n\ndate = dt.strptime(input(), \'%Y/%m/%d\')\n\nHeisei = dt.strptime("2019/04/30", \'%Y/%m/%d\')\n\nif date < Heisei:\n print("Heisei")\nelse:\n print("TBD")', 'from datetime import datetime as dt\n\ndate = dt.strptime(input(), \'%Y/%m/%d\')\n\nHeisei = dt.strptime("2019/04/30", \'%Y/%m/%d\')\n\nif date <= Heisei:\n print("Heisei")\nelse:\n print("TBD")'] | ['Wrong Answer', 'Accepted'] | ['s241949154', 's020577799'] | [4720.0, 4592.0] | [41.0, 42.0] | [186, 187] |
p03109 | u021548497 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['S = input()\n\nif S[5] == 0 and ((S[6] == 1) or (S[6] == 2) or (S[6] == 3) or (S[6] == 4)):\n print("Heisei")\nelse:\n print("TBD")', 'S = input()\nprint(S[5],S[6])\nif S[5] == "0" and ((S[6] == "1") or (S[6] == "2") or (S[6] == "3") or (S[6] == "4")):\n print("Heisei")\nelse:\n print("TBD")\n ', 'S = input()\nif (S[5] == "0") and ((S[6] == "1") or (S[6] == "2") or (S[6] == "3") or (S[6] == "4")):\n print("Heisei")\nelse:\n print("TBD")\n '] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s525817566', 's683611461', 's656167037'] | [2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0] | [132, 163, 148] |
p03109 | u022215787 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["import sys\ny, m, d = map(int, input().split('/'))\n\nif y < 2019:\n print('Heisei')\n sys.exit()\n\nif y == 2019 and d < 5:\n print('Heisei')\n sys.exit()\n\nprint('TBD')", "import sys\ny, m, d = map(int, input().split('/'))\n\nif y < 2019:\n print('Heisei')\n sys.exit()\n\nif y == 2019 and m < 5:\n print('Heisei')\n sys.exit()\n\nprint('TBD')"] | ['Wrong Answer', 'Accepted'] | ['s058350570', 's192220136'] | [2940.0, 2940.0] | [17.0, 18.0] | [164, 164] |
p03109 | u027403702 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['a,b,c = input().split(/)\nA = a + b + c\nif A <= "20190430" :\n print("Heisei")\nelse :\n print("TBD")', 'a,b,c = input().split("/")\nA = a + b + c\nif A <= "20190430" :\n print("Heisei")\nelse :\n print("TBD")'] | ['Runtime Error', 'Accepted'] | ['s366477296', 's340912828'] | [2940.0, 2940.0] | [17.0, 17.0] | [103, 105] |
p03109 | u027675217 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['y,m,d = map(int, input()split(/))\nif y > 2018:\n if m > 4:\n print("TBD")\nelse:\n print("Heisei")\n', 'import datetime\n\nS = input()\nans = "TBD"\ndatetime.datetime.strptime(S, \'%Y/%M/%d\')\ntbd=datetime(2019/4/30)\nif S <= tbd:\n ans="Heisei"\nprint("ans")\n', 'y,m,d = map(int, input().split("/"))\nif y > 2018 and m > 4 :\n print("TBD")\nelse:\n print("Heisei")\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s159858024', 's232441442', 's806887916'] | [2940.0, 4568.0, 2940.0] | [17.0, 33.0, 17.0] | [108, 150, 104] |
p03109 | u030649913 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["S = input()\nyear = int(S[:4])\nmonth = int(S[5:7])\nif year < 2019:\n print('Heisei')\nelif year == 2019:\n if month > 4:\n print('TBD')\n else:\n print('Heisei')\nelse:\n print('TBD'", "S = input()\nyear = int(S[:4])\nmonth = int(S[5:7])\nif year < 2019:\n print('Heisei')\nelif year == 2019:\n if month > 4:\n print('TBD')\n else:\n print('Heisei')\nelse:\n print('TBD'", "S = input()\nyear = int(S[:4])\nmonth = int(S[5:7])\nif year < 2019:\n print('Heisei')\nelif month < 5:\n print('Heisei')\nelse:\n print('TBD')"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s515421480', 's595636753', 's950024272'] | [2940.0, 2940.0, 2940.0] | [17.0, 18.0, 17.0] | [199, 199, 144] |
p03109 | u030726788 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["s = int(''.join(input.split('/')))\nif(s <= 20190430):print('Heisei')\nelse:print('TBD')", "s = int(''.join(input().split('/')))\nif(s <= 20190430):print('Heisei')\nelse:print('TBD')\n"] | ['Runtime Error', 'Accepted'] | ['s099552447', 's247892557'] | [2940.0, 2940.0] | [17.0, 17.0] | [86, 89] |
p03109 | u036340997 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['import bisect\na, b, q = map(int, input().split())\ninf = 10**18\ns = [-inf] + [int(input()) for i in range(a)] + [inf]\nt = [-inf] + [int(input()) for i in range(b)] + [inf]\n\nfor i in range(q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = inf\n for S in [s[b-1], s[b]]:\n for T in [t[d-1], t[d]]:\n d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)\n res = min(d1, d2, res)\n print(res)\n', "print('Heisei' if int(input().replace('/',''))<=20190430 else 'TBD')"] | ['Runtime Error', 'Accepted'] | ['s850773483', 's711895446'] | [3064.0, 2940.0] | [18.0, 18.0] | [438, 68] |
p03109 | u041382530 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["S=input().split('/')\nif S[1] == '4':\n\tprint('Heisei')\nelse:\n\tprint('TBD')", "S=input().split('/')\nS=[int(i) for i in S]\nif S[1] <= 4:\n\tprint('Heisei')\nelse:\n\tprint('TBD')"] | ['Wrong Answer', 'Accepted'] | ['s043922878', 's303255277'] | [2940.0, 2940.0] | [17.0, 18.0] | [73, 93] |
p03109 | u044442911 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['def main():\n N = int(input())\n lst = [input().split()for i in range(N)]\n Y = 0\n\n for i in range(0, N):\n if str(lst[i][1]) == "JPY":\n Y += float(lst[i][0])\n else:\n Y += float(lst[i][0])*380000.0\n print(Y)\n\n\nif __name__ == "__main__":\n main()\n', '\n\ndef main():\n N = int(input())\n lst = [input().split()for i in range(N)]\n Y = 0\n\n for i in range(0, N):\n if lst[i][1] == "JPY":\n Y += float(lst[i][0])\n else:\n Y += float(lst[i][0])*380000.0\n print(Y)\n\n\nif __name__ == "__main__":\n main()', 'def main():\n N = int(input())\n lst = [input().split()for i in range(N)]\n Y = 0\n\n for i in range(0, N):\n if lst[i][1] == "JPY":\n Y += float(lst[i][0])\n else:\n Y += float(lst[i][0])*380000.0\n print(Y)\n\n\nif __name__ == "__main__":\n main()\n', 'def main():\n N = int(input())\n lst = [input().split()for i in range(N)]\n Y = 0\n\n for i in range(0, N):\n if lst[i][1] == "JPY":\n Y += float(lst[i][0])\n else:\n Y += float(lst[i][0])*380000.0\n print(Y)\n\n\nif __name__ == "__main__":\n main()\n', 'from datetime import datetime\n\n\ndef main():\n S = datetime.strptime(input(), "%Y/%m/%d")\n if(S <= datetime(2019, 4, 30)):\n print("Heisei")\n else:\n print("TBD")\n\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s074940214', 's667547283', 's898500406', 's935916061', 's383763476'] | [3056.0, 3060.0, 2940.0, 3056.0, 4772.0] | [17.0, 18.0, 18.0, 18.0, 50.0] | [295, 291, 290, 290, 222] |
p03109 | u044746696 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['a,b,c=map(int,input()split("/"))\nprint("Heisei" if b*10+c<=70 else "TBD")\n ', 'a,b,c=map(int,input()split("/"))\nprint("Heisei" if b*10+c>=70 else "TBD")\n ', 'a,b,c=map(int,input().split("/"))\nprint("Heisei" if b*100+c<=70 else "TBD")\n ', 'a,b,c=map(int,input().split("/"))\nprint("Heisei" if b*100+c<=430 else "TBD")\n '] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s147222871', 's219446158', 's475936480', 's394460121'] | [2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0, 20.0] | [76, 76, 78, 79] |
p03109 | u046585946 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s=list(map(int,input().split("/")))\nif (s[0]=2019 and s[1]<=4) or (s[0]<2019):\n print("Heisei")\nelse:\n print("TBD")', 's=list(map(int,input().split("/")))\nif (s[0]==2019 and s[1]<=4) or (s[0]<2019):\n print("Heisei")\nelse:\n print("TBD")'] | ['Runtime Error', 'Accepted'] | ['s459448132', 's134679014'] | [2940.0, 2940.0] | [17.0, 17.0] | [117, 118] |
p03109 | u050698451 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["s = input().replace('/','')\nif s[4:5] == 1:\n return TBD\nelse:\n if s[5:6] > 4:\n return TBD\n else:\n return Heisei\n", "s = input().replace('/','')\nif s[4:5] == 1:\n print('TBD')\nelse:\n if s[5:6] > 4:\n print('TBD')\n else:\n print('Heisei')\n", "s = input().replace('/','')\nif s[4:5] == '1':\n print('TBD')\nelse:\n if int(s[5:6]) > 4:\n print('TBD')\n else:\n print('Heisei')\n"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s000136466', 's383291119', 's241927748'] | [2940.0, 2940.0, 2940.0] | [19.0, 17.0, 17.0] | [121, 127, 134] |
p03109 | u052499405 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s = input()\nyear = int(s[0:4])\nmonth = int(s[5:7])\n\nif yaer >= 2019 and month >= 5:\n print("TBD")\nelse:\n print("Heisei")', 's = input()\nyear = int(s[0:4])\nmonth = int(s[5:7])\n \nif year >= 2019 and month >= 5:\n print("TBD")\nelse:\n print("Heisei")'] | ['Runtime Error', 'Accepted'] | ['s295703790', 's291898521'] | [2940.0, 2940.0] | [17.0, 17.0] | [122, 123] |
p03109 | u057415180 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["s = input()\nif s[4] == '0' and s[5] == '1' or s[5] == '2'or s[5] == '3' or s[5] == '4':\n print('Heisei')\nelse:\n print('TBD')", "s = input()\nmm = int(s[5:7])\nif mm <= 4:\n print('Heisei')\nelse:\n print('TBD')"] | ['Wrong Answer', 'Accepted'] | ['s884234657', 's548612450'] | [2940.0, 2940.0] | [17.0, 17.0] | [126, 83] |
p03109 | u058592821 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["a, b, c = (int(i) for i in input().split('/'))\nn = a*1e7 + b*1e3 + c*10\nif n > 20190430:\n print('TBD')\nelse:\n print('Heisei')", "s = input().split('/')\nif int(s[0]+s[1]+s[2]) > 20190430:\n print('Heisei')\nelse:\n print('TBD')", "s = input().split('/')\nif int(s[0]+s[1]+s[2]) > 20190430:\n print('TBD')\nelse:\n print('Heisei')"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s678458113', 's705005808', 's542021783'] | [2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0] | [127, 96, 96] |
p03109 | u065188401 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["S = input()\nS = S.replace('/', '')\n\nif int(S) >= 20190501:\n print('TBD')\nelse:\n print('heisei')", "S = input()\nS = S.replace('/', '')\n\nif int(S) >= 20190501:\n print('TBD')\nelse:\n print('Heisei')"] | ['Wrong Answer', 'Accepted'] | ['s185601616', 's227163595'] | [2940.0, 2940.0] | [17.0, 17.0] | [101, 101] |
p03109 | u066692421 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['y, m, d = map(int, input().split("/"))\nif m < 5:\n print("heisei")\nelse:\n print("TBD")\n', 'y, m, d = map(int, input().split("/"))\nif m < 5:\n print("Heisei")\nelse:\n print("TBD")'] | ['Wrong Answer', 'Accepted'] | ['s392147524', 's136105677'] | [2940.0, 3064.0] | [17.0, 17.0] | [88, 91] |
p03109 | u070163338 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["s = list(map(int, input().split('/')))\nprint(s)", 's = list(map(int, input().split(\'/\')))\nif s[0] == 2018 and s[1] > 4:\n print("TBD")\nelif s[0] >2018:\n print("TBD")\nelse : print("Heisei")', 's = list(map(int, input().split(\'/\')))\nif s[0] = 2018 and s[1] > 4:\n print("TBD")\nelif s[0] >2018:\n print("TBD")\nelse : print("Heisei")', 's = list(map(int, input().split(\'/\')))\nif s[0] == 2019 and s[1] > 4:\n print("TBD")\nelif s[0] >2019:\n print("TBD")\nelse : print("Heisei")'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s187288388', 's420015484', 's715533437', 's524048949'] | [2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 18.0, 17.0, 17.0] | [47, 138, 137, 138] |
p03109 | u074445770 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["s=input()\nif(int(s[6])<=4 and s[5]==0):\n print('Heisei')\nelse:\n print('TBD') ", "s=input()\nif(int(s[6])>4 or int(s[5])==1):\n print('TBD')\nelse:\n print('Heisei') "] | ['Wrong Answer', 'Accepted'] | ['s734651776', 's707982554'] | [2940.0, 2940.0] | [17.0, 18.0] | [86, 89] |
p03109 | u076996519 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["s = input()\ns = s.remove('/').remove('/')\nif int(s) <= 20190430:\n\tprint('Heisei')\nelse:\n\tprint('TBD') ", "s = input()\ns = s.replace('/','')\nif int(s) <= 20190430:\n\tprint('Heisei')\nelse:\n\tprint('TBD') "] | ['Runtime Error', 'Accepted'] | ['s154554972', 's961952138'] | [2940.0, 2940.0] | [17.0, 17.0] | [102, 94] |
p03109 | u077019541 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['S = input().split("/")\nif S[1]<=4:\n print("Heisei")\nelse:\n print("TBD")', 'S = input().split("/")\ntuki = S[1]\nhi = S[2]\nprint(int(tuki))\nif int(tuki)<4:\n print("Heisei")\nelse:\n if int(tuki)==4 and int(hi)<=30:\n print("Heisei")\n else:\n print("TBD")', 'S = input().split("/")\ntuki = S[1]\nhi = S[2]\nprint(int(tuki))\nif int(tuki)<4:\n print("Heisei")\nelse:\n if int(tuki)==4 and hi<=30:\n print("Heisei")\n else:\n print("TBD")', 'S = input().split("/")\nif int(S[1])<=4:\n print("Heisei")\nelse:\n print("TBD")'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s286140481', 's615546934', 's754275439', 's950187502'] | [2940.0, 3068.0, 3060.0, 3060.0] | [17.0, 17.0, 17.0, 20.0] | [77, 195, 190, 82] |
p03109 | u077075933 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['year, month, day = map(int, input().split("/"))\n\nif year<2019:\n print("Heisei")\nelif year == 2019 && month<5:\n print(Heisei)\nelse:\n print("TBD")', 'year, month, day = map(int, input().split("/"))\n\nif year<2019:\n print("Heisei")\nelif year == 2019 && month<5:\n print("Heisei")\nelse:\n print("TBD")', 'year, month, day = map(int, input().split("/"))\n\nif year<2019:\n print("Heisei")\nelif year == 2019 and month<5:\n print("Heisei")\nelse:\n print("TBD")'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s123231005', 's633547190', 's472780933'] | [2940.0, 2940.0, 2940.0] | [17.0, 17.0, 18.0] | [147, 149, 150] |
p03109 | u077498363 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['import datetime\n\ny, m, d = map(int, input().split(\'/\'))\ny, m, d = map(int, dam.split(\'/\'))\nif (base_date < datetime.date(y, m, d)):\n return ("TBD")\nelse:\n return ("Heisei")', 'import datetime\n\nbase_date = datetime.date(2019, 4, 30)\ny, m, d = map(int, input().split(\'/\'))\nif (base_date < datetime.date(y, m, d)):\n return ("TBD")\nelse:\n return ("Heisei")', "print('Heisei' if input()<'2019/05/01' else 'TBD')"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s153109409', 's337156887', 's311137303'] | [2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0] | [178, 182, 50] |
p03109 | u077671720 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["def main():\n year, month, day = int(input().strip().split('/'))\n\n if year < 2019:\n print('Heisei')\n return\n \n if year == 2019:\n if month < 4:\n print('Heisei')\n return\n elif month == 4 and day <= 30:\n print('Heisei')\n return\n\n print('TBD')\n return\n\nif __name__ == '__main__':\n main()\n", "\ndef main():\n year, month, day = map(int, input().strip().split('/'))\n\n if year < 2019:\n print('Heisei')\n return\n \n if year == 2019:\n if month < 4:\n print('Heisei')\n return\n elif month == 4 and day <= 30:\n print('Heisei')\n return\n\n print('TBD')\n return\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s916226670', 's028655135'] | [2940.0, 2940.0] | [17.0, 17.0] | [376, 382] |
p03109 | u078349616 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['y, m, d = input().split("/")\nif y * 365 + m * 12 + d > 2019 * 365 + 4 * 12 + 30:\n print("TBD")\nelse:\n print("Heisei")', 'y, m, d = map(int, input().split("/"))\nif y * 365 + m * 30 + d > 2019 * 365 + 4 * 30 + 30:\n print("TBD")\nelse:\n print("Heisei")'] | ['Runtime Error', 'Accepted'] | ['s340134850', 's803487074'] | [2940.0, 2940.0] | [18.0, 17.0] | [119, 129] |
p03109 | u081823802 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['#coding:utf-8\nimport sys\n\nBAMB_NUM = 0\nBAMB_A = 0\nBAMB_B = 0\nBAMB_C = 0\nBAMB_LIST = []\n\ndef calcMP(idx, lenA, lenB, lenC):\n # when classified all bamboos\n if (idx == BAMB_NUM):\n # exists a zero length bamboo\n if (lenA <= 0 or lenB <= 0 or lenC <= 0):\n return sys.maxsize\n return abs(lenA - BAMB_A) + abs(lenB - BAMB_B) + abs(lenc - BAMB_C)\n \n # don\'t use idx-th bamboo\n mp = calcMP(idx+1, lenA, lenB, lenC)\n\n # use idx-th bamboo\n mp = min(mp, calcMP(idx + 1, lenA + BAMB_LIST[idx], lenB, lenC) + (BAMB_A > 0 ? 10 : 0))\n mp = min(mp, calcMP(idx + 1, lenA, lenB + BAMB_LIST[idx], lenC) + (BAMB_B > 0 ? 10 : 0))\n mp = min(mp, calcMP(idx + 1, lenA, lenB, lenC + BAMB_LIST[idx]) + (BAMB_C > 0 ? 10 : 0))\n\n return mp\n\nif __name__ == "__main__":\n \n # requested bamboo lengths\n bamb_num, bambA, bambB, bambC = map(lambda x: int(x), input().split())\n # available bamboo lengths\n bamb_list = []\n for bamb in range(bamb_num):\n bamb_list.append(int(input()))\n\n mp = calcMP(0, 0, 0, 0)\n print(mp)', '#coding:utf-8\nimport sys\n\nBAMB_NUM = 0\nBAMB_A = 0\nBAMB_B = 0\nBAMB_C = 0\nBAMB_LIST = []\n\ndef calcMP(idx, lenA, lenB, lenC):\n """\n calculate MP.\n """\n # when classified all bamboos\n if (idx == BAMB_NUM):\n return abs(lenA - BAMB_A) + abs(lenB - BAMB_B) + abs(lenC - BAMB_C) - 30 if min(lenA, lenB, lenC) > 0 else sys.maxsize\n \n # don\'t use idx-th bamboo\n mp1 = calcMP(idx + 1, lenA, lenB, lenC)\n # use idx-th bamboo\n mp2 = calcMP(idx + 1, lenA + BAMB_LIST[idx], lenB, lenC) + 10\n mp3 = calcMP(idx + 1, lenA, lenB + BAMB_LIST[idx], lenC) + 10\n mp4 = calcMP(idx + 1, lenA, lenB, lenC + BAMB_LIST[idx]) + 10\n\n return min(mp1, mp2, mp3, mp4)\n\nif __name__ == "__main__":\n \n # requested bamboo lengths\n BAMB_NUM, BAMB_A, BAMB_B, BAMB_C = map(lambda x: int(x), input().split())\n # available bamboo lengths\n for bamb in range(BAMB_NUM):\n BAMB_LIST.append(int(input()))\n\n mp = calcMP(0, 0, 0, 0)\n print(mp)', '#coding:utf-8\n\nif __name__ == "__main__":\n date = input()\n year, month, day = date.split("/")\n\n if int(year) <= 2019:\n if int(month) <= 4:\n if int(day) <= 30:\n print("Heisei")\n exit()\n \n print("TBD")'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s235385246', 's825513173', 's590669449'] | [2940.0, 3064.0, 2940.0] | [18.0, 17.0, 17.0] | [1147, 1039, 262] |
p03109 | u090032260 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s = input()\ns.strip("/")\ns = int(s)\nif s <= 20190430:\n print("Heisei")\nelse:\n print("TBD")', 's = input()\nif int(s[5:7])<= 4:\n print("Heisei")\nelse:\n print("TBD")'] | ['Runtime Error', 'Accepted'] | ['s547158216', 's273352191'] | [2940.0, 2940.0] | [18.0, 17.0] | [96, 74] |
p03109 | u090444091 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['n=int(input())\ni=0\nJPY=0\nwhile n > i:\n i=i+1\n a,b=map(str,input().split())\n a = float(a)\n if b == "JPY":\n JPY=JPY+a\n else:\n JPY=JPY+a*380000\nprint(JPY)', 'input=input()\nif input < "2019/04/31":\n print("Heisei")\nelse:\n print("TBD")'] | ['Runtime Error', 'Accepted'] | ['s871080931', 's200097617'] | [3060.0, 2940.0] | [18.0, 18.0] | [162, 77] |
p03109 | u093739220 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['import datetime\n\nt = datetime.datetime.strptime(input(), "%Y/%m/%d")\nif t < (year=2019, month=5, day=1):\n print("Heisei")\nelse:\n \tprint("TBD")\n', 'import datetime\n \nt = datetime.datetime.strptime(input(), "%Y/%m/%d")\nif t < (year=2019, month=5, day=1):\n print("Heisei")\nelse:\n print("TBD")', 'import datetime\n \nt = datetime.datetime.strptime(input(), "%Y/%m/%d")\nif t < datetime.datetime(year=2019, month=5, day=1):\n print("Heisei")\nelse:\n print("TBD")\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s253177443', 's573224391', 's129352532'] | [3188.0, 2940.0, 4432.0] | [18.0, 18.0, 32.0] | [147, 148, 166] |
p03109 | u094565093 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["N=int(input())\nxu=[list(map(str, input().split())) for _ in range(N)]\ntotal=0\nfor i in range(N):\n if xu[i][1]=='JPY':\n total+=float(xu[i][0])\n else:\n total+=380000.0*float(xu[i][0])", 'N=int(input().replace(\'/\',\'\'))\nif N <= 20190430:\n print("Heisei")\nelse:\n print("TBD")'] | ['Runtime Error', 'Accepted'] | ['s627508617', 's622031047'] | [3060.0, 2940.0] | [18.0, 17.0] | [201, 91] |
p03109 | u095756391 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["a = int(input())\n\nb = []\n\nfor i in range(a):\n b.append(input().split())\n\nres = 0\n\nfor i in b:\n if (i[1] == 'BTC'):\n res += int(i[0])*380000\n else:\n res += int(i[0])\n\nprint(res) ", "a = str(input.split())\n\na = int(a[0][:4]) + int(a[0][5:7]) + int(a[0][8:])\n\nif (a > 20190430):\n print('TBD')\nelse:\n print('Heisei') ", "a = int(input())\n\nb = []\n\nfor i in range(a):\n b.append(input().split())\n\nres = 0\n\nfor i in b:\n if (i[1] == 'BTC'):\n res += i[0]*380000\n else:\n res += i[0]\n\nprint(res) ", "a = str(input.split())\n\na = int(a[:4]) + int(a[5:7]) + int(a[8:])\n\nif (a > 20190430):\n print('TBD')\nelse:\n print('Heisei') ", "a = list(map(string, input.split()))\n\na = int(a[0][:4]) + int(a[0][5:7]) + int(a[0][8:])\n\nif (a > 20190430):\n print('TBD')\nelse:\n print('Heisei') ", "a = str(input())\n\na = a[:4] + a[5:7] + a[8:]\n\na = int(a)\n\nif (a > 20190430):\n print('TBD')\nelse:\n print('Heisei') "] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s303498463', 's478629681', 's762773344', 's846123861', 's912863504', 's448351317'] | [3060.0, 2940.0, 2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0, 17.0, 17.0, 17.0] | [200, 138, 190, 129, 152, 120] |
p03109 | u096100666 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['y,m,d = map(int,input().split("/"))\nif m <= 4:\n print("heisei")\nelse :\n print("TBD")', 'y,m,d = map(int,input().split("/"))\nprint("Heisei" * (m <= 4) or "TBD")'] | ['Wrong Answer', 'Accepted'] | ['s025622021', 's821385861'] | [2940.0, 2940.0] | [17.0, 18.0] | [86, 71] |
p03109 | u096359533 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['list = S.split("/")\ny = int(list[0])\nm = int(list[1])\nd = int(list[2])\n\nif (y > 2019):\n print("TBD")\nelif (y < 2019):\n print("Heisei")\nelif (m > 4):\n print("TBD")\nelif (m < 4):\n print("Heisei")\nelif (d > 30):\n print("TBD")\nelse:\n print("Heisei")', 'N = int(input())\ntotal = 0.0\nrate = 380000\n\nfor i in range(N):\n a,t = input().split()\n if(t=="BTC"):\n total += float(a) * rate\n else:\n total += float(a)\nprint(total)', 'def(S):\n\n list = S.split("/")\n y = int(list[0])\n m = int(list[1])\n d = int(list[2])\n\n if (y > 2019):\n print("TBD")\n elif (y < 2019):\n print("Heisei")\n elif (m > 4):\n print("TBD")\n elif (m <= 4):\n print("Heisei")', 'N = input()\ntotal = 0\n\nfor i in range(len(N)):\n if (N[i][1]=="BTC"):\n total += float(N[i][0])*380000\n else:\n total += float(N[i][0])\nprint(total)', 'list = input().split("/")\ny = int(list[0])\nm = int(list[1])\n\nif (y>=2019 and m>=5):\n print("TBD")\nelse:\n print("Heisei")'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s132762580', 's182525082', 's398858323', 's636962309', 's139079097'] | [3060.0, 3060.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 18.0, 17.0, 17.0] | [263, 174, 239, 165, 126] |
p03109 | u097069712 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['S = input()\nif S[5:7] >= "04":\n\tprint("TBD")\nelse:\n\tprint("Heisei")', 'S = input()\nT = input()\nif T[0:-1] == S:\n print("Heisei")\nelse:\n print("TBD")', 'S = input()\nif int(S[5:7]) <= 4:\n\tprint("TBD")\nelse:\n\tprint("Heisei")', 'S = input()\nif S[5:7] >= "04":\n\tprint("TBD")\nelse\n\tprint("Heisei")', 'S = input()\nif int(S[5:7]) <= 4:\n print("Heisei")\nelse:\n print("TBD")'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s033155581', 's390131662', 's424607611', 's425509328', 's881372571'] | [2940.0, 2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 18.0, 18.0, 19.0] | [67, 79, 69, 66, 75] |
p03109 | u098026648 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["y,m,d = map(int, input().split('/'))\nprint(y,m,d)\nif y > 2019:\n print('TBD')\nelif y == 2019:\n if (m < 4) or (m == 4 and d < 30):\n print('TBD')\n else:\n print('Heisei')\nelse:\n print('Heisei')", "y,m,d = map(int, input().split('/'))\nprint(y,m,d)\nif y < 2019:\n print('TBD')\nelif y == 2019:\n if (m < 4) or (m == 4 and d < 30):\n print('TBD')\n else:\n print('Heisei')\nelse:\n print('Heisei')", "y,m,d = map(int, input().split('/'))\nif y > 2019:\n print('TBD')\nelif y == 2019:\n if (m > 4) or (m == 4 and d > 30):\n print('TBD')\n else:\n print('Heisei')\nelse:\n print('Heisei')\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s420526547', 's926172780', 's028330040'] | [3060.0, 3060.0, 2940.0] | [17.0, 19.0, 82.0] | [215, 215, 203] |
p03109 | u098968285 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['ans = "Heisei"\nS = list(map(int, input().split("/")))\nif S[1] == 4:\n if S[2] < 30:\n ans = "TBD"\nelif S[1] < 4:\n ans = "TBD"\n', 'ans = "TBD"\nS = list(map(int, input().split("/")))\nif S[1] <= 4:\n ans = "Heisei"\nprint(ans)\n \n'] | ['Wrong Answer', 'Accepted'] | ['s010458479', 's665433912'] | [2940.0, 3060.0] | [17.0, 19.0] | [137, 100] |
p03109 | u099566485 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['#119-A\ndef IL(): return list(map(int,input().split()))\ndef SL(): return input().split()\ndef I(): return int(input())\ndef S(): return input()\ns=input().split("/")\ns=s[0]+s[1]+s[2]\ns=int(s)\nif s<=2019430:\n print("Heisei")\nelse:\n print("TBD")', '#119-A\ndef IL(): return list(map(int,input().split()))\ndef SL(): return input().split()\ndef I(): return int(input())\ndef S(): return input()\ns=input().split("/")\ns=s[0]+s[1]+s[2]\ns=int(s)\nif s<=20190430:\n print("Heisei")\nelse:\n print("TBD")'] | ['Wrong Answer', 'Accepted'] | ['s697226204', 's314904223'] | [3060.0, 3060.0] | [17.0, 17.0] | [245, 246] |
p03109 | u102126195 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['S = input()\nS1 = S[0:4]\nif int(S1) < 2019:\n print("TBD")\nelse:\n if int(S[5]) < 5 and S[6] != "1" and S[6] != "2":\n print("TBD")\n else:\n print("Heisei")', 'S = input()\nS1 = S[0:4]\nif int(S1) < 2019:\n print("Heisei")\nelse:\n if int(S[5:7]) >= 5:\n print("TBD")\n elif int(S[6]) < 5:\n print("Heisei")'] | ['Wrong Answer', 'Accepted'] | ['s494663899', 's300590211'] | [2940.0, 3060.0] | [17.0, 17.0] | [174, 162] |
p03109 | u102242691 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['\ns = list(int(input()))\n\nif (s[5]*10 + s[6]) <= 4 and (s[8]*10 + s[9]) <=30:\n print("Heisei")\nelse:\n print("TBD")\n', '\ns = list(input())\n\nif (int(s[5])*10 + int(s[6])) <= 4 and (int(s[8])*10 + int(s[9])) <=30:\n print("Heisei")\nelse:\n print("TBD")\n'] | ['Runtime Error', 'Accepted'] | ['s348571620', 's636468969'] | [2940.0, 3060.0] | [17.0, 19.0] | [120, 135] |
p03109 | u116233709 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s=int(input())\nif int(s[5:7])>4:\n print("TBD")\nelse:\n print("Heisei")', 's=input()\nif int(s[5:7])>4:\n print("TBD")\nelse:\n print("Heisei")\n'] | ['Runtime Error', 'Accepted'] | ['s605736586', 's422250460'] | [2940.0, 2940.0] | [17.0, 17.0] | [71, 67] |
p03109 | u116518395 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['N = int(input())\nSUM = 0\nfor i in range(N):\n ODM = input().split()\n if ODM[1] == "JPY":\n SUM = SUM + float(ODM[0])\n else:\n SUM = SUM + float(ODM[0])*380000\nprint(SUM)', 'import datetime\ndate = list(map(int,input().split("/")))\ndate2 = datetime.datetime(date[0],date[1],date[2])\ndate3 = datetime.datetime(2019,4,30)\nif date2 > date3:\n print("TBD")\nelse:\n print("Heisei")\n'] | ['Runtime Error', 'Accepted'] | ['s600739374', 's187459024'] | [2940.0, 3312.0] | [17.0, 18.0] | [189, 206] |
p03109 | u119345557 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['date=input()\nyr=slice(int[0:4])\nmn=slice(int[5:7])\ndy=slice(int[8:10])\nif yr <2019:\n print("Heisei")\nelif yr >2019:\n print("TBD")\nelse:\n if mn<4:\n print("Heisei")\n elif mn>4:\n print("TBD")\n else:\n print("Heisei")', 'yr,mn,dy=map(int,input().split(\'/\'))\nif yr <2019:\n print("Heisei")\nelif yr >2019:\n print("TBD")\nelse:\n if mn<4:\n print("Heisei")\n elif mn>4:\n print("TBD")\n else:\n print("Heisei")'] | ['Runtime Error', 'Accepted'] | ['s368641204', 's883909152'] | [3060.0, 3060.0] | [17.0, 17.0] | [226, 192] |
p03109 | u123745130 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['a,b,c=map(int,input().split("/"))\nprint(["TBD","Heisei"][(a>=2019) & (b>=5)])', 'a,b,c=map(int,input().split("/"))\nprint(["TBD","Heisei"][(a>=2019) & (b>=5)])', 'a,b,c=map(int,input().split("/"))\nprint(["Heisei","TBD"][(a>=2019) & (b>=5)])'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s086295814', 's773835319', 's967324732'] | [2940.0, 3060.0, 2940.0] | [19.0, 20.0, 17.0] | [77, 77, 77] |
p03109 | u123824541 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["S = input().split('/')\nif int(S[0])>=2019:\n if int(S[1])>=5:\n print('TBD')\nelse:\n print('Heisei')\n", "S = input().split('/')\nif int(S[0])>=2019:\n if int(S[1])>=5:\n print('TBD')\n else:\n print('Heisei')\nelse:\n print('Heisei')\n"] | ['Wrong Answer', 'Accepted'] | ['s583898403', 's789749078'] | [2940.0, 2940.0] | [19.0, 18.0] | [111, 143] |
p03109 | u129315407 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['txt = input()\nif txt >= "2019/04/30":\n print("TBD")\nelse:\n print("Heisei")', 'txt = input()\nif txt > "2019/04/30":\n print("TBD")\nelse:\n print("Heisei")'] | ['Wrong Answer', 'Accepted'] | ['s412456704', 's031047778'] | [2940.0, 2940.0] | [18.0, 18.0] | [80, 79] |
p03109 | u129492036 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['# -*- coding: utf-8 -*-\n\na = input().split("/")\n\n201if int(a[1])<5:\n print("Heisei")\nelse:\n print("TBD")\n ', '# -*- coding: utf-8 -*-\n\na = input().split("/")\n\nif int(a[1])<5:\n print("Heisei")\nelse:\n print("TBD")\n '] | ['Runtime Error', 'Accepted'] | ['s955028279', 's536487897'] | [2940.0, 2940.0] | [17.0, 17.0] | [115, 112] |
p03109 | u131264627 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["s = input()\nprint('Heisei' if s < '2019/04/30' else 'TBD')", "s = input()\nprint('Heisei' if s <= '2019/04/30' else 'TBD')"] | ['Wrong Answer', 'Accepted'] | ['s682470101', 's605778733'] | [2940.0, 2940.0] | [17.0, 17.0] | [58, 59] |
p03109 | u132583371 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["a,b,c = input().split('/')\nif int(a) <= 2019 and int(b) <= 4 and int(c) <=30:\n print('heisei')\nelse:\n print('TBD')", "a,b,c = input().split('/')\nif int(a) <= 2019 and int(b) <= 4 and int(c) <=30:\n print('Heisei')\nelse:\n print('TBD')\n"] | ['Wrong Answer', 'Accepted'] | ['s864706856', 's279450547'] | [2940.0, 2940.0] | [17.0, 17.0] | [120, 121] |
p03109 | u133583235 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['y, m, d = map(int, input().split("/")\n\nif m <= 4:\n print("Heisei")\nelse:\n print("TBD")', 'S = input()\nif int(S[5])<=0 and int(S[6])<=4:\n print("Heisei")\nelse:\n print("TBD")'] | ['Runtime Error', 'Accepted'] | ['s984274391', 's006317898'] | [2940.0, 2940.0] | [17.0, 17.0] | [92, 84] |
p03109 | u134302690 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['S = input()\nyear = int(S[0:4])\nmon = int(S[5:7])\nday = int(S[8:])\nprint(year,mon,day)\nif year <= 2019 and 1 <= mon <= 4 and 1 <= day <= 30:\n print("Heisei")\nelse:\n print("TBD")', 'S = input()\nyear = int(S[0:4])\nmon = int(S[5:7])\nday = int(S[8:])\n#print(year,mon,day)\nif year <= 2019 and 1 <= mon <= 4 and 1 <= day <= 30:\n print("Heisei")\nelse:\n print("TBD")'] | ['Wrong Answer', 'Accepted'] | ['s738623326', 's365345102'] | [3060.0, 3060.0] | [18.0, 17.0] | [182, 183] |
p03109 | u138781768 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s = input()\nrei = "2019/04/30"\nif int(rei[5:7]) < int(s[5:7]):\n\tprint("TBD")\nelse:\n print("TBD")', 's = input()\nrei = "2019/04/30"\nif 4 < int(s[5:7]):\n\tprint("TBD")\nelse:\n print("Heisei")\n'] | ['Wrong Answer', 'Accepted'] | ['s927299745', 's296925761'] | [2940.0, 2940.0] | [17.0, 17.0] | [99, 91] |
p03109 | u141410514 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s = input()\ny = int(s[:4])\nm = int(s[5:7])\nd = int(s[8:10])\nprint("{0} {1} {2}".format(y,m,d))\nif (y>=2019 and m >=5) or (y>2019):\n print("TBD")\nelse:\n print("Heisei")', 's = input()\ny = int(s[:4])\nm = int(s[5:7])\nd = int(s[8:10])\nif (y>=2019 and m >=5) or (y>2019):\n print("TBD")\nelse:\n print("Heisei")\n'] | ['Wrong Answer', 'Accepted'] | ['s081433124', 's517127862'] | [3060.0, 2940.0] | [17.0, 17.0] | [173, 139] |
p03109 | u141646806 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['from sys import stdin\n\na = stdin.readline().rstrip().split(\'/\')\n\nif(int(a[1]) > 4):\n print("Heisei")\nprint("TBD")\n\n\n', 'from sys import stdin\n\na = stdin.readline().rstrip().split(\'/\')\n\nif(int(a[1]) > 4) print("Heisei")\nprint("TBD")\n\n\n', 'from sys import stdin\n\na = stdin.readline().rstrip().split(\'/\')\n\nif(int(a[]) > 4) print("Heisei")\nprint("TBD")\n\n\n', 'import sys\n\na = sys.stdin.readline().rstrip().split(\'/\')\n\nif(int(a[1]) > 4):\n print("TBD")\nelse:\n\tprint("Heisei")\n\n\n'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s280518258', 's645019296', 's851115704', 's624744062'] | [2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0, 17.0] | [117, 114, 113, 119] |
p03109 | u142415823 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["print('Heisei' if int(input().split('/')[1]) > 4 else 'TBD')", "print('TBD' if int(input().split('/')[1]) > 4 else 'Heisei')"] | ['Wrong Answer', 'Accepted'] | ['s269796075', 's765933883'] | [2940.0, 2940.0] | [17.0, 19.0] | [60, 60] |
p03109 | u146767117 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['year, month, day = map(int, input().split("/"))\n\n# year, month, day = map(int, S.split("/"))\nif month >= 5:\n print("TBD")\nelse:\n print("heisei")', 'year, month, day = map(int, input().split("/"))\n\nif month >= 5:\n print("TBD")\nelse:\n print("Heisei")'] | ['Wrong Answer', 'Accepted'] | ['s146627743', 's119124010'] | [2940.0, 2940.0] | [17.0, 17.0] | [146, 102] |
p03109 | u148551245 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['s = map(int,input().split("/"))\nif s[1] < 5:\n print(\'Heisei\')\nelse:\n print(\'TBD\')', 's = list(map(int,input().split("/")))\nif s[1] < 5:\n print(\'Heisei\')\nelse:\n print(\'TBD\')'] | ['Runtime Error', 'Accepted'] | ['s653289797', 's521457800'] | [2940.0, 3060.0] | [17.0, 19.0] | [87, 93] |
p03109 | u152638361 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ['S = input()\nnum = int("1" + S[:4] + S[5:7] + S[8:10])\nif num >120190430:\n print("TBD")\nelse: print("heisei")', 'S = input()\nnum = int("1" + S[:4] + S[5:7] + S[8:10])\nif num >120190430:\n print("TBD")\nelse: print("Heisei")'] | ['Wrong Answer', 'Accepted'] | ['s924139109', 's748327343'] | [2940.0, 2940.0] | [17.0, 17.0] | [111, 111] |
p03109 | u155236040 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["s = list(map(int,input().split('/')))\n\nif s[0] <= 2019 and s[1] <= 4 and s[2] <= 30:\n print('heisei')\nelse:\n print('TBD')", "s = list(map(int,input().split('/')))\n\nif s[0] <= 2019 and s[1] <= 4 and s[2] <= 30:\n print('Heisei')\nelse:\n print('TBD')"] | ['Wrong Answer', 'Accepted'] | ['s077828725', 's809747842'] | [2940.0, 2940.0] | [17.0, 17.0] | [127, 127] |
p03109 | u159335277 | 2,000 | 1,048,576 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. | ["y, m, d = input().split('/')\nif m <= 4:\n print('Heisei')\nelse:\n print('TBD')\n", "y, m, d = list(map(int, input().split('/')))\nif m <= 4:\n print('Heisei')\nelse:\n print('TBD')\n"] | ['Runtime Error', 'Accepted'] | ['s193256098', 's995340063'] | [2940.0, 2940.0] | [17.0, 17.0] | [79, 95] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.