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 |
|---|---|---|---|---|---|---|---|---|---|---|
p03105 | u834248129 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A, B, C = map(int, input().split())\n\nif B >= A*C:\n print(A*C)\nelse:\n print(B//A)', 'A, B, C = map(int, input().split())\n\nif B >= A*C:\n print(C)\nelse:\n print(B//A)'] | ['Wrong Answer', 'Accepted'] | ['s280066681', 's196712209'] | [2940.0, 2940.0] | [17.0, 18.0] | [86, 84] |
p03105 | u837544459 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a, b, c = map(int, input().split())\nprint(min(n//a, c))', 'a, b, c = map(int, input().split())\nprint(min(a//b, c))', 'a, b, c= map(int, input().split())\nprint(min(a//b, c)', 'a, b, c = map(int, input().split())\nprint(min(b//a, c))'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s286881412', 's429065154', 's553537809', 's210530740'] | [9068.0, 8904.0, 8912.0, 8980.0] | [31.0, 33.0, 27.0, 28.0] | [55, 55, 53, 55] |
p03105 | u842388336 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A,B,C = map(int,input().split())\nprint(min(B//A),C)', 'A,B,C = map(int,input().split())\nprint(min(B//A,C))'] | ['Runtime Error', 'Accepted'] | ['s333949179', 's234362890'] | [2940.0, 2940.0] | [17.0, 20.0] | [51, 51] |
p03105 | u844789719 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A, B, C = [int(_) for _ in input().split()]\nprint(min([A // B, C]))\n', 'A, B, C = [int(_) for _ in input().split()]\nprint(min([B // A, C]))\n'] | ['Wrong Answer', 'Accepted'] | ['s174539202', 's920586834'] | [2940.0, 2940.0] | [19.0, 18.0] | [68, 68] |
p03105 | u845152373 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A, B, C = map(int, input().split())\nprint(max(C, B // A))', 'A, B, C = map(int, input().split())\nprint(min(C, B // A))\n'] | ['Wrong Answer', 'Accepted'] | ['s650682974', 's287425882'] | [2940.0, 2940.0] | [17.0, 17.0] | [57, 58] |
p03105 | u848654125 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a, b, c = [int(i) for i in input().split()]\n\nif a%b > c:\n print(c)\nelse:\n print(a%b)\n', 'import scipy as sp\n\n\ndef divisor(num):\n list = set()\n for i in sp.arange(1, num+1):\n if num % i == 0:\n list.add(i)\n return list\n\n\na, b, k = [int(i) for i in input().split()]\n\ndiv_a = divisor(a)\ndiv_b = divisor(b)\n\ncd = sp.sort(list(div_a & div_b))\ncd_r = cd[::-1]\nprint(cd_r[k-1])\n', 'a, b, c = [int(i) for i in input().split()]\n\nif b//a > c:\n print(c)\nelse:\n print(b//a)\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s086999523', 's709636301', 's358318778'] | [2940.0, 13080.0, 2940.0] | [18.0, 172.0, 17.0] | [91, 308, 93] |
p03105 | u857130525 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['import sys\n\nfor line in sys.stdin:\n print(line.strip().split())', "import sys, math\n\nstdout_write = sys.stdout.write\n\nfor line in sys.stdin:\n a, b, c = (int(i) for i in line.strip().split())\n ans = min(int(math.floor(b / a)), c)\n stdout_write('{}\\n'.format(ans))"] | ['Wrong Answer', 'Accepted'] | ['s497410413', 's508978512'] | [2940.0, 3060.0] | [17.0, 17.0] | [66, 198] |
p03105 | u857148155 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c=[int(s)for s in input().split()]\nprint(max((b//a,c)))', 'a,b,c=[int(s)for s in input().split()]\nprint(min((b//a,c)))'] | ['Wrong Answer', 'Accepted'] | ['s708244336', 's853148019'] | [2940.0, 2940.0] | [17.0, 17.0] | [59, 59] |
p03105 | u863370423 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['n=input().split()\na=int(n[0])\nb=int(n[1])\nc=int(n[2])\nk=b//n\nif k>c:\n print(c)\nelse:\n print(k)', 'a, b, c = map(int, input().split())\nprint(c) if b//a >= c else print(b//a)'] | ['Runtime Error', 'Accepted'] | ['s136716978', 's092677730'] | [2940.0, 2940.0] | [17.0, 17.0] | [96, 74] |
p03105 | u863850961 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['0', 'a,b,c=list(map(int ,input().split()))\nmyans1=int(b/a)\nif(myans1>c):\n\tprint(c)\nelse:\n\tprint(myans1)\n'] | ['Wrong Answer', 'Accepted'] | ['s257447039', 's704726417'] | [9052.0, 9152.0] | [27.0, 25.0] | [1, 99] |
p03105 | u864069774 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,k = map(int,input().split())\n\nyakusuu_array = []\n\nfor ab in [a,b]:\n yakusuu_array_ab = []\n for i in range(1,ab):\n if ab % i == 0:\n yakusuu_array_ab.append(i)\n yakusuu_array.append(yakusuu_array_ab)\n\nkouyakusuu = list(set(yakusuu_array[0]) & set(yakusuu_array[1]))\n\nif len(kouyakusuu) == 0:\n print(1)\nelse:\n print(kouyakusuu[k-1])\n', 'a,b,c = map(int,input().split())\noto = b//a\nif oto >= c:\n oto = c\nprint(oto)\n'] | ['Runtime Error', 'Accepted'] | ['s334055056', 's710580102'] | [3060.0, 2940.0] | [17.0, 17.0] | [367, 80] |
p03105 | u864667985 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c = map(int, input().split())\nprint(max(b//a, c))', 'a, b, c = map(int, input().split())\nprint(min(c, b//a))\n'] | ['Wrong Answer', 'Accepted'] | ['s099125906', 's803846572'] | [3316.0, 2940.0] | [20.0, 20.0] | [53, 56] |
p03105 | u864900001 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a', 'a, b, c = map(int, input().split())\ni=0\nwhile(a*i<=b and i<=c):\n i += 1\nprint(i-1)\n\n'] | ['Runtime Error', 'Accepted'] | ['s319734158', 's410755165'] | [2940.0, 2940.0] | [17.0, 17.0] | [1, 87] |
p03105 | u865413330 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a, b, k = map(int, input().split())\nl1 = [i for i in range(1, a) if (a % i == 0)]\nl2 = [i for i in range(1, b) if (b % i == 0)]\nl = list(set(l1) & set(l2))\nl.sort()\nprint(l[k-1])', 's = input()\ncount = 0\n\nfor i in range(5):\n if not(("01" in s) | ("10" in s)):\n break\n if "01" in s:\n count += 2 * s.count("01")\n s = s.replace("01", "")\n elif "10" in s :\n count += 2 * s.count("10")\n s = s.replace("10", "")\n\nprint(count)\n', 's = input()\ncount = 0\n\nfor i in range(1000):\n if not(("01" in s) | ("10" in s)):\n break\n if "01" in s:\n count += 2 * s.count("01")\n s = s.replace("01", "")\n else :\n count += 2 * s.count("10")\n s = s.replace("10", "")\n\nprint(count)\n', 'a, b, c = map(int, input().split())\nprint(b // a) if (b // a) < c else print(c)'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s363194494', 's429434581', 's938583387', 's059511957'] | [3060.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0, 17.0] | [178, 282, 275, 79] |
p03105 | u867796365 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['from sys import stdin\n\n\nsdi = stdin.readline().rstrip()\n# a, b, c = stdin.readline().rstrip().split()\n# a, b, c = [x for x in stdin.readline().rstrip().split()]\n# a, b, c = [int(x) for x in stdin.readline().rstrip().split()]\nl = list(sdi)\nl.reverse()\nstart = len(l)\ni = 0\nwhile len(l) - 1 >= i + 1:\n if l[i] != l[i + 1]:\n l.pop(i + 1)\n l.pop(i)\n i = max(i - 2, 0)\n continue\n i += 1\nprint(start - len(l))\n', 'from sys import stdin\n\n\n\n# a, b, c = stdin.readline().rstrip().split()\n# a, b, c = [x for x in stdin.readline().rstrip().split()]\na, b, c = [int(x) for x in stdin.readline().rstrip().split()]\nv = 0\nwhile b - a >= 0:\n b = b - a\n v += 1\n if v == c:\n break\n\nprint(v)\n'] | ['Wrong Answer', 'Accepted'] | ['s584251769', 's411966080'] | [3060.0, 2940.0] | [17.0, 18.0] | [461, 336] |
p03105 | u876705760 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['class UnionFind():\n def __init__(self, n):\n self.__parent = [i for i in range(n)]\n self.size = [1 for _ in range(n)]\n\n def union(self, x, y):\n pX, pY = self.find(x), self.find(y)\n if pX != pY:\n if pX < pY:\n self.__parent[pY] = pX\n self.size[pX] += self.size[pY]\n else:\n self.__parent[pX] = pY\n self.size[pY] += self.size[pX] \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\nN, M = map(int, input().split())\nbridge = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(M)]\nuf = UnionFind(N)\nnum_disconnect = int(N*(N-1)/2)\nans = []\nfor a, b in reversed(bridge):\n ans.append(num_disconnect)\n pA, pB = uf.find(a), uf.find(b)\n if pA != pB:\n num_disconnect -= uf.size[pA] * uf.size[pB]\n uf.union(a, b)\n\nfor i in reversed(ans): print(i) ', 'a, b, c = map(int, input().split()) \n\nif b//a >= c: print(c)\nelse: print(b//a)'] | ['Runtime Error', 'Accepted'] | ['s015285098', 's613070233'] | [3064.0, 2940.0] | [18.0, 18.0] | [1046, 122] |
p03105 | u886902015 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c=map(int,input().split())\nprint(max(b//a,c))', 'a,b,c=map(int,input().split())\nprint(min(b//a,c))'] | ['Wrong Answer', 'Accepted'] | ['s204492653', 's629201636'] | [9088.0, 9156.0] | [26.0, 26.0] | [49, 49] |
p03105 | u887207211 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a, b, c = map(int,input().split())\nif(a > b):\n print(0)\nelif(a*c <= b):\n print(b)\nelif(a*c > b):\n print(a)', 'A, B, C = map(int,input().split())\nprint(min(B//A, C))'] | ['Wrong Answer', 'Accepted'] | ['s661148992', 's915850070'] | [2940.0, 2940.0] | [17.0, 18.0] | [109, 54] |
p03105 | u898967808 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c=map(int,input().split())\nmin(b//a,c)', 'a,b,c=map(int,input().split())\nprint(min(b//a,c))'] | ['Wrong Answer', 'Accepted'] | ['s822797068', 's712322135'] | [2940.0, 2940.0] | [18.0, 17.0] | [42, 49] |
p03105 | u902693400 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c= map(int, input().split())\n\nif (b/a) => c:\n print(c)\nelse:\n print(b/a)', 'a,b,c= map(int, input().split())\nd=(b/a)\nif d=> c:\n print(c)\nelse:\n print(d)', 'a,b,c= map(int, input().split())\nd=int(b/a)\nif d>= c:\n print(c)\nelse:\n print(d)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s025999147', 's213132991', 's175285183'] | [2940.0, 2940.0, 2940.0] | [17.0, 24.0, 17.0] | [78, 78, 81] |
p03105 | u905872604 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,k = map(int, input().split())\nimport math\nimport sys\nc = math.gcd(a, b)\nls = []\nfor i in range(1, c):\n if c % i == 0:\n ls.append(i)\n\nprint(ls[k-1])\n', 'a, b, c= map(int, input().split())\nprint(max(b//a, c))\n\n', 'a, b, c= map(int, input().split())\nprint(min(b//a, c))\n\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s543836087', 's873534663', 's542942484'] | [2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0] | [162, 56, 56] |
p03105 | u910756197 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A, B, C = map(int, input().split())\nprint(min(A // B, C))', 'A, B, C = map(int, input().split())\nprint(min(B // A, C))\n'] | ['Wrong Answer', 'Accepted'] | ['s487989337', 's882841842'] | [2940.0, 2940.0] | [17.0, 21.0] | [57, 58] |
p03105 | u917733926 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a, b, c = (int(i) for i in input().split())\n\nif a * c == b:\n print(c)\nelse:\n print(b//a)', 'a, b, c = (int(i) for i in input().split())\n\nif (a * c) < b:\n print(c)\nelse:\n print(b//a)', 'a, b, c = (int(i) for i in input().split())\n\nif a * c < b:\n print(c)\nelse:\n print(b//a)', 'a, b, c = (int(i) for i in input().split())\n\nif ((a * c) < b):\n print(c)\nelse:\n print(b//a)'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s172195473', 's645434565', 's676508385', 's748957094'] | [3060.0, 2940.0, 2940.0, 2940.0] | [20.0, 17.0, 22.0, 17.0] | [94, 97, 95, 97] |
p03105 | u919404987 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A, B, C = [int(s) for s in input().split(" ")]\nfor i in range(C):\n B -= A\n if B<0:\n break\nprint(i)\n', 'A, B, C = [int(s) for s in input().split(" ")]\nfor i in range(C):\n B -= A\n if B<0:\n break\nprint(B+A)', 'A, B, C = [int(s) for s in input().split(" ")]\nfor i in range(C):\n B -= A\n if B<0:\n i += 1\n break\nprint(i)\n', 'A, B, C = [int(s) for s in input().split(" ")]\nfor i in range(C):\n B -= A\n if B<0:\n i -= 1\n break\nprint(i+1)\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s348648719', 's602234833', 's770342908', 's245237468'] | [2940.0, 3064.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0, 17.0] | [104, 105, 115, 117] |
p03105 | u919734978 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c = map(int,input().split())\nif a*c > b:\n print(c)\nelse:\n print(b//a)', 'a,b,c = map(int,input().split())\nif a*c < b:\n print(c)\nelse:\n print(b//a)\n'] | ['Wrong Answer', 'Accepted'] | ['s503416138', 's846828416'] | [2940.0, 3064.0] | [17.0, 17.0] | [75, 76] |
p03105 | u920963042 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['INPUT = list(int, input().split)\nA = INPUT[0]\nB = INPUT[1]\nC = INPUT[2]\n\nif (B//A) > C:\n ANS = C\nelse:\n ANS = B//A\n\nprint(ANS)', 'INPUT = list(map(int, input().split))\nA = INPUT[0]\nB = INPUT[1]\nC = INPUT[2]\n\nif (B//A) > C:\n ANS = C\nelse:\n ANS = B//A\n\nprint(ANS)', 'A, B, C = (int(i) for i in input().split()) \n\nif (B//A) > C:\n ANS = C\nelse:\n ANS = B//A\n\nprint(ANS)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s874355147', 's908127162', 's359149387'] | [3064.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0] | [132, 137, 106] |
p03105 | u922769680 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A,B,K=map(int,input().split())\nans_list=[]\nC=min(A,B)+1\nfor i in range(1,C):\n if A%i == 0 and B%i == 0:\n ans_list.append(i)\nprint(ans_list[-K])', 'a_list=list(map(int,input().split()))\nA=a_list[0]\nB=a_list[1]\nC=a_list[2]\nif B//A <= C:\n answer=B//A\nelse:\n answer=C\nprint(answer)'] | ['Runtime Error', 'Accepted'] | ['s775438345', 's186635216'] | [2940.0, 3060.0] | [18.0, 17.0] | [153, 136] |
p03105 | u923010184 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c = map(int,input().split())\nif a // b > c:\n print(c)\nelse:\n print(a // b)\n \n ', 'a,b,c = map(int,input().split())\nif b // a > c:\n print(c)\nelse:\n print(b // a)\n \n \n'] | ['Wrong Answer', 'Accepted'] | ['s673831138', 's587079868'] | [2940.0, 2940.0] | [18.0, 17.0] | [86, 87] |
p03105 | u923341003 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['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 = 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)', 'a, b, c = list(map(int,input().split()))\nq = int(b / a)\nif q > c:\n print(c)\nelse:\n print(q)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s386338771', 's719538193', 's788277134'] | [3316.0, 3192.0, 2940.0] | [18.0, 18.0, 18.0] | [1804, 1808, 97] |
p03105 | u924671994 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,k=map(int,input().split())\n \ncount=0\n \nfor i in range(1,min(a,b)+1)[::-1]:\n if a%i==0 and b%i==0:\n count+=1\n if count==k:\n print(i)', 'a,b,c=map(int,input().split())\n\nanswer = b//a\n\nif answer<c:\n print(answer)\n else:\n print(c)', 'a,b,k=map(int,input().split())\n \ncount=0\n \nfor i in range(1,min(a,b)+1)[::-1]:\n if a%i==0 and b%i==0:\n count+=1\n if count==k:\n num=i\n break\nprint(i)', 'a,b,k=map(int,input().split())\n \ncount=0\n \nfor i in range(1,max(a,b)+1)[::-1]\n \nif a%i==0 and b%i==0:\n count+=1\n if count==k:\n print(i)', 'a,b,c=map(int,input().split())\n\nanswer=b//a\n\nif answer<c:\n print(answer)\nelse:\n print(c)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s197680402', 's556310982', 's784802401', 's958161943', 's440596626'] | [2940.0, 2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0, 17.0, 17.0] | [143, 96, 159, 140, 92] |
p03105 | u932913455 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['def main120():\n import sys\n S_org = input()\n S = []\n\n for s in range(len(S_org)):\n S.append(S_org[s])\n S = list(map(int, S))\n\n cont = True\n index = 0\n count = 0\n\n if len(S) == 1:\n print(0)\n sys.exit()\n\n else:\n while(cont):\n print(index)\n if S[index] == S[index+1]:\n index += 1\n else:\n count += 2\n S.pop(index)\n S.pop(index)\n if index > 0:\n index -= 1\n\n if index == len(S) - 2:\n if S[index] != S[index+1]:\n count += 2\n print(count)\n sys.exit()\n\n\nmain120()', 'A, B, C = (int(x) for x in input().split())\n\ncount = int(B/A)\nif count <= C:\n print(count)\nelse:\n print(C)'] | ['Runtime Error', 'Accepted'] | ['s011519198', 's631096641'] | [3064.0, 2940.0] | [18.0, 17.0] | [714, 112] |
p03105 | u937706062 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a = str(input())\nx = a.count("0")\ny = a.count("1")\nprint(2 * min(int(x), int(y)))\n', 'a = str(input())\nx = a.count("0")\ny = a.count("1")\nprint(2 * min(int(x), int(y)))\n', 'A, B, C = map(int, input().split())\nprint(min(B // A, C))\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s391986307', 's758713075', 's709032724'] | [2940.0, 2940.0, 3064.0] | [18.0, 17.0, 17.0] | [82, 82, 58] |
p03105 | u938486382 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ["a, b, c = list(map(int, input().split(' ')))\nmin(b//a, c)", "a, b, c = list(map(int, input().split(' ')))\nprint(min(b//a, c))"] | ['Wrong Answer', 'Accepted'] | ['s487579793', 's418479793'] | [2940.0, 2940.0] | [17.0, 17.0] | [57, 64] |
p03105 | u940102677 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c = map(int,input().split())\nprint(max(b//a,c))', 'a,b,c = map(int,input().split())\nprint(min(b//a,c))'] | ['Wrong Answer', 'Accepted'] | ['s505317983', 's154546382'] | [2940.0, 2940.0] | [17.0, 18.0] | [51, 51] |
p03105 | u940279019 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A,B,C = map(int,input().split())\nprint(if(B/A <= C)int(B/A) else(int(C))', 'A,B,C = map(int,input().split())\n\nans = min(C,B//A)\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s250965444', 's087511255'] | [2940.0, 3064.0] | [18.0, 17.0] | [72, 62] |
p03105 | u943117333 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c =map(int, input().split()) \n\nif b%a <= c :\n print(b//a)\nelse:\n print(c)', 'a,b,c =map(int, input().split()) \n\nif b//a<= c :\n print(b//a)\nelif b//a> c:\n print(c)'] | ['Wrong Answer', 'Accepted'] | ['s741142305', 's977942592'] | [2940.0, 2940.0] | [17.0, 18.0] | [83, 91] |
p03105 | u945945701 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a = input()\nb = input()\nc = input()\n\nprint (a)\nprint (b)\nprint (c)', 'a,b,c = map(int,input.split())\nprint (min(b//a,c))', 'input = input()\na,b,c = map(int,input.split())\nprint (min(a/b,c))', 'input = input()\na,b,c = map(int,input.split())\nprint (min(a/b,c))', 'input = input()\na,b,c = map(int,input.split())\nprint (min(b//a,c))'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s179324427', 's573001894', 's909955528', 's989405001', 's057782796'] | [3068.0, 2940.0, 2940.0, 2940.0, 2940.0] | [18.0, 18.0, 17.0, 18.0, 17.0] | [66, 50, 65, 65, 66] |
p03105 | u950708010 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c = (int(i) for i in input().split())\nif a*c <= a:print(c)\nelse:print(b//a)', 'a,b,c = (int(i) for i in input().split())\nif a*c <= b:print(c)\nelse:print(b//a)'] | ['Wrong Answer', 'Accepted'] | ['s386991452', 's889024345'] | [2940.0, 2940.0] | [17.0, 17.0] | [79, 79] |
p03105 | u951652829 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a , b, c = map(int, input().split())\nd = b // a \nif d > c:\n return c\nelse:\n return d', 'a , b, c = map(int, input().split())\nd = b // a \nif d > c:\n print(c)\nelse:\n print(d)'] | ['Runtime Error', 'Accepted'] | ['s514300471', 's206446325'] | [2940.0, 2940.0] | [17.0, 17.0] | [87, 87] |
p03105 | u953379577 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c = map(int,input().split())\nprint(min(c,a//b))', 'a,b,c = map(int,input().split())\nprint(min(c,b//a))'] | ['Wrong Answer', 'Accepted'] | ['s632404878', 's487771266'] | [9100.0, 9060.0] | [28.0, 23.0] | [51, 51] |
p03105 | u963903527 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ["A, B, C = map(int, input().split())\n\nprint(B // A if B // A < C else C)\nprint('a')", 'A, B, C = map(int, input().split())\n\nprint(B // A if B // A < C else C)'] | ['Wrong Answer', 'Accepted'] | ['s237118334', 's335372519'] | [2940.0, 2940.0] | [18.0, 17.0] | [82, 71] |
p03105 | u964763428 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A, B, K = map(int, input().split())\nd = [i for i in range(100,1,-1) if (A%i==0 and B%i==0)]\nprint(d[K-1])\n', 'a,b,c=map(int,input().split())\nif a*c<=b:\n print(c)\nelse:\n print(b//a)'] | ['Runtime Error', 'Accepted'] | ['s005032203', 's410610277'] | [2940.0, 2940.0] | [18.0, 17.0] | [106, 72] |
p03105 | u966000628 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c = map(int,input().split())\nlis = []\nfor i in range(1,min(a,b)+1):\n if a%i == 0 and b%i == 0:\n lis.append(i)\nprint(lis[-1*c])', 'a,b,c = map(int,input(),split())\nif a*c < b:\n print(c)\nelse:\n print(b//a)', 'a,b,c = map(int,input().split())\nif a*c < b:\n print(c)\nelse:\n print(b//a)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s116628770', 's125723266', 's237217668'] | [2940.0, 2940.0, 2940.0] | [18.0, 17.0, 17.0] | [134, 75, 76] |
p03105 | u967835038 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ["s=str(input())\nprint(min(s.count('0'),s.count('1'))*2)", 'a, b, c = map(int, input().split())\nprint(min(b//a, c))\n'] | ['Wrong Answer', 'Accepted'] | ['s714186303', 's838208218'] | [2940.0, 2940.0] | [18.0, 17.0] | [54, 56] |
p03105 | u973108807 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a,b,c = map(int, input().split())\nprint(min(c, b//a)', 'a,b,c = map(int, input().split())\nprint(min(c, b//a))'] | ['Runtime Error', 'Accepted'] | ['s591909958', 's993503693'] | [2940.0, 2940.0] | [17.0, 17.0] | [52, 53] |
p03105 | u980783809 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a, b, c = map(int, input().split())\nprint(min(c,a//b))', 'a, b, c = map(int, input().split())\nprint(min(c,b//a))'] | ['Wrong Answer', 'Accepted'] | ['s311994265', 's620609415'] | [9080.0, 9104.0] | [29.0, 31.0] | [54, 54] |
p03105 | u981002188 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['S = input()\nS = S.split()\nhowMuch = S[0]\nIhave = S[1]\nsutis = S[2]\n \nans = int(Ihave)/int(howMuch)\nans2 = int(sutis) * int(howMuch)\nif ans < sutis:\n print(int(sutis))\nelse:\n print(int(ans))', 'S = input()\nS = S.split()\nhowMuch = S[0]\nIhave = S[1]\nsutis = S[2]\n \nif (Ihave // howMuch) < sutis:\n print(Ihave // howMuch)\nelse:\n print(sutis)', 'S = input()\nS = S.split()\nhowMuch = S[0]\nIhave = S[1]\nsutis = S[2]\n\nans = int(Ihave)/int(howMuch)\nprint(int(ans))', 'S = input()\nS = S.split()\nhowMuch = int(S[0])\nIhave = int(S[1])\nsutis = int(S[2])\n \nif (Ihave // howMuch) < sutis:\n print(Ihave // howMuch)\nelse:\n print(sutis)'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s055939807', 's305264944', 's383503744', 's095309580'] | [3060.0, 2940.0, 2940.0, 3060.0] | [17.0, 17.0, 17.0, 17.0] | [195, 150, 113, 165] |
p03105 | u982198202 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A, B, C = map(int, input().split())\nans = int(B / A)\nif ans > 0:\n print(ans)\nelse:\n print(0)', 'A, B, C = map(int, input().split())\nans = int(B / A)\nif ans > 0:\n if C > ans:\n print(ans)\n else:\n print(C)\nelse:\n print(0)'] | ['Wrong Answer', 'Accepted'] | ['s081061435', 's970691381'] | [2940.0, 2940.0] | [17.0, 17.0] | [98, 145] |
p03105 | u982594421 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ["from itertools import chain\nimport sys\nsys.setrecursionlimit(99999)\n\ns = input().rstrip()\n\ndef f(s):\n l = s.split('01')\n for i in range(len(l)):\n l[i] = l[i].split('10')\n l = list(chain.from_iterable(l))\n if len(l) == 1:\n return 0\n else:\n r = (len(l) - 1) * 2\n return r + f(''.join(l))\n\nprint(f(s))\n", 'a, b, c = map(int, input().split())\nprint(min(b // a, c))\n\n'] | ['Wrong Answer', 'Accepted'] | ['s191919059', 's380828242'] | [3060.0, 2940.0] | [17.0, 17.0] | [342, 59] |
p03105 | u983599131 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['in = input().split()\n\na = int(in[0])\nb = int(in[1])\nc = int(in[2])\n\nif b / a < c:\n print(b/ a)\nelse:\n print(c)\n', 'in1 = input().split()\n\na = int(in1[0])\nb = int(in1[1])\nc = int(in1[2])\n\nif b / a < c:\n print(int(b / a))\nelse:\n print(c)\n'] | ['Runtime Error', 'Accepted'] | ['s992241407', 's874109552'] | [2940.0, 2940.0] | [17.0, 18.0] | [113, 123] |
p03105 | u987637902 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a, b, c = map(input().split())\nif a * c > b:\n print(b//a)\nelse:\n print(c)\n', 'a, b, c = map(int, input().split())\nif a * c > b:\n print(b//a)\nelse:\n print(c)\n'] | ['Runtime Error', 'Accepted'] | ['s026949707', 's195325620'] | [8908.0, 9084.0] | [26.0, 25.0] | [80, 85] |
p03105 | u988004923 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['import sys\nsys.setrecursionlimit(10**5)\nn, m = list(map(int, input().split()))\nab = [list(map(int, input().split())) for i in range(m)]\n\nans = n * (n - 1) // 2\nresult = [ans]\nleader = [-1] * n\nsize = [1] * n\n\n\ndef leader_check(i):\n if leader[i] == -1:\n return i\n ln = leader_check(leader[i])\n leader[i] = ln\n return ln\n\n\nfor a, b in ab[:0:-1]:\n a, b = a - 1, b - 1\n la = leader_check(a)\n lb = leader_check(b)\n if la != lb:\n leader[la] = lb\n ans -= size[la] * size[lb]\n size[lb] += size[la]\n result.append(ans)\n\nfor i in result[::-1]:\n print(i)\n', 'a,b,c=list(map(int,input().split()))\nif b>a*c:\n print(c)\nelse:\n print(int(b/a))'] | ['Runtime Error', 'Accepted'] | ['s049058276', 's141428479'] | [3064.0, 2940.0] | [17.0, 17.0] | [602, 85] |
p03105 | u989623817 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['a, b, c = input().split()\n\n\nprint(max(c, b//a))', 'a, b, c = map(int,input().split())\nprint(max(c, b//a))\n', 'a, b, c = map(int, input().split())\n\n\nprint(min(c, b//a))\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s189315463', 's720344992', 's228826355'] | [2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0] | [47, 55, 58] |
p03105 | u993435350 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['H,W = map(int,input().split())\na,b = map(int,input().split())\n\nwhite = (H * W) - (W * a) - ((H - a) * b)\n\nprint(white)', 'A,B,C = map(int,input().split())\n\nprint(min(B//A,C))'] | ['Runtime Error', 'Accepted'] | ['s447895169', 's416222457'] | [2940.0, 2940.0] | [17.0, 17.0] | [118, 52] |
p03105 | u994064513 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A,B,C = [int(s) for s in input().split()]\n\nprint(C) if B B//A >= C else print(B//A)', 'A,B,C = [int(s) for s in input().split()]\n \nprint(C) if B//A >= C else print(B//A)'] | ['Runtime Error', 'Accepted'] | ['s221609664', 's338821106'] | [2940.0, 2940.0] | [17.0, 17.0] | [83, 82] |
p03105 | u995102075 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['K = int(input())\n\nif K % 2:\n print((K // 2) * (K // 2 + 1))\nelse:\n print((K // 2)**2)\n', 'A, B, C = map(int, input().split())\n\nif C <= B / A:\n print(C)\nelse:\n print(int(B / A))\n'] | ['Runtime Error', 'Accepted'] | ['s258889393', 's989399565'] | [2940.0, 2940.0] | [17.0, 17.0] | [92, 93] |
p03105 | u997641430 | 2,000 | 1,048,576 | Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? | ['A,B,C=map(int,input().split())\nprint(min(int(B/A),C)', 'A,B,C=map(int,input().split())\nprint(min(int(B/A),C))'] | ['Runtime Error', 'Accepted'] | ['s854666744', 's466601094'] | [2940.0, 2940.0] | [17.0, 17.0] | [52, 53] |
p03108 | u000623733 | 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\npairs = []\nfor _ in range(M):\n pairs.append(list(map(int, input().split())))\npairs = pairs[::-1]\n\n\n\nclass UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n)]\n self.rank = [1 for i in range(n)]\n\n def root(self, x):\n if (self.par[x]==x):\n return x\n else:\n # path compression\n self.par[x] = self.root(self.par[x])\n return self.par[x]\n\n def union(self, x, y):\n x = self.root(x)\n y = self.root(y)\n\n if (x==y):\n return\n\n if (self.rank[x] < self.rank[y]):\n self.par[x] = y\n self.rank[y] += self.rank[x]\n self.rank[x] = 0\n else:\n self.par[y] = x\n self.rank[x] += self.rank[y]\n self.rank[y] = 0\n\n def find(self, x, y):\n return self.root(x)==self.root(y)\n \n def get_inconvenience(self, x, y):\n x = self.root(x)\n y = self.root(y)\n return self.rank[x] * self.rank[y]\n\nuf = UnionFind(N)\ninconvenience = [int(N*(N-1)/2)]\nfor m in range(M-1):\n inconvenience.append(inconvenience[-1] - uf.get_inconvenience(pairs[m][0]-1, pairs[m][1]-1))\n uf.union(pairs[m][0]-1, pairs[m][1]-1)\n\nprint(*inconvenience[::-1], sep='\\n')\n", "N, M = map(int, input().split())\n\npairs = []\nfor _ in range(M):\n pairs.append(list(map(int, input().split())))\npairs = pairs[::-1]\n\n\n\nclass UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n)]\n self.rank = [1 for i in range(n)]\n\n def root(self, x):\n if (self.par[x]==x):\n return x\n else:\n # path compression\n self.par[x] = self.root(self.par[x])\n return self.par[x]\n\n def union(self, x, y):\n x = self.root(x)\n y = self.root(y)\n\n if (x==y):\n return\n\n if (self.rank[x] < self.rank[y]):\n self.par[x] = y\n self.rank[y] += self.rank[x]\n self.rank[x] = 0\n else:\n self.par[y] = x\n self.rank[x] += self.rank[y]\n self.rank[y] = 0\n\n def find(self, x, y):\n return self.root(x)==self.root(y)\n \n def get_inconvenience(self, x, y):\n x = self.root(x)\n y = self.root(y)\n\n if x==y:\n return 0\n else:\n return self.rank[x] * self.rank[y]\n\nuf = UnionFind(N)\ninconvenience = [int(N*(N-1)/2)]\nfor m in range(M-1):\n inconvenience.append(inconvenience[-1] - uf.get_inconvenience(pairs[m][0]-1, pairs[m][1]-1))\n uf.union(pairs[m][0]-1, pairs[m][1]-1)\n\nprint(*inconvenience[::-1], sep='\\n')\n"] | ['Wrong Answer', 'Accepted'] | ['s293733455', 's503476501'] | [38356.0, 38352.0] | [780.0, 737.0] | [1407, 1464] |
p03108 | u001024152 | 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 \n \n \n def __init__(self,n):\n self.par = [-1]*n \n self.size = [1]*n\n for i in range(n):\n self.par[i] = i \n \n def root(self, x: int) -> int:\n \n if self.par[x] == x: # if root\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:int, y:int)->bool:\n \n return self.root(x)==self.root(y)\n \n def unite(self, x:int, y:int):\n \n x = self.root(x)\n y = self.root(y)\n if x == y: return\n self.par[x] = y\n self.size[y] += self.size[x]\n self.size[x] = 0\n \n def getsize(self, x:int):\n return self.size[self.root(x)]\n \nN,M = map(int, input().split())\nab = tuple(tuple(map(lambda x:int(x)-1, input().split())) for _ in range(M))\n\ndef comb2(n):\n if n==0: return 0\n return n*(n-1)//2\n\nuf = UnionFind(N)\nans = []\nnex = comb2(N)\n\nfor ai,bi in reversed(ab):\n ans.append(nex)\n sa = uf.getsize(ai)\n sb = uf.getsize(bi)\n nex = ans[-1] + comb2(sa) + comb2(sb)\n uf.unite(ai,bi)\n nex -= comb2(uf.getsize(ai))\n \n\nfor a in reversed(ans):\n print(a)', 'class UnionFind:\n def __init__(self, N:int):\n \n self.par = [i for i in range(N)]\n self.size = [1]*N\n self.rank = [1]*N\n \n def root(self, x:int)->int:\n \n if self.par[x] == x: # if root\n return x\n else:\n self.par[x] = self.root(self.par[x]) \n return self.par[x]\n \n def is_same(self, x:int, y:int)->bool:\n \n return self.root(x)==self.root(y)\n \n def unite(self, x:int, y:int):\n \n root_x = self.root(x)\n root_y = self.root(y)\n if root_x == root_y: return\n if self.rank[root_x] == self.rank[root_y]:\n self.rank[root_x] += 1\n elif self.rank[root_x]<self.rank[root_y]:\n root_x,root_y = root_y,root_x\n \n self.par[root_y] = root_x\n self.size[root_x] += self.size[root_y]\n self.size[root_y] = 0 \n \n def get_size(self, x:int)->int:\n \n return self.size[self.root(x)]\n \n\ndef main():\n N,M = map(int,input().split())\n ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(M)]\n uf = UnionFind(N)\n accm = []\n for ai,bi in reversed(ab):\n if uf.is_same(ai,bi):\n accm.append(0)\n else:\n accm.append(uf.get_size(ai)*uf.get_size(bi))\n uf.unite(ai,bi)\n\n accm = accm[::-1]\n for i in range(1,len(accm)):\n accm[i] += accm[i-1]\n for a in accm:\n print(a)\n\nmain()'] | ['Runtime Error', 'Accepted'] | ['s995041455', 's099489042'] | [23284.0, 27600.0] | [1001.0, 878.0] | [1667, 1731] |
p03108 | u013408661 | 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\nn,m=map(int,input().split())\nbridge=[[i for i in map(int,l.split())] for l in sys.stdin]\nbridge.reverse()\nall=(n*(n-1))//2\nans=[all]\nroot=[1]*(n+1)\nrank=[0]*(n+1)\nsize=[0]*(n+1)\ndef find(x):\n if root[x]==x:\n return x\n else:\n root[x]=find(root[x])\n return root[x]\ndef check(x,y):\n return find(x)==find(y)\ndef union(x,y):\n x=find(x)\n y=find(y)\n if rank[x]<rank[y]:\n root[x]=y\n size[y]+=size[x]\n else:\n root[y]=x\n size[x]+=size[y]\n if rank[x]==rank[y]:\n rank[x]+=1\nfor i in bridge:\n if check(i[0],i[1]):\n ans.append(ans[-1])\n else:\n ans.append(ans-size[i[0]]*size[i[1]])\n union(i[0],i[1])\nans.pop()\nfor i in range(m):\n print(ans.pop())', 'import sys\nn,m=map(int,input().split())\nbridge=[[i for i in map(int,l.split())] for l in sys.stdin]\nbridge.reverse()\nall=(n*(n-1))//2\nans=[all]\nroot=[i for i in range(n+1)]\nrank=[0]*(n+1)\nsize=[1]*(n+1)\ndef find(x):\n if root[x]==x:\n return x\n else:\n root[x]=find(root[x])\n return root[x]\ndef check(x,y):\n return find(x)==find(y)\ndef union(x,y):\n x=find(x)\n y=find(y)\n if rank[x]<rank[y]:\n root[x]=y\n size[y]+=size[x]\n else:\n root[y]=x\n size[x]+=size[y]\n if rank[x]==rank[y]:\n rank[x]+=1\nfor i in bridge:\n if check(i[0],i[1]):\n ans.append(ans[-1])\n else:\n ans.append(ans[-1]-size[find(i[0])]*size[find(i[1])])\n union(i[0],i[1])\nans.pop()\nfor i in range(m):\n print(ans.pop())'] | ['Wrong Answer', 'Accepted'] | ['s960941307', 's497575113'] | [25264.0, 29900.0] | [365.0, 551.0] | [687, 717] |
p03108 | u037098269 | 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_list = []\nb_list = []\nfor i in range(M):\n a, b = map(int, input().split())\n a_list.append(a)\n b_list.append(b)\n\nclass UnionFind():\n def __init__(self, N):\n self.par = [i for i in range(N+1)]\n self.rank = [0]*(N+1)\n self.size = [1] * (N + 1)\n \n def find(self, x):\n if self.par[x] == x:\n return self.par[x]\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def fsize(self, x):\n return self.size[self.par[x]]\n\n\n def unite(self, x, y):\n x_par = self.find(x)\n y_par = self.find(y)\n if x_par == y_par:\n return\n if self.rank[x_par] < self.rank[y_par]:\n self.par[x_par] = y_par\n self.size[y_par] += self.size[x_par]\n else:\n self.par[y_par] = x_par\n self.size[x_par] += self.size[y_par]\n if self.rank[x_par] == self.rank[y_par]:\n self.rank[x_par] += 1\n\n\n def isunite(self, x, y):\n if self.find(x) == self.find(y):\n return True\n else:\n return False\n\n\nuf = UnionFind(N)\nans_list = [] \nans = int(N*(N-1)/2)\nfor i in range(M):\n ans_list.append(ans)\n a = a_list[M-1-i]\n b = b_list[M-1-i]\n if uf.isunite(a, b):\n pass\n else:\n p = uf.fsize(a)\n q = uf.fsize(b)\n ans -= p*q\n uf.unite(a, b)\n\nfor i in range(M):', 'N, M = map(int, input().split())\na_list = []\nb_list = []\nfor i in range(M):\n a, b = map(int, input().split())\n a_list.append(a)\n b_list.append(b)\n\npar = [i for i in range(N+1)]\nrank = [0]*(N+1)\nsize = [1] * (N + 1)\n\ndef find(x):\n if par[x] == x:\n return par[x]\n else:\n par[x] = find(par[x])\n return par[x]\n\n\ndef unite(x, y):\n x_par = find(x)\n y_par = find(y)\n if x_par == y_par:\n return\n if rank[x_par] < rank[y_par]:\n par[x_par] = y_par\n size[y_par] += size[x_par]\n else:\n par[y_par] = x_par\n size[x_par] += size[y_par]\n if rank[x_par] == rank[y_par]:\n rank[x_par] += 1\n\n\ndef bool_func(x, y):\n if find(x) == find(y):\n return True\n else:\n return False\n\n\nans_list = [] \nans = int(N*(N-1)/2)\nfor i in range(M):\n ans_list.append(ans)\n a = a_list[M-1-i]\n b = b_list[M-1-i]\n p = size[find(a)]\n q = size[find(b)]\n if bool_func(a, b):\n pass\n else:\n ans -= p*q\n unite(a, b)\n\nfor i in range(M):\n print(ans_list[M-1-i])\n '] | ['Runtime Error', 'Accepted'] | ['s878019299', 's706035828'] | [3064.0, 19404.0] | [17.0, 707.0] | [1451, 1088] |
p03108 | u038229929 | 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. | ["from sys import stdin\nN, M = [int(x) for x in stdin.readline().rstrip().split()]\ndata = [stdin.readline().rstrip().split() for _ in range(M)]\n\nisland = list(range(N))\ncounts = [1] * N\ntotal = int((N * (N - 1)) / 2)\nresult = []\n\nfor c in reversed(data):\n ref0 = int(c[0]) - 1\n while island[ref0] != ref0:\n ref0 = island[ref0]\n ref1 = int(c[1]) - 1\n while island[ref1] != ref1:\n ref1 = island[ref1]\n\n if ref0 == ref1:\n root = min(ref0, ref1)\n pair = max(ref0, ref1)\n island[int(c[0]) - 1] = root\n island[int(c[1]) - 1] = root\n island[pair] = root\n result.append(0);\n else:\n root = min(ref0, ref1)\n island[int(c[0]) - 1] = root\n island[int(c[1]) - 1] = root\n island[pair] = root\n result.append(counts[ref0] * counts[ref1]);\n counts[root] = counts[ref0] + counts[ref1]\n\nres = [total]\nfor r in result:\n res.append((res[-1] - r))\n\nprint('\\n'.join(reversed([str(x) for x in res][:-1])))\n", "from sys import stdin\nN, M = [int(x) for x in stdin.readline().rstrip().split()]\ndata = [stdin.readline().rstrip().split() for _ in range(M)]\n\nisland = list(range(N))\ncounts = [1] * N\ntotal = int((N * (N - 1)) / 2)\nresult = []\n\nfor c in reversed(data):\n ref0 = int(c[0]) - 1\n while island[ref0] != ref0:\n ref0 = island[ref0]\n ref1 = int(c[1]) - 1\n while island[ref1] != ref1:\n ref1 = island[ref1]\n\n if ref0 == ref1:\n result.append(0);\n else:\n island[c[0] - 1] = min(ref0, ref1)\n island[c[1] - 1] = min(ref0, ref1)\n result.append(counts[ref0] * counts[ref1]);\n counts[min(ref0,ref1)] = counts[ref0] + counts[ref1]\n\nres = [total]\nfor r in result:\n res.append((res[-1] - r))\n\nprint('\\n'.join(reversed([str(x) for x in res][:-1])))\n", "from sys import stdin\nN, M = [int(x) for x in stdin.readline().rstrip().split()]\ndata = [stdin.readline().rstrip().split() for _ in range(M)]\nprint(data)\n\nisland = list(range(N))\ncounts = [1] * N\ntotal = int((N * (N - 1)) / 2)\nresult = []\n\nfor c in reversed(data):\n ref0 = int(c[0]) - 1\n while island[ref0] != ref0:\n ref0 = island[ref0]\n ref1 = int(c[1]) - 1\n while island[ref1] != ref1:\n ref1 = island[ref1]\n\n if ref0 == ref1:\n result.append(0);\n else:\n island[max(ref0,ref1)] = min(ref0, ref1)\n result.append(counts[ref0] * counts[ref1]);\n counts[min(ref0,ref1)] = counts[ref0] + counts[ref1]\n\nres = [total]\nfor r in result:\n res.append((res[-1] - r))\n\nprint('\\n'.join(reversed([str(x) for x in res])))\n", "from sys import stdin\nN, M = [int(x) for x in stdin.readline().rstrip().split()]\ndata = [stdin.readline().rstrip().split() for _ in range(M)]\n\nisland = list(range(N))\ncounts = [1] * N\ntotal = int((N * (N - 1)) / 2)\nresult = []\n\nfor c in reversed(data):\n ref0 = int(c[0]) - 1\n while island[ref0] != ref0:\n ref0 = island[ref0]\n ref1 = int(c[1]) - 1\n while island[ref1] != ref1:\n ref1 = island[ref1]\n\n if ref0 == ref1:\n root = min(ref0, ref1)\n pair = max(ref0, ref1)\n island[int(c[0]) - 1] = root\n island[int(c[1]) - 1] = root\n island[pair] = root\n result.append(0);\n else:\n root = min(ref0, ref1)\n pair = max(ref0, ref1)\n island[int(c[0]) - 1] = root\n island[int(c[1]) - 1] = root\n island[pair] = root\n result.append(counts[ref0] * counts[ref1]);\n counts[root] = counts[ref0] + counts[ref1]\n\nres = [total]\nfor r in result:\n res.append((res[-1] - r))\n\nprint('\\n'.join(reversed([str(x) for x in res][:-1])))\n"] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s214652978', 's320175260', 's970626301', 's365838400'] | [36900.0, 36900.0, 52600.0, 50008.0] | [120.0, 110.0, 621.0, 442.0] | [999, 798, 768, 1030] |
p03108 | u052499405 | 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.par = [i for i in range(n+1)]\n self.rank = [0] * (n+1)\n\n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n def same_count(self, x):\n return self.par.count(self.find(x))\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n else:\n self.par[y] = x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n def print_par(self):\n print(self.par)\n\ntxt = open("a.txt", "r")\nn, m = [int(item) for item in input().split()]\ne = [[int(item) for item in input().split()] for i in range(m)]\ne = e[::-1]\n\nUF = UnionFind(n)\nunconvinience = n * (n-1) / 2\nuc_list = [int(unconvinience)]\n\nfor item in e:\n if UF.same_check(item[0], item[1]):\n pass\n else:\n unconvinience -= (UF.same_count(item[0]) * UF.same_count(item[1]))\n\n uc_list.append(int(unconvinience))\n UF.union(item[0], item[1])\n\nfor i in range(m):\n print(uc_list[::-1][i+1])\n', 'class UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n+1)]\n self.rank = [0] * (n+1)\n\n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n def same_count(self, x):\n return self.par.count(self.find(x))\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n else:\n self.par[y] = x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n def print_par(self):\n print(self.par)\n\ntxt = open("a.txt", "r")\nn, m = [int(item) for item in txt.readline().split()]\ne = [[int(item) for item in txt.readline().split()] for i in range(m)]\ne = e[::-1]\n\nUF = UnionFind(n)\nunconvinience = n * (n-1) / 2\nuc_list = [int(unconvinience)]\n\nfor item in e:\n if UF.same_check(item[0], item[1]):\n pass\n else:\n unconvinience -= (UF.same_count(item[0]) * UF.same_count(item[1]))\n\n uc_list.append(int(unconvinience))\n UF.union(item[0], item[1])\n\nprint(uc_list)\nfor i in range(m):\n print(uc_list[::-1][i+1])\n', 'n, m = [int(item) for item in input().split()]\nab = [[int(item) for item in input().split()] for _ in range(m)]\nab.reverse()\n\nclass UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n)]\n self.rank = [0] * n\n self.size = [1] * n\n\n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n def get_size(self, x):\n return self.size[self.find(x)]\n\ninconv = n*(n-1) // 2 \nUF = UnionFind(n)\n\ninconv_list = []\ninconv_list.append(inconv)\nfor a, b in ab:\n if not UF.same_check(a-1, b-1):\n inconv -= UF.get_size(a-1) * UF.get_size(b-1)\n UF.union(a-1, b-1)\n inconv_list.append(inconv)\nfor item in inconv_list[::-1][1:]:\n print(item)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s030821897', 's827689335', 's517673347'] | [3064.0, 3192.0, 30984.0] | [20.0, 18.0, 884.0] | [1260, 1289, 1238] |
p03108 | u054106284 | 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 = (int(i) for i in input().split())\nL = []\nfor i in range(M):\n a, b = (int(j) for j in input().split())\n L.append((a-1, b-1))\nL.reverse()\n\nuf = [-1]*N\ndef parent(v):\n if uf[v] < 0:\n return v\n else:\n uf[v] = parent(uf[v])\n return parent(uf[v])\n\nres = [0]*M\nans = (N*(N-1))//2\nres[0] = ans\n\nfor i in range(1, M):\n a, b = L[i-1]\n pa = parent(a)\n pb = parent(b)\n if pa != pb:\n sa = -uf[pa]\n sb = -uf[pb]\n uf[b] = pa\n ans -= sa * sb\n uf[pa] = -(sa + sb)\n res[i] = ans\n print(uf)\n\nres.reverse()\nfor i in range(M):\n print(res[i])', 'import sys\ninput = sys.stdin.readline\n\nsys.setrecursionlimit(100000)\n\nN, M = (int(i) for i in input().split())\nL = []\nfor i in range(M):\n a, b = (int(j) for j in input().split())\n L.append((a-1, b-1))\nL.reverse()\n\nuf = [-1]*N\ndef parent(v):\n if uf[v] < 0:\n return v\n else:\n uf[v] = parent(uf[v])\n return uf[v]\n\ndef union(u, v):\n pu = parent(u)\n pv = parent(v)\n if pu != pv:\n res = uf[pv] * uf[pu]\n uf[pv] += uf[pu]\n uf[pu] = pv\n else:\n res = 0\n return res\n\nres = [0]*M\nans = (N*(N-1))//2\nres[0] = ans\n\nfor i in range(1, M):\n a, b = L[i-1]\n ans -= union(a, b)\n res[i] = ans\n\nres.reverse()\nfor i in range(M):\n print(res[i])'] | ['Wrong Answer', 'Accepted'] | ['s940362685', 's077483925'] | [125708.0, 34368.0] | [2105.0, 489.0] | [616, 709] |
p03108 | u062459048 | 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 = []*m\nB = []*m\nfor i in range(m):\n A[i],B[i] =map(int, input().split())\n\nal = n(n-1)/2\nansl = [al]\nd = list(range(m+1))\ndl = [[_] for _ in range(m+1)]\n\nfor i in range(m-1,0,-1):\n x = d[A[i]]\n y = d[B[i]]\n x,y = max(x,y),min(x,y)\n al -= dl[x]*dl[y]\n for i in range(dl[y]):\n d[i] = x\n dl[x] += dl[y]\n ansl.append(al)\n \nfor i in range(m-1,-1,-1):\nprint(ansl[i])', 'n, m = map(int, input().split())\nA = []*m\nB = []*m\nfor i in range(m):\n A[i],B[i] =map(int, input().split())\n\nal = n*(n-1)//2\nansl = [al]\nd = list(range(m+1))\ndl = [[_] for _ in range(m+1)]\n\nfor i in range(m-1,0,-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 al -= len(dl[x])*len(dl[y])\n for i in dl[y]:\n d[i] = x\n dl[x] += dl[y]\n ansl.append(al)\n\nfor i in range(m-1,-1,-1):\n print(int(ansl[i]))', '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\nal = n*(n-1)//2\nansl = [al]\nd = list(range(n+1))\ndl = [[_] for _ in range(n+1)]\n\nfor i in range(m-1,0,-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 al -= len(dl[x])*len(dl[y])\n for i in dl[y]:\n d[i] = x\n dl[x] += dl[y]\n ansl.append(al)\n\nfor i in range(m-1,-1,-1):\n print(int(ansl[i]))\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s172196710', 's651677121', 's378326297'] | [3064.0, 3188.0, 39028.0] | [18.0, 21.0, 739.0] | [406, 436, 439] |
p03108 | u064246852 | 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,size):\n self.par = list(range(size))\n self.rank = [0]*size\n self.sizeof = [1]*size \n def find(self,x):\n if self.par[x] == x:\n return x\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n def union(self,x,y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n if self.rank[x] < self.rank[y]:\n tmp = self.sizeof[x]\n self.par[x] = y\n self.sizeof[y] += tmp\n else:\n tmp = self.sizeof[y]\n self.par[y] = x\n self.sizeof[x] += tmp\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n def same(self,x,y):\n return self.find(x) == self.find(y)\n def sizeOf(self,x): \n return self.sizeof[self.find(x)]\nN,M = map(int,input().split())\nab = []\nfor i in range(M):\n a,b = map(int,input().split())\n ab.append((a,b))\nuf = UnionFind(N+1)\nans = [0]*M\nans[M-1] = N*(N-1)//2\nfor i in range(M):\n a,b = ab[M-1-i][0],ab[M-1-i][1]\n if i != M-1:\n if uf.same(a,b):\n ans[M-2-i] = ans[M-1-i]\n else:\n ans[M-2-i] = ans[M-1-i] - uf.sizeOf(a)*uf.sizeOf(b)\n uf.union(a,b)\nprint(ans)', 'class UnionFind:\n def __init__(self,size):\n self.par = list(range(size))\n self.rank = [0]*size\n self.sizeof = [1]*size \n def find(self,x):\n if self.par[x] == x:\n return x\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n def union(self,x,y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n if self.rank[x] < self.rank[y]:\n tmp = self.sizeof[x]\n self.par[x] = y\n self.sizeof[y] += tmp\n else:\n tmp = self.sizeof[y]\n self.par[y] = x\n self.sizeof[x] += tmp\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n def same(self,x,y):\n return self.find(x) == self.find(y)\n def sizeOf(self,x): \n return self.sizeof[self.find(x)]\nN,M = map(int,input().split())\nab = []\nfor i in range(M):\n a,b = map(int,input().split())\n ab.append((a,b))\nuf = UnionFind(N+1)\nans = [0]*M\nans[M-1] = N*(N-1)//2\nfor i in range(M):\n a,b = ab[M-1-i][0],ab[M-1-i][1]\n if i != M-1:\n if uf.same(a,b):\n ans[M-2-i] = ans[M-1-i]\n else:\n ans[M-2-i] = ans[M-1-i] - uf.sizeOf(a)*uf.sizeOf(b)\n uf.union(a,b)\nfor i in range(M):\n print(ans[i])'] | ['Wrong Answer', 'Accepted'] | ['s456339905', 's380283693'] | [26488.0, 24088.0] | [786.0, 851.0] | [1294, 1320] |
p03108 | u067729694 | 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\nAB = []\n\nfor _ in range(M):\n A_i, B_i = map(int, input().split())\n AB.append([A_i, B_i])\n \n \nclass UnionFind(object):\n def __init__(self, n=1):\n self.par = [i for i in range(n)]\n self.rank = [0 for _ in range(n)]\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 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, M = map(int, input().split())\n\nAB = []\n\nfor _ in range(M):\n A_i, B_i = map(int, input().split())\n AB.append([A_i, B_i])\n\nclass UnionFind():\n def __init__(self, n):\n self.parent = [-1 for _ in range(n)] \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 def size(self, x):\n x = self.root(x)\n return -1 * self.parent[x]\n \n def union(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n x_size = self.size(x)\n y_size = self.size(y)\n if x_size < y_size:\n x, y = y, x\n self.parent[x] += self.parent[y]\n self.parent[y] = x\n return True\n \nmax_inconvenience = N * (N - 1) // 2 \nans = [max_inconvenience]\nuf = UnionFind(N)\nfor bridge in reversed(AB):\n x = uf.root(bridge[0] - 1)\n y = uf.root(bridge[1] - 1)\n\n if x != y:\n x_size = uf.size(x)\n y_size = uf.size(y)\n ans_tmp = max_inconvenience - x_size * y_size\n max_inconvenience = ans_tmp\n uf.union(x, y)\n else:\n ans_tmp = max_inconvenience\n ans.append(ans_tmp)\n \nfor a in reversed(ans[:-1]):\n print(a)'] | ['Wrong Answer', 'Accepted'] | ['s517878683', 's130628770'] | [19628.0, 27604.0] | [332.0, 794.0] | [997, 1326] |
p03108 | u075303794 | 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.parents = list(range(n))\n self.size = [1]*n\n \n def find(self,x):\n if self.parents[x] == x:\n return x\n\t\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.size[x]>self.size[y]:\n x,y=y,x\n\t\n self.size[x]+=self.size[y]\n self.parents[y] = x\n \n def sizeofset(self,x):\n return self.size[self.find(x)]\n\n\nN,M=map(int,input().split())\nuf = UnionFind(N)\n\ncnt=(N)*(N-1)//2\nL=[[int(x) for x in input().split()] for _ in range(M)]\nans=[]\n\nfor a,b in L[::-1]:\n ans.append(cnt)\n if uf.find(a)!=uf.find(b):\n cnt-= uf.sizeofset(a)*uf.sizeofset(b)\n uf.union(a,b)\n\nfor x in ans[::-1]:\n print(x)', 'class UnionFind():\n def __init__(self,n):\n self.parents = [-1]*n\n \n def find(self,x):\n if self.parents[x] < 0:\n return x\n\t\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\t\n self.parents[x]+=self.parents[y]\n self.parents[y] = x\n \n def same(self,x,y):\n return self.find(x) == self.find(y)\n \n def size(self,x):\n return abs(self.parents[self.find(x)])\n\n\nN,M=map(int,input().split())\nuf = UnionFind(N+1)\n\ncnt=(N)*(N-1)//2\nL=[[int(x) for x in input().split()] for _ in range(M)]\nans=[]\n\nfor a,b in L[::-1]:\n ans.append(cnt)\n if not uf.same(a,b):\n cnt -= uf.size(a)*uf.size(b)\n uf.union(a,b)\n\nfor x in ans[::-1]:\n print(x)'] | ['Runtime Error', 'Accepted'] | ['s278876870', 's409225421'] | [33988.0, 31156.0] | [508.0, 490.0] | [805, 841] |
p03108 | u076936237 | 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 math\n\nn, m = list(map(int, input().split()))\n\nbr = [list(map(int, input().split())) for _ in range(m)]\n\nans = []\n\ndef ncr(n, r):\n if n<r:\n return 0\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\nsubg = {i+1:i+1 for i in range(n)}\n\nnodes = {i+1:1 for i in range(n)}\n\nres = []\nr = ncr(n, 2)\n\ndef fetch(i):\n if i == subg[i]:\n return i\n j = fetch(subg[i])\n subg[i] = j\n return j\n\nfor a, b in reversed(br):\n # print(subg, nodes)\n\n if len(nodes.keys()) == 1:\n res.append(0)\n continue\n else:\n res.append(r)\n\n mi, ma = min(a,b), max(a,b)\n \n x = nodes[fetch(mi)] \n y = nodes[fetch(ma)]\n\n r += ncr(x, 2) + ncr(y, 2)\n r -= ncr(x+y, 2)\n\n v, w = max(fetch(mi), fetch(ma)), min(fetch(mi), fetch(ma))\n nodes[w] += nodes[v]\n \n subg[mi] = w\n subg[ma] = w\n\nfor i in reversed(res):\n print(i)\n\n', '\nn, m = list(map(int, input().split()))\n\nbr = [list(map(int, input().split())) for _ in range(m)]\n\nans = []\n\ndef nc2(n):\n if n<2:\n return 0\n return n * (n-1) // 2\n\n\nclass UnionFind:\n\n def __init__(self, size):\n self.table = [-1 for _ in range(size+1)]\n self.size = [1 for _ in range(size+1)]\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 s1 = self.find(x)\n s2 = self.find(y)\n if s1 != s2:\n if self.table[s1] != self.table[s2]:\n if self.table[s1] < self.table[s2]:\n self.table[s2] = s1\n self.size[s1] += self.size[s2]\n self.size[s2] = 0\n else:\n self.table[s1] = s2\n self.size[s2] += self.size[s1]\n self.size[s1] = 0\n else:\n self.table[s1] += -1\n self.table[s2] = s1\n self.size[s1] += self.size[s2]\n self.size[s2] = 0\n\n def get_size(self, x):\n s1 = self.find(x)\n return self.size[s1]\n\n def check_same(self, x, y):\n return self.find(x) == self.find(y)\n\nres = []\nr = nc2(n)\n\nuf = UnionFind(n)\n\nfor a, b in reversed(br):\n\n res.append(r)\n\n if not uf.check_same(a,b):\n r -= uf.get_size(a)*uf.get_size(b)\n\n uf.union(a,b)\n\nfor i in reversed(res):\n print(i)'] | ['Wrong Answer', 'Accepted'] | ['s848442944', 's080507642'] | [54872.0, 34204.0] | [2106.0, 793.0] | [920, 1458] |
p03108 | u080428180 | 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. | ['# find-union\n\nimport sys\ninput = sys.stdin.readline\n\n\ndef find(x):\n if par[x] == x:\n return x\n else:\n return find(par[x])\n\n\ndef unite(x,y):\n x = find(x)\n y = find(y)\n\n if x != y:\n \n if rank[x] < rank[y]:\n par[x] = y\n size[y] += size[x]\n else:\n par[y] = x\n size[x] += size[y]\n if rank[x] == rank[y]:\n rank[x] += 1\n\n\ndef same(x,y):\n return find(x) == find(y)\n\n#################################\n\n\nn,m = map(int,input().split())\n\npar = [0]*n \nfor i in range(n):\n par[i] = i\nrank = [1]*n \nsize = [1]*n \n\nedge = [tuple(map(int,input().split())) for i in range(m)]\nedge = edge[::-1]\n\nres = []\nfor i in range(m):\n fi = find(edge[i][0])\n se = find(edge[i][1])\n if fi == se:\n res.append(0)\n else:\n res.append(size[fi]*size[se])\n unite(fi,se)\nass = 0\nfor i in range(m):\n ass += res[m-1-i]\n print(ass)', '# find-union\n\nimport sys\ninput = sys.stdin.readline\n\n\ndef find(x):\n if par[x] == x:\n return x\n else:\n return find(par[x])\n\n\ndef unite(x,y):\n x = find(x)\n y = find(y)\n\n if x != y:\n \n if rank[x] < rank[y]:\n par[x] = y\n size[y] += size[x]\n else:\n par[y] = x\n size[x] += size[y]\n if rank[x] == rank[y]:\n rank[x] += 1\n\n\ndef same(x,y):\n return find(x) == find(y)\n\n#################################\n\n\nn,m = map(int,input().split())\n\npar = [0]*(n+1) \nfor i in range(n):\n par[i] = i\nrank = [1]*(n+1) \nsize = [1]*(n+1) \n\nedge = [tuple(map(int,input().split())) for i in range(m)]\nedge = edge[::-1]\n\nres = []\nfor i in range(m):\n fi = find(edge[i][0])\n se = find(edge[i][1])\n if fi == se:\n res.append(0)\n else:\n res.append(size[fi]*size[se])\n unite(fi,se)\nass = 0\nfor i in range(m):\n ass += res[m-1-i]\n print(ass)'] | ['Runtime Error', 'Accepted'] | ['s014016210', 's278902480'] | [22928.0, 24052.0] | [359.0, 445.0] | [1183, 1195] |
p03108 | u083960235 | 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, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom fractions import gcd\n \ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef S_MAP(): return map(str, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef S_LIST(): return list(map(str, input().split()))\n \nsys.setrecursionlimit(10 ** 9)\nINF = float(\'inf\')\nmod = 10 ** 9 + 7\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n \n \n self.parents = [-1] * n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n \n def size(self, x):\n return -self.parents[self.find(x)]\n 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 \n def __str__(self):\n return \'\\n\'.join(\'{}: {}\'.format(r, self.members(r)) for r in self.roots())\n\ndef C(n, r):\n return factorial(n) // (factorial(n - r) * factorial(r))\n\nN, M = MAP()\nL = [LIST() for i in range(M)]\n\ntree = UnionFind(N)\n\n# print(C(N, 2))\nans = [0] * M\nfor i in range(M-1, -1, -1):\n a, b = L[i]\n tree.union(a-1, b-1)\n moto = C(N, 2) \n for key, l in tree.all_group_members().items():\n if len(l) >= 2:\n moto -= C(len(l), 2)\n # print(moto)\n ans[i] = moto\n# print(ans)\nans.append(C(N, 2))\nfor a in ans[1:]:\n print(a)\n # print(dic)\n \n \n # group = tree.group_count()\n # print("g:", group)\n # if group >= 2:\n # ans = combinations_count(group, 2)\n \n \n # else:\n # ans = 0\n # print("ans,", ans)\n\n\n ', 'import sys, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\n\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef S_MAP(): return map(str, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef S_LIST(): return list(map(str, input().split()))\n \nsys.setrecursionlimit(10 ** 9)\nINF = float(\'inf\')\nmod = 10 ** 9 + 7\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n \n \n self.parents = [-1] * n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n \n def size(self, x):\n return -self.parents[self.find(x)]\n 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 \n def __str__(self):\n return \'\\n\'.join(\'{}: {}\'.format(r, self.members(r)) for r in self.roots())\n\nN, M = MAP()\nL = [LIST() for i in range(M)]\ngraph = defaultdict(list)\ntree = UnionFind(N)\ngroup = tree.group_count()\nprint(group)\n\nd = group * (group - 1) // 2\n# ans = [0] * M\nans = []\nans.append(d)\nfor a, b in L[::-1]:\n e = deepcopy(d)\n tree.union(a-1, b-1)\n r = tree.all_group_members()\n \n # print(r)\n for k, v in r.items():\n if len(v) > 1:\n e -= len(v) * (len(v) - 1) // 2\n ans.append(e)\n\nans = ans[:-1]\nans = ans[::-1]\n \nprint(*ans, sep="\\n")\n # tree[b-1].append(a-1)\n # group = tree.group_count()\n # print(group)\n # print(group * (group - 1) // 2)\n\n\n', 'import sys, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\n\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef S_MAP(): return map(str, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef S_LIST(): return list(map(str, input().split()))\n \nsys.setrecursionlimit(10 ** 9)\nINF = float(\'inf\')\nmod = 10 ** 9 + 7\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n \n \n self.parents = [-1] * n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n \n def size(self, x):\n return -self.parents[self.find(x)]\n 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 \n def __str__(self):\n return \'\\n\'.join(\'{}: {}\'.format(r, self.members(r)) for r in self.roots())\n\nN, M = MAP()\nL = [LIST() for i in range(M)]\ngraph = defaultdict(list)\ntree = UnionFind(N)\n\nd = N * (N - 1) // 2\n# ans = [0] * M\nans = []\nans.append(d)\nfor a, b in L[::-1]:\n \n if not tree.same(a-1, b-1):\n d -= tree.size(a-1) * tree.size(b-1)\n tree.union(a-1, b-1)\n ans.append(d)\nans = ans[:-1]\nans = ans[::-1]\n\nprint(*ans, sep="\\n")\n # tree[b-1].append(a-1)\n # group = tree.group_count()\n # print(group)\n # print(group * (group - 1) // 2)\n\n\n'] | ['Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s213216170', 's424057750', 's585175619'] | [35332.0, 33628.0, 37576.0] | [2109.0, 2106.0, 666.0] | [3047, 2944, 2819] |
p03108 | u087917227 | 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())\ntmp = N*(N-1)//2\nl = []\ncnt = []\nab = [list(map(int, input().split())) for i in range(M)]\n# print(ans)\nherasu = 0\nans = [tmp]\nfor i in ab[::-1]:\n \n if (i[0] in cnt) and (i[1] in cnt):\n\n flag = False\n for index, l1 in enumerate(l):\n print(l1, i)\n if (i[0] in l1) and (i[1] in l1):\n flag = True\n elif i[0] in l1:\n tmp0 = l1\n elif i[1] in l1:\n tmp1 = l1\n if flag == False:\n herasu += len(tmp0)*len(tmp1)\n# print(l,tmp0,tmp1)\n l.remove(tmp0)\n l.remove(tmp1)\n l.append(tmp1+tmp0)\n \n \n \n if (i[0] not in cnt) and (i[1] not in cnt):\n\n cnt += [i[0],i[1]]\n l.append(i)\n herasu += 1\n \n else:\n\n for l1 in l:\n# print(l1)\n if i[0] in l1:\n\n herasu += len(l1)\n l1.append(i[1])\n break\n if i[1] in l1:\n\n \n herasu += len(l1)\n l1.append(i[0])\n break\n \n ans.append(tmp-herasu)\n \nfor i in ans[::-1][1:]:\n print(i if i>=0 else 0)\n', 'class UnionFind:\n def __init__(self,size):\n self.par = [i for i in range(size)]\n self.rank = [0 for _ in range(size)]\n self.size = [1 for _ in range(size)]\n \n \n def find(self,x):\n if self.par[x] == x:\n return x\n else:\n return self.find(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[y] = x\n self.size[x] += self.size[y]\n else:\n self.par[x] = y\n self.size[y] += self.size[x]\n if self.rank[x] == self.rank[y]:\n self.rank[y] += 1\n \n \n def same(self,x,y):\n return self.find(x) == self.find(y)\n \nN,M = map(int,input().split())\ns = N*(N-1)//2\nans = []\nab = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]\n\ntree = UnionFind(N)\n\nfor index, bridge in enumerate(ab[::-1]):\n if tree.same(bridge[0],bridge[1]):\n ans.append(s)\n else:\n d = tree.size[tree.find(bridge[0])] * tree.size[tree.find(bridge[1])]\n tree.union(bridge[0],bridge[1])\n s -= d\n ans.append(s)\nprint("\\n".join(map(str, ans[::-1])))', 'N,M = map(int,input().split())\ntmp = N*(N-1)//2\nl = []\ncnt = []\nab = [list(map(int, input().split())) for i in range(M)]\n# print(ans)\nherasu = 0\nans = [tmp]\nfor i in ab[::-1]:\n \n if (i[0] in cnt) and (i[1] in cnt):\n\n for index, l1 in enumerate(l):\n if i[0] in l1:\n tmp0 = index\n if i[1] in l1:\n tmp1 = index\n herasu += len(l[tmp0])*len(l[tmp1])\n del(l[tmp0])\n del(l[tmp1])\n l.append(l[tmp0]+l[tmp1])\n \n \n if (i[0] not in cnt) and (i[1] not in cnt):\n\n cnt += [i[0],i[1]]\n l.append(i)\n herasu += 1\n \n else:\n\n for l1 in l:\n# print(l1)\n if i[0] in l1:\n\n herasu += len(l1)\n l1.append(i[1])\n break\n if i[1] in l1:\n \n herasu += len(l1)\n l1.append(i[0])\n break\n \n ans.append(tmp-herasu)\n \nfor i in ans[::-1][1:]:\n print(i)\n', 'class UnionFind:\n def __init__(self,size):\n self.par = [i for i in range(size)]\n self.rank = [0 for _ in range(size)]\n self.size = [1 for _ in range(size)]\n \n \n def find(self,x):\n if self.par[x] == x:\n return x\n else:\n return self.find(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[y] = x\n self.size[x] += self.size[y]\n else:\n self.par[x] = y\n self.size[y] += self.size[x]\n if self.rank[x] == self.rank[y]:\n self.rank[y] += 1\n \n \n def same(self,x,y):\n return self.find(x) == self.find(y)\n \nN,M = map(int,input().split())\ns = N*(N-1)//2\nans = []\nab = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]\n\ntree = UnionFind(N)\n\nfor index, bridge in enumerate(ab[::-1]):\n if tree.same(bridge[0],bridge[1]):\n ans.append(s)\n else:\n d = tree.size[tree.find(bridge[0])] * tree.size[tree.find(bridge[1])]\n tree.union(bridge[0],bridge[1])\n ans.append(s)\n s -= d\n \nprint("\\n".join(map(str, ans[::-1])))'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s002564642', 's447413964', 's499061857', 's809484756'] | [93628.0, 42676.0, 30736.0, 42672.0] | [2105.0, 858.0, 2105.0, 873.0] | [1432, 1315, 1172, 1324] |
p03108 | u095426154 | 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())\nbridge=[[] for i in range(m)]\niland=[[i+1] for i in range(n)]\nfor i in range(m):\n bridge[i]=list(map(int,input().split()))\nans=[0 for i in range(m+1)]\nans[0]=int((n-1)*n/2)\nk=1\nfor i in reversed(bridge):\n ans[k]=ans[k-1]\n for j in range(i[0]):\n if i[0] in iland[j]:\n temp=j\n break\n for j in range(i[1]):\n if i[1] in iland[j]:\n if temp!=j:\n ans[k]=ans[k-1]-len(iland[j])*len(iland[temp])\n iland[j].extend(iland[temp])\n del iland[temp]\n break\n if ans[k]==0:\n ans[k:]=[0 for l in range(m-k)]\n break\n k+=1\nfor i in range(m):\n print(ans[m-1-i])', 'n,m=map(int,input().split())\nbridge=[[] for i in range(m)]\nleader=[i for i in range(n+1)]\nmember=[1 for i in range(n+1)]\nfor i in range(m):\n bridge[i]=list(map(int,input().split()))\nans=[0 for i in range(m+1)]\nans[0]=int((n-1)*n/2)\nk=1\nfor i in reversed(bridge):\n print(leader)\n print(member)\n le0=leader[i[0]]\n le1=leader[i[1]]\n if le0!=le1:\n ans[k]=ans[k-1]-member[le0]*member[le1]\n if member[le0]>=member[le1]:\n member[le0]+=member[le[1]]\n leader[i[1]]=le0\n else:\n member[le1]+=member[le0]\n leader[i[0]]=le1\n else:\n ans[k]=ans[k-1]\n if ans[k]==0:\n ans[k:]=[0 for l in range(m-k)]\n break\n k+=1\nfor i in range(m):\n print(ans[m-1-i])', 'n,m=map(int,input().split())\nbridge=[[] for i in range(m)]\nleader=[i for i in range(n+1)]\nmember=[1 for i in range(n+1)]\nfor i in range(m):\n bridge[i]=list(map(int,input().split()))\nans=[0 for i in range(m+1)]\nans[0]=int((n-1)*n/2)\nk=1\nfor i in reversed(bridge):\n le0=leader[i[0]]\n le1=leader[i[1]]\n while le0!=leader[le0]:\n le0=leader[le0]\n leader[i[0]]=le0\n \n while le1!=leader[le1]:\n le1=leader[le1]\n leader[i[1]]=le1\n \n if le0!=le1:\n ans[k]=ans[k-1]-member[le0]*member[le1]\n if member[le0]>=member[le1]:\n member[le0]+=member[le1]\n leader[le1]=le0\n else:\n member[le1]+=member[le0]\n leader[le0]=le1\n else:\n ans[k]=ans[k-1]\n if ans[k]==0:\n ans[k:]=[0 for l in range(m-k)]\n break\n k+=1\nfor i in range(m):\n print(ans[m-1-i])'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s073283285', 's481653696', 's702662062'] | [43800.0, 35072.0, 35024.0] | [2107.0, 375.0, 635.0] | [710, 749, 881] |
p03108 | u096616343 | 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 \nN, M = map(int,input().split())\nbridge = []\nfor i in range(M):\n A, B = map(int,input().split())\n bridge.append((A - 1, B - 1))\n \nuf = UnionFind(N)\nans = N * (N - 1) // 2\ncnt = 0\nfor i in range(M):\n A, B = bridge[i]\n if not same(A, B):\n cnt += size(A) * size(B)\n union(A, B)\n print(ans - cnt)", "class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\n \nN, M = map(int,input().split())\nbridge = []\nfor i in range(M):\n A, B = map(int,input().split())\n bridge.append((A - 1, B - 1))\n \nuf = UnionFind(N)\nans = N * (N - 1) // 2\ncnt = 0\nfor i in range(M):\n A, B = bridge[i]\n if not uf.same(A, B):\n cnt += uf.size(A) * uf.size(B)\n uf.union(A, B)\n print(ans - cnt)", '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 \n\n \nN, M = map(int,input().split())\nbridge = []\nfor i in range(M):\n A, B = map(int,input().split())\n bridge.append((A - 1, B - 1))\n \nuf = UnionFind(N)\nans = [N * (N - 1) // 2]\ncnt = 0\nfor i in range(M - 1):\n A, B = bridge[-i-1]\n if not uf.same(A, B):\n cnt += uf.size(A) * uf.size(B)\n uf.union(A, B)\n ans.append(ans[0] - cnt)\nfor i in range(M):\n print(ans[-i-1])'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s251445691', 's529565787', 's580617996'] | [17412.0, 20420.0, 22536.0] | [316.0, 775.0, 794.0] | [1475, 1487, 1081] |
p03108 | u099566485 | 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 IL(): return list(map(int,input().split()))\ndef SL(): return input().split()\ndef I(): return int(input())\ndef S(): return list(input())\n\nclass UnionFind(object):\n \n def __init__(self, n):\n self.par = [i for i in range(n)]\n self.rank = [0 for i in range(n)]\n self.size=[1 for i in range(n)]\n \n def find(self, x):\n \n if self.par[x] == x:\n return x\n else:\n return self.find(self.par[x])\n \n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n 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 self.size[x]+=self.size[y]\n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n \nn,m=IL()\nl=[[0,0] for i in range(m)]\npar=[1 for i in range(n)]\nfor i in range(m):\n a,b=IL()\n l[i]=[a-1,b-1]\nans=[0 for i in range(m)]\nuf=UnionFind(n)\nt_ans=n*(n-1)/2\nans[-1]=t_ans\nfor i in range(m-1):\n a=uf.find(l[-1-i][0])\n b=uf.find(l[-1-i][1])\n \n if a!=b:\n t_ans-=uf.size[a]*uf.size[b]\n uf.union(a,b)\n ans[-2-i]=t_ans\nfor i in range(m):\n print(ans[i])', 'def IL(): return list(map(int,input().split()))\ndef SL(): return input().split()\ndef I(): return int(input())\ndef S(): return list(input())\n\nclass UnionFind(object):\n \n def __init__(self, n):\n self.par = [i for i in range(n)]\n self.rank = [0 for i in range(n)]\n self.size=[1 for i in range(n)]\n \n def find(self, x):\n \n if self.par[x] == x:\n return x\n else:\n return self.find(self.par[x])\n \n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n 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 self.size[x]+=self.size[y]\n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n \nn,m=IL()\nl=[[0,0] for i in range(m)]\npar=[1 for i in range(n)]\nfor i in range(m):\n a,b=IL()\n l[i]=[a-1,b-1]\nans=[0 for i in range(m)]\nuf=UnionFind(n)\nt_ans=n*(n-1)/2\nans[-1]=t_ans\nfor i in range(m-1):\n a=uf.find(l[-1-i][0])\n b=uf.find(l[-1-i][1])\n \n if a!=b:\n t_ans-=uf.size[a]*uf.size[b]\n uf.union(a,b)\n ans[-2-i]=t_ans\nfor i in range(m):\n print(int(ans[i]))'] | ['Wrong Answer', 'Accepted'] | ['s395918222', 's196633120'] | [30164.0, 29952.0] | [784.0, 834.0] | [1383, 1388] |
p03108 | u119982147 | 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 __slots__ = ['parent']\n \n \n\n def __init__(self, n):\n self.parent = [-1] * 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 union(self, x, y):\n parent_x = self.find(x)\n parent_y = self.find(y)\n\n if parent_x != parent_y:\n if self.parent[parent_x] < self.parent[parent_y]:\n self.parent[parent_x] += self.parent[parent_y]\n self.parent[parent_y] = parent_x\n else:\n self.parent[parent_y] += self.parent[parent_x]\n self.parent[parent_x] = parent_y\n\n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n while self.parent[x] >= 0:\n x = self.find(self.parent[x])\n return abs(self.parent[x])\n\n\nn, m = map(int, input().split())\n\nbrige = [list(map(int, input().split())) for _ in range(m)]\n\nuf = UnionFind(n)\nans = [0] * m\nans[m-1] = int(n*(n-1)/2)\n\nfor i in range(m-1, 0, -1):\n a = brige[i][0]-1\n b = brige[i][1]-1\n if uf.find(a) != uf.find(b):\n print(uf.size(a), uf.size(b))\n ans[i-1] = ans[i] - uf.size(a)*uf.size(b)\n else:\n ans[i-1] = ans[i]\n uf.union(a, b)\n\nfor ans_i in ans:\n print(int(ans_i))\n", "class UnionFind():\n __slot__ = ['parent']\n \n \n\n def __init__(self, n):\n self.parent = [-1] * 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 union(self, x, y):\n parent_x = self.find(x)\n parent_y = self.find(y)\n\n if parent_x != parent_y:\n if self.parent[parent_x] < self.parent[parent_y]:\n self.parent[parent_x] += self.parent[parent_y]\n self.parent[parent_y] = parent_x\n else:\n self.parent[parent_y] += self.parent[parent_x]\n self.parent[parent_x] = parent_y\n\n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n while self.parent[x] >= 0:\n x = self.find(self.parent[x])\n return abs(self.parent[x])\n\n\nn, m = map(int, input().split())\n\nbrige = [list(map(int, input().split())) for _ in range(m)]\n\nuf = UnionFind(n)\nans = [0] * m\nans[m-1] = int(n*(n-1)/2)\n\nfor i in range(m-1, 0, -1):\n a = brige[i][0]-1\n b = brige[i][1]-1\n if uf.find(a) != uf.find(b):\n print(uf.size(a), uf.size(b))\n ans[i-1] = ans[i] - uf.size(a)*uf.size(b)\n else:\n ans[i-1] = ans[i]\n uf.union(a, b)\n\nfor ans_i in ans:\n print(ans_i)\n", "class UnionFind():\n __slots__ = ['parent']\n \n \n\n def __init__(self, n):\n self.parent = [-1] * 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 union(self, x, y):\n parent_x = self.find(x)\n parent_y = self.find(y)\n\n if parent_x != parent_y:\n if self.parent[parent_x] < self.parent[parent_y]:\n self.parent[parent_x] += self.parent[parent_y]\n self.parent[parent_y] = parent_x\n else:\n self.parent[parent_y] += self.parent[parent_x]\n self.parent[parent_x] = parent_y\n\n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n while self.parent[x] >= 0:\n x = self.find(self.parent[x])\n return abs(self.parent[x])\n\n\nn, m = map(int, input().split())\n\nbrige = [list(map(int, input().split())) for _ in range(m)]\n\nuf = UnionFind(n)\nans = [0] * m\nans[m-1] = int(n*(n-1)/2)\n\nfor i in range(m-1, 0, -1):\n a = brige[i][0]-1\n b = brige[i][1]-1\n if uf.find(a) != uf.find(b):\n ans[i-1] = ans[i] - uf.size(a)*uf.size(b)\n else:\n ans[i-1] = ans[i]\n uf.union(a, b)\n\nfor ans_i in ans:\n print(int(ans_i))"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s099180561', 's275869780', 's819034007'] | [37552.0, 37544.0, 36544.0] | [1023.0, 1051.0, 781.0] | [1455, 1449, 1416] |
p03108 | u129315407 | 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())\nAi = [list(map(int, input().split())) for _ in range(M)]\n\ngroups = [-1 for i in range(N + 1)] \nsizes = [1 for _ in range(N + 1)]\nAi.reverse()\n\nvalue = N * (N - 1) // 2\nanswers = []\nanswers.append(value)\n\ndef parent(n):\n if groups[n] < 0:\n return n\n return parent(groups[n])\n\nfor a in Ai:\n if value <= 0:\n answers.append(0)\n continue\n p1 = parent(a[0])\n p2 = parent(a[1])\n if p1 == p2:\n answers.append(value)\n continue\n\n value -= sizes[p1] * sizes[p2]\n if p1 > p2:\n sizes[p2] += sizes[p1]\n groups[p1] = p2\n else:\n sizes[p2] += sizes[p1]\n groups[p2] = p1\n answers.append(value)\n\nanswers.reverse()\nanswers = answers[1:]\nfor a in answers:\n print(a)', 'N, M = map(int, input().split())\nAi = [list(map(int, input().split())) for _ in range(M)]\n\ngroups = [-1 for i in range(N + 1)] \nsizes = [1 for _ in range(N + 1)]\nAi.reverse()\n\nvalue = N * (N - 1) // 2\nanswers = []\nanswers.append(value)\n\ndef parent(n):\n if groups[n] < 0:\n return n\n return parent(groups[n])\n\nfor a in Ai:\n if value <= 0:\n answers.append(0)\n continue\n p1 = parent(a[0])\n p2 = parent(a[1])\n if p1 == p2:\n answers.append(value)\n continue\n\n value -= sizes[p1] * sizes[p2]\n if p1 > p2:\n sizes[p2] += sizes[p1]\n groups[p1] = p2\n else:\n sizes[p1] += sizes[p2]\n groups[p2] = p1\n answers.append(value)\n\nanswers.reverse()\nanswers = answers[1:]\nfor a in answers:\n print(a)'] | ['Wrong Answer', 'Accepted'] | ['s157306816', 's259101661'] | [35624.0, 34216.0] | [752.0, 751.0] | [796, 796] |
p03108 | u138253748 | 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 itertools\n\ndef findRoot(uf,value):\n if uf[value]==None:\n return value\n else:\n uf[value]=findRoot(uf,uf[value])\n return uf[value]\n\nn,m=[int(x) for x in input().split(' ')]\n\nuf=[None]*n\nb=[]\ns=[1]*n\nr=[]\n\nfor x in range(0,m):\n b.append([int(x)-1 for x in input().split(' ')])\n\nfor x in b[::-1]:\n r1=findRoot(uf,x[0])\n r2=findRoot(uf,x[1])\n\n if r1==r2:\n r.append(0)\n else:\n r.append(s[r1]*s[r2])\n\n if s[r1]<s[r2]:\n uf[r2]=r1\n s[r1]+=s[r2]\n else\n uf[r1]=r2\n s[r2]+=s[r1]\n\n\nfor x in itertools.accumulate(r[::-1]):\n print(x)", "import itertools\nimport sys\n\ndef findRoot(uf,value):\n if uf[value]==None:\n return value\n else:\n\n uf[value]=findRoot(uf,uf[value])\n return uf[value]\n\n\nsys.setrecursionlimit(50000)\nn,m=[int(x) for x in input().split(' ')]\n\nuf=[None]*n\nb=[]\ns=[1]*n\nr=[]\n\nfor x in range(0,m):\n b.append([int(x)-1 for x in input().split(' ')])\n\nfor x in b[::-1]:\n r1=findRoot(uf,x[0])\n r2=findRoot(uf,x[1])\n\n if r1==r2:\n r.append(0)\n else:\n r.append(s[r1]*s[r2])\n\n uf[r2]=r1\n s[r1]+=s[r2]\n\nfor x in itertools.accumulate(r[::-1]):\n print(x)\n"] | ['Runtime Error', 'Accepted'] | ['s495113584', 's991596295'] | [3064.0, 41444.0] | [18.0, 590.0] | [587, 574] |
p03108 | u147687635 | 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. | ['from itertools import groupby\n \nclass UnionFind:\n \n def __init__(self, n):\n self.n = n\n self.parents = list(range(n))\n self.rank = [0] * n\n self.size = [1] * n\n \n def find(self, x):\n if self.parents[x] == x:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n def union(self, x, y):\n root_x = self.find(x)\n root_y = self.find(y)\n if self.rank[root_x] < self.rank[root_y]:\n self.parents[root_x] = root_y\n self.size[root_y] += self.size[root_x]\n else:\n self.parents[root_y] = root_x\n self.size[root_x] += self.size[root_y]\n if self.rank[root_x] == self.rank[root_y]:\n self.rank[x] += 1\n \n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n \n def get_size(self, x):\n return self.size[self.find(x)]\n \n def get_group(self):\n arr = sorted([(self.find(node), node) for node in range(self.n)])\n groups = []\n for _, g in groupby(arr, key=lambda x: x[0]):\n groups.append([u[1] for u in g])\n return groups\n\n \nN, M = map(int, input().split())\nbridges = []\nfor _ in range(M):\n bridges.append(list(map(lambda x: int(x)-1, input().split())))\nU = UnionFind(N)\nF = [N * (N-1) // 2]\nfor i in range(M-1):\n F.append(F[i] - U.get_size(bridges[M-i-1][0]) * U.get_size(bridges[M-i-1][1]))\n U.union(*bridges[M-i-1])\nF.reverse()\nfor f in F:\n print(f)', 'from itertools import groupby\n\nclass UnionFind:\n\n def __init__(self, n):\n self.n = n\n self.parents = list(range(n))\n self.rank = [0] * n\n self.size = [1] * n\n\n def find(self, x):\n if self.parents[x] == x:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n def union(self, x, y):\n root_x = self.find(x)\n root_y = self.find(y)\n if self.rank[root_x] < self.rank[root_y]:\n self.parents[root_x] = root_y\n self.size[root_y] += self.size[root_x]\n else:\n self.parents[root_y] = root_x\n self.size[root_x] += self.size[root_y]\n if self.rank[root_x] == self.rank[root_y]:\n self.rank[x] += 1\n \n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n\n def get_size(self, x):\n return self.size[self.find(x)]\n\n def get_group(self):\n arr = sorted([(self.find(node), node) for node in range(self.n)])\n groups = []\n for _, g in groupby(arr, key=lambda x: x[0]):\n groups.append([u[1] for u in g])\n return groups\n\nN, M = map(int, input().split())\nbridges = []\nfor _ in range(M):\n bridges.append(list(map(lambda x: int(x)-1, input().split())))\n\nU = UnionFind(N)\nF = [N * (N-1) / 2]\nfor i in range(M-1):\n F.append(F[-1] - U.get_size(bridges[M-i-1][0]) * U.get_size(bridges[M-i-1][1]))\n F.append(U.union(*bridges[M-i-1]))\nfor f in F.reverse():\n print(f)', 'from itertools import groupby\n \nclass UnionFind:\n \n def __init__(self, n):\n self.n = n\n self.parents = list(range(n))\n self.rank = [0] * n\n self.size = [1] * n\n \n def find(self, x):\n if self.parents[x] == x:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n def union(self, x, y):\n root_x = self.find(x)\n root_y = self.find(y)\n if self.rank[root_x] < self.rank[root_y]:\n self.parents[root_x] = root_y\n self.size[root_y] += self.size[root_x]\n else:\n self.parents[root_y] = root_x\n self.size[root_x] += self.size[root_y]\n if self.rank[root_x] == self.rank[root_y]:\n self.rank[x] += 1\n \n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n \n def get_size(self, x):\n return self.size[self.find(x)]\n \n def get_group(self):\n arr = sorted([(self.find(node), node) for node in range(self.n)])\n groups = []\n for _, g in groupby(arr, key=lambda x: x[0]):\n groups.append([u[1] for u in g])\n return groups\n\n \nN, M = map(int, input().split())\nbridges = []\nfor _ in range(M):\n bridges.append(list(map(lambda x: int(x)-1, input().split())))\nU = UnionFind(N)\nF = [N * (N-1) // 2]\nfor i in range(M-1):\n if not U.is_same(*bridges[M-i-1]):\n F.append(F[i] - U.get_size(bridges[M-i-1][0]) * U.get_size(bridges[M-i-1][1]))\n U.union(*bridges[M-i-1])\n else:\n F.append(F[i])\nF.reverse()\nfor f in F:\n print(f)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s402997025', 's672721826', 's401145712'] | [154468.0, 32948.0, 35028.0] | [2113.0, 431.0, 925.0] | [1540, 1531, 1620] |
p03108 | u160244242 | 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())\nlst = [list(map(int, input().split())) for _ in range(m)]\n\nlst = list(reversed(lst))\n\npossible_route = n*(n-1)/2\nans = [possible_route]\nroute_lst = []\n\nfor pair in lst:\n new_route_lst = []\n index0 = -1\n index1 = -1\n for k, route in enumerate(route_lst):\n if pair[0] in route:\n index0 = k\n if pair[1] in route:\n index1 = k\n if index0 >= 0 and index1 >= 0 and index1 != index0:\n route = set(route_lst[index0]) | set(route_lst[index1]) \n new_route_lst.append(list(route))\n elif index0 >= 0:\n route = set(route_lst[index1]) | set(pair)\n new_route_lst.append(list(route))\n elif index1 >= 0:\n route = set(route_lst[index1]) | set(pair)\n new_route_lst.append(list(route))\n else:\n new_route_lst.append(pair)\n for k, route in enumerate(route_lst):\n if k == index0 or k == index1:\n pass\n else:\n new_route_lst.append(route)\n \n count = 0 \n for k in new_route_lst:\n m = len(k)\n count += m*(m-1)/2\n \n ans.append(possible_route - count)\n \n route_lst = new_route_lst\n\nfor i in reversed(ans):\n print(int(i))', 'class UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n+1)]\n self.rank = [0] * (n+1)\n self.sizes = [1] * (n+1)\n self.root = [1] * (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 self.root[x] = -1\n self.sizes[y] += self.sizes[x]\n else:\n self.par[y] = x\n self.root[y] = -1\n self.sizes[x] += self.sizes[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n \n \n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n \n def size(self, x):\n return self.sizes[find(x)]\n \n \nn, m = map(int, input().split())\nlst = [list(map(int, input().split())) for _ in range(m)]\n \nall_comb = n*(n-1)/2\n \na = UnionFind(n)\n \nans = [all_comb]\nfor pair in reversed(lst):\n if a.same_check(pair[0], pair[1]):\n ans.append(ans[-1])\n pass\n else:\n ans.append(ans[-1] - a.sizes[a.find(pair[0])]*a.sizes[a.find(pair[1])])\n a.union(pair[0], pair[1])\n \nfor i in reversed(ans[:-1]):\n print(int(i))'] | ['Wrong Answer', 'Accepted'] | ['s062806819', 's403724222'] | [28652.0, 38584.0] | [2105.0, 896.0] | [1212, 1424] |
p03108 | u166306121 | 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. | ["from sys import stdin\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [-1 for i in range(n + 1)]\n\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 \n \n def union(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n if self.par[x] > self.par[y]:\n x, y = y, x\n self.par[x] += self.par[y]\n self.par[y] = x\n\n \n def issame(self, x, y):\n return self.root(x) == self.root(y)\n\n \n def size(self, x):\n return -self.par[self.root(x)]\n\n\nif __name__ == '__main__':\n N, M = list(map(int, input().split()))\n # print(Town.par)\n Island = UnionFind(N)\n A = [None]*M\n B = [None]*M\n cntlist = [0]*M\n cnt = N*(N-1)//2\n for i in range(M):\n A[i],B[i] = map(int,stdin.readline().rstrip('\\n').split())\n \n for i in range(M-1,0,-1):\n if Island.root(A[i]) == Island.root(B[i]):\n continue\n else:\n cnt -= (Island.size(A[i]))*(Island.size(B[i]))\n Island.union(A[i],B[i])\n \n # print(Island.size(i),end=',')\n # print()\n # print(cnt)\n cntlist[i] = cnt\n\n print(Island.par)\n for i in range(1,M):\n print(cntlist[i])\n print(N*(N-1)//2)", "from sys import stdin\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [-1 for i in range(n + 1)]\n\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 \n \n def union(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n if self.par[x] > self.par[y]:\n x, y = y, x\n self.par[x] += self.par[y]\n self.par[y] = x\n\n \n def issame(self, x, y):\n return self.root(x) == self.root(y)\n\n \n def size(self, x):\n return -self.par[self.root(x)]\n\n\nif __name__ == '__main__':\n N, M = list(map(int, input().split()))\n # print(Town.par)\n Island = UnionFind(N)\n A = [None]*M\n B = [None]*M\n cntlist = [0]*M\n cnt = N*(N-1)//2\n for i in range(M):\n A[i],B[i] = map(int,stdin.readline().rstrip('\\n').split())\n \n for i in range(M-1,0,-1):\n if Island.root(A[i]) == Island.root(B[i]):\n cntlist[i] = cnt\n continue\n else:\n cnt -= (Island.size(A[i]))*(Island.size(B[i]))\n Island.union(A[i],B[i])\n \n # print(Island.size(i),end=',')\n # print()\n # print(cnt)\n cntlist[i] = cnt\n\n print(Island.par)\n for i in range(1,M):\n print(cntlist[i])\n print(N*(N-1)//2)", "from sys import stdin\nclass UnionFind:\n def __init__(self, n):\n \n self.par = [-1 for i in range(n + 1)]\n\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 \n \n def union(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n if self.par[x] > self.par[y]:\n x, y = y, x\n self.par[x] += self.par[y]\n self.par[y] = x\n\n \n def issame(self, x, y):\n return self.root(x) == self.root(y)\n\n \n def size(self, x):\n return -self.par[self.root(x)]\n\n\nif __name__ == '__main__':\n N, M = list(map(int, input().split()))\n # print(Town.par)\n Island = UnionFind(N)\n A = [None]*M\n B = [None]*M\n cntlist = [0]*M\n cnt = N*(N-1)//2\n for i in range(M):\n A[i],B[i] = map(int,stdin.readline().rstrip('\\n').split())\n \n for i in range(M-1,0,-1):\n if Island.root(A[i]) == Island.root(B[i]):\n cntlist[i] = cnt\n continue\n else:\n cnt -= (Island.size(A[i]))*(Island.size(B[i]))\n Island.union(A[i],B[i])\n \n # print(Island.size(i),end=',')\n # print()\n # print(cnt)\n cntlist[i] = cnt\n\n print(Island.par)\n for i in range(1,M):\n print(cntlist[i])\n print(N*(N-1)//2)", "import sys\ninput = sys.stdin.readline\ndef ii(): return int(input())\ndef mi(): return map(int, input().rstrip().split())\ndef lmi(): return list(map(int, input().rstrip().split()))\ndef li(): return list(input().rstrip())\n# template\n\n\n# BEGIN CUT HERE\nsys.setrecursionlimit(100000)\nclass UnionFind():\n \n def __init__(self,n):\n self.data = [-1] * n\n \n def unite(self, x, y):\n \n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n elif self.data[x] < self.data[y]:\n x, y = y, x # swap\n self.data[x] += self.data[y]\n self.data[y] = x\n \n def find(self, x):\n \n if self.data[x] < 0:\n return x\n self.data[x] = self.find(self.data[x])\n return self.data[x]\n\n def same(self, x, y):\n \n return self.find(x) == self.find(y)\n \n def size(self, x):\n \n return self.data[self.find(x)]\n \n# END CUT HERE\n\ndef ABC120_D():\n n, m = mi()\n a = [0] * m\n b = [0] * m\n for i in range(m):\n a[i], b[i] = mi()\n \n uf = UnionFind(n)\n ans = [0] * (m + 1)\n ans[m] = n * (n - 1) // 2\n\n for i in range(m - 1, -1, -1):\n a[i] -= 1\n b[i] -= 1\n ans[i] = ans[i + 1]\n if uf.same(a[i], b[i]):\n continue\n \n x = uf.size(a[i])\n y = uf.size(b[i])\n ans[i] -= x * y\n \n uf.unite(a[i],b[i])\n \n for i in range(1, m + 1):\n print(ans[i])\n\n# verified on 2019/06/23\n\n\n\nif __name__ == '__main__':\n ABC120_D()\n"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s354150343', 's667575182', 's956483570', 's167841077'] | [17788.0, 17780.0, 17792.0, 47092.0] | [621.0, 627.0, 613.0, 627.0] | [1787, 1820, 1820, 1859] |
p03108 | u171366497 | 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())\nbranch=[tuple(map(int,input().split())) for _ in range(m)]\ncango=dict()\nres=[0]\ndata=[0 for _ in range(1+n)]\n\ndef calc(k):\n return 1/2*k*(k-1)\n\ndef search(data,x):\n bef=x\n while data[x]>0:\n data[bef]=data[x]\n bef=x\n x=data[x]\n return x,data[x]\n\nfor i in range(m):\n a,b=branch.pop()\n aroot,aidx=search(data,a)\n broot,bidx=search(data,b)\n if aidx!=0:aset=cango[aidx]\n if bidx!=0:bset=cango[bidx]\n lena=len(aset)\n lenb=len(bset)\n if aidx==0 and bidx==0:\n data[a]=-1*a\n data[b]=a\n cango[-1*a]={a,b}\n elif aidx==bidx and aidx!=0:\n res.append(res[-1])\n continue\n elif aidx==0 and bidx!=0:\n cango[bidx]|={a,}\n data[a]=broot\n elif aidx!=0 and bidx==0:\n cango[aidx]|={b,}\n data[b]=aroot\n elif aidx!=0 and bidx!=0 and aidx!=bidx:\n cango.pop(bidx)\n cango[aidx]|=bset\n data[broot]=aroot\n res.append(res[-1]-calc(lena)-calc(lenb)+calc(lena+lenb))\n\nfor j in range(m-1,-1,-1):\n print(int(res[m]-res[j]))', 'n,m=map(int,input().split())\nbranch=[tuple(map(int,input().split())) for _ in range(m)]\nres=[0]\ndata=[-1 for _ in range(1+n)]\ndef calc(k):\n k=abs(k)\n return 1/2*k*(k-1)\n\ndef search(data,x):\n if data[x]<=0:\n return x\n else:\n data[x]=search(data,data[x])\n return data[x]\n\nfor i in range(m):\n a,b=branch.pop()\n aroot=search(data,a)\n broot=search(data,b)\n if aroot==broot:\n res.append(res[-1])\n continue\n res.append(res[-1]-calc(data[aroot])-calc(data[broot])+calc(data[aroot]+data[broot]))\n if data[aroot]<=data[broot]:\n data[aroot]+=data[broot]\n data[broot]=aroot\n elif data[aroot]>data[broot]:\n data[broot]+=data[aroot]\n data[aroot]=broot\nfor j in range(m-1,-1,-1):\n print(int(res[m]-res[j])) '] | ['Runtime Error', 'Accepted'] | ['s518993646', 's570779786'] | [17352.0, 18576.0] | [301.0, 732.0] | [1076, 794] |
p03108 | u179169725 | 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\nread = sys.stdin.readline\n\n\ndef readln():\n return list(map(int, read().split()))\n\n\nN, M = readln()\nA = [0]*M\nB = [0]*M\nfor i in range(M-1, -1, -1):\n a, b = readln()\n A[i], B[i] = a, b\n# AB = [readln() for _ in range(M)]\n# A = [ab[0]-1 for ab in AB[::-1]]\n# B = [ab[1]-1 for ab in AB[::-1]]\n\n\nclass UnionFind:\n def __init__(self, N):\n self.N = N \n \n self.parent = [-1] * N \n\n def root(self, A):\n # print(A)\n \n if (self.parent[A] < 0):\n return A\n self.parent[A] = self.root(self.parent[A]) \n return self.parent[A]\n\n def size(self, A):\n \n return -self.parent[self.root(A)]\n\n def concat(self, A, B):\n \n \n A = self.root(A)\n B = self.root(B)\n\n \n if (A == B):\n return False\n\n \n if (self.size(A) < self.size(B)):\n A, B = B, A\n\n \n self.parent[A] += self.parent[B] \n self.parent[B] = A \n\n return True\n\n\nans = [N * (N - 1) // 2]\nuni = UnionFind(N)\nfor a, b in zip(A, B):\n if uni.root(a) == uni.root(b):\n ans.append(ans[-1])\n else:\n ans.append(ans[-1] - uni.size(a) * uni.size(b))\n uni.concat(a, b)\n\nfor a in ans[-2::-1]:\n print(a)\n', 'def readln():\n return list(map(int, input().split()))\n\n\nN, M = readln()\nAB = [readln() for _ in range(M)]\nA = [ab[0] for ab in AB[::-1]]\nB = [ab[1] for ab in AB[::-1]]\n\n\nclass UnionFind:\n def __init__(self, N):\n self.N = N \n \n self.parent = [-1] * N \n\n def root(self, A):\n \n if (self.parent[A] < 0):\n return A\n self.parent[A] = self.root(A) \n return self.parent[A]\n\n def size(self, A):\n \n return -self.parent[self.root(A)]\n\n def concat(self, A, B):\n \n \n A = self.root(A)\n B = self.root(B)\n\n \n if (A == B):\n return False\n\n \n if (self.size(A) < self.size(B)):\n A, B = B, A\n\n \n self.parent[A] += self.parent[B] \n self.parent[B] = A \n\n return True\n\n\nans = [N * (N - 1) // 2]\nuni = UnionFind(N)\nfor a, b in zip(A, B):\n if uni.root(a) == uni.root(b):\n ans.append(ans[-1])\n else:\n ans.append(ans[-1] - uni.size(a) * uni.size(b))\n\nfor a in ans[::-1]:\n print(a)\n', 'import sys\nread = sys.stdin.readline\n\n\ndef readln():\n return list(map(int, read().split()))\n\n\nN, M = readln()\nA = [0]*M\nB = [0]*M\nfor i in range(M-1, -1, -1):\n a, b = readln()\n A[i], B[i] = a-1, b-1\n# AB = [readln() for _ in range(M)]\n# A = [ab[0]-1 for ab in AB[::-1]]\n# B = [ab[1]-1 for ab in AB[::-1]]\n\n\nclass UnionFind:\n def __init__(self, N):\n self.N = N \n \n self.parent = [-1] * N \n\n def root(self, A):\n # print(A)\n \n if (self.parent[A] < 0):\n return A\n self.parent[A] = self.root(self.parent[A]) \n return self.parent[A]\n\n def size(self, A):\n \n return -self.parent[self.root(A)]\n\n def concat(self, A, B):\n \n \n A = self.root(A)\n B = self.root(B)\n\n \n if (A == B):\n return False\n\n \n if (self.size(A) < self.size(B)):\n A, B = B, A\n\n \n self.parent[A] += self.parent[B] \n self.parent[B] = A \n\n return True\n\n\nans = [N * (N - 1) // 2]\nuni = UnionFind(N)\nfor a, b in zip(A, B):\n if uni.root(a) == uni.root(b):\n ans.append(ans[-1])\n else:\n ans.append(ans[-1] - uni.size(a) * uni.size(b))\n uni.concat(a, b)\n\nfor a in ans[-2::-1]:\n print(a)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s328500576', 's917804085', 's242878744'] | [15692.0, 34280.0, 17772.0] | [545.0, 553.0, 673.0] | [2075, 1877, 2079] |
p03108 | u191829404 | 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. | ['# abcde\ts=input()\ts=\'abcde\'\n# abcde\ts=list(input())\ts=[\'a\', \'b\', \'c\', \'d\', \'e\']\n\n# 1 2\t| x,y = s_inpl() |\tx=1,y=2\n\n\n\n\n# INPUT\n# 3\n# hoge\n# foo\n# bar\n# ANSWER\n# n=int(input())\n\n\nimport math\nimport copy\nfrom collections import defaultdict\nfrom collections import Counter\nfrom collections import deque\n\nfrom itertools import product\n\nfrom itertools import permutations\n\nfrom itertools import combinations\nfrom bisect import bisect_left, bisect_right\n# import numpy as np\n\ndef inside(y, x, H, W):\n return 0 <= y < H and 0 <= x < W\n\n\ndy = [0, -1, 0, 1]\ndx = [1, 0, -1, 0]\n\ndef i_inpl(): return int(input())\ndef s_inpl(): return map(int,input().split())\ndef l_inpl(): return list(map(int, input().split()))\nINF = float("inf")\n\n############\n############\n############\n\nclass UnionFind:\n \n def __init__(self, N):\n \n self.parent = list(range(N))\n self.rank = [0] * N\n self.size = [1] * N\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 \n def count(self, x):\n return self.size[x]\n\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return \n\n if self.rank[x] < self.rank[y]:\n x, y = y, x\n\n self.size[x] += self.size[y]\n self.parent[x] = x\n\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n \n \n def same(self, x, y):\n return self.find(x) == self.find(y) \n\nn,m = map(int,input().split())\na = [list(map(int,input().split())) for i in range(m)]\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))\n', '# abcde\ts=input()\ts=\'abcde\'\n# abcde\ts=list(input())\ts=[\'a\', \'b\', \'c\', \'d\', \'e\']\n\n# 1 2\t| x,y = s_inpl() |\tx=1,y=2\n\n\n\n\n# INPUT\n# 3\n# hoge\n# foo\n# bar\n# ANSWER\n# n=int(input())\n\n\nimport math\nimport copy\nfrom collections import defaultdict\nfrom collections import Counter\nfrom collections import deque\n\nfrom itertools import product\n\nfrom itertools import permutations\n\nfrom itertools import combinations\nfrom bisect import bisect_left, bisect_right\n# import numpy as np\n\ndef inside(y, x, H, W):\n return 0 <= y < H and 0 <= x < W\n\n\ndy = [0, -1, 0, 1]\ndx = [1, 0, -1, 0]\n\ndef i_inpl(): return int(input())\ndef s_inpl(): return map(int,input().split())\ndef l_inpl(): return list(map(int, input().split()))\nINF = float("inf")\n\n############\n############\n############\n\nclass UnionFind:\n \n def __init__(self, N):\n \n self.parent = list(range(N))\n self.rank = [0] * N\n self.size = [1] * N\n\n \n def root_find(self, x):\n if self.parent[x] != x:\n self.parent[x] = self.root_find(self.parent[x])\n return self.parent[x]\n\n \n def count(self, x):\n return self.size[self.root_Pfind(x)]\n\n \n def unite(self, x, y):\n x_root = self.root_find(x)\n y_root = self.root_find(y)\n\n if x_root == y_root:\n return \n\n if self.rank[x_root] < self.rank[y_root]:\n x_root, y_root = y_root, x_root\n\n self.size[x_root] += self.size[y_root]\n self.parent[y_root] = x\n\n if self.rank[x_root] == self.rank[y_root]:\n self.rank[x_root] += 1\n \n \n def same(self, x, y):\n return self.root_find(x) == self.root_find(y) \n\n\nN, M = l_inpl()\nuf = UnionFind(N)\n\nqs = []\nfor _ in range(M):\n a, b = l_inpl()\n qs.append([a-1, b-1])\n\n\nans = [N*(N-1)//2]\nfor a, b in qs[::-1][:-1]:\n if not uf.same(a, b):\n ans.append(ans[-1] - uf.count(a) * uf.count(b))\n uf.unite(a, b)\n else:\n ans.append(ans[-1])\n\nprint("\\n".join([str(s) for s in ans[::-1]]))', '# abcde\ts=input()\ts=\'abcde\'\n# abcde\ts=list(input())\ts=[\'a\', \'b\', \'c\', \'d\', \'e\']\n\n# 1 2\t| x,y = s_inpl() |\tx=1,y=2\n\n\n\n\n# INPUT\n# 3\n# hoge\n# foo\n# bar\n# ANSWER\n# n=int(input())\n\n\nimport math\nimport copy\nfrom collections import defaultdict\nfrom collections import Counter\nfrom collections import deque\n\nfrom itertools import product\n\nfrom itertools import permutations\n\nfrom itertools import combinations\nfrom bisect import bisect_left, bisect_right\n# import numpy as np\n\ndef inside(y, x, H, W):\n return 0 <= y < H and 0 <= x < W\n\n\ndy = [0, -1, 0, 1]\ndx = [1, 0, -1, 0]\n\ndef i_inpl(): return int(input())\ndef s_inpl(): return map(int,input().split())\ndef l_inpl(): return list(map(int, input().split()))\nINF = float("inf")\n\n############\n############\n############\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\nn,m = map(int,input().split())\na = [list(map(int,input().split())) for i in range(m)]\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))\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s093353847', 's945159270', 's531141228'] | [38652.0, 27604.0, 38588.0] | [733.0, 421.0, 904.0] | [2691, 2749, 2485] |
p03108 | u198440493 | 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 root(s):\n t=l[s]\n if t<0:\n return s\n return root(t)\ndef f(s):\n return root(int(s)-1)\nn,m=map(int,input().split())\nans=n*(n-1)//2\nl=[-1]*n\na=[1]*n\nb=[input().split() for _ in range(m)]\nc=[0]*m+[ans]\nfor i in range(m-1,-1,-1):\n x,y=map(f,b[i+1])\n if x!=y:\n l[x]=y\n ans-=a[x]*a[y]\n a[y]+=a[x]\n c[i]=ans\nfor x in c[1:]:\n print(x)', 'n,m=map(int,input().split())\nans=n*(n-1)/2\nl=[-1]*n\na=[1]*n\nb=[input().split() for _ in range(m)]\nc=[0]*m+[ans]\ndef r(s):\n t=l[s]\n return s if t<0 else r(t)\ndef f(s):\n return r(int(s)-1)\nfor i in range(m-1,-1,-1):\n x,y=map(f,b[i])\n if x!=y:\n l[x]=y\n ans-=a[x]*a[y]\n a[y]+=a[x]\n c[i]=ans\nfor x in c[1:]:\n print(x)', 'import sys\nsys.setrecursionlimit(100000)\ninput=sys.stdin.readline\nn,m=map(int,input().split())\nl=[1]*n\nz=n*(n-1)//2\ninput()\nm-=1\nb=[input().split() for _ in range(m)]\nc=[0]*m+[z]\ndef r(s):\n t=l[s]\n if t>0:\n return s\n else:\n l[s]=r(t)\n return l[s]\ndef f(s):\n return r(int(s)-1)\nfor i in range(m-1,-1,-1):\n x,y=map(f,b[i])\n if x!=y:\n s,t=l[x],l[y]\n z-=s*t\n if s<t:\n l[x]=-y\n l[y]+=s\n else:\n l[y]=-x\n l[x]+=t\n c[i]=z\nfor x in c:\n print(x)', 'import sys\nsys.setrecursionlimit(100000)\ninput = sys.stdin.readline\nn,m=map(int,input().split())\nz=n*(n-1)//2\nl=[-1]*n\na=[1]*n\nb=[input().split() for _ in range(m)]\nc=[0]*m+[z]\ndef f(x):\n x=int(x)-1\n s=x+0\n while(1):\n t=l[s]\n if t<0:\n l[x]=s\n return s\n s=t\nfor i in range(m-1,-1,-1):\n x,y=map(f,b[i])\n if x!=y:\n l[x]=y\n z-=a[x]*a[y]\n a[y]+=a[x]\n c[i]=z\nfor x in c[1:]:\n print(x)', 'import sys\nsys.setrecursionlimit(100000)\ninput=sys.stdin.readline\nn,m=map(int,input().split())\nz=n*(n-1)//2\nl=[-1]*n\na=[1]*n\nb=[input().split() for _ in range(m)]\nc=[0]*m+[z]\ndef f(s):\n s=int(s)-1\n t=l[s]\n while(t>=0):\n t=l[t]\n l[s]=t\n return t\nfor i in range(m-1,-1,-1):\n x,y=map(f,b[i])\n if x!=y:\n l[x]=y\n z-=a[x]*a[y]\n a[y]+=a[x]\n c[i]=z\nfor x in c[1:]:\n print(x)', 'import sys\nsys.setrecursionlimit(100000)\ninput=sys.stdin.readline\nn,m=map(int,input().split())\nl=[-1]*n\nz=n*(n-1)//2\nb=tuple(input().split() for _ in range(m))\nc=[0]*m+[z]\ndef r(s):\n t=l[s]\n if t<0:\n return s\n else:\n l[s]=r(t)\n return l[s]\ndef f(s):\n return r(int(s)-1)\nfor i in range(m-1,0,-1):\n x,y=map(f,b[i])\n if x!=y:\n s,t=l[x],l[y]\n z-=s*t\n if s>t:\n l[x]=y\n l[y]+=s\n else:\n l[y]=x\n l[x]+=t\n c[i]=z\nfor x in c[1:]:\n print(x)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s463052976', 's468136388', 's500865683', 's881151900', 's938180411', 's587420347'] | [35352.0, 43348.0, 121432.0, 36580.0, 36580.0, 40272.0] | [218.0, 1712.0, 526.0, 2108.0, 323.0, 475.0] | [349, 328, 484, 413, 387, 478] |
p03108 | u210543511 | 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())\nils = [map(int, input().split()) for _ in range(M)]\n\npar = [i for i in range(N)]\nsize = [1] * N\n\ndef root(x):\n if par[x] == x:\n return x\n else:\n par[x] = root(par[x])\n \ndef unit(x, y):\n x = root(x)\n y = root(y)\n if x == y:\n return\n par[x] = y\n size[y] += size[x]\n size[x] = size[y]\n \n \ninconv = N * (N - 1) // 2\ninconvs = [inconv]\nfor A, B in ils[::-1]\n inconv -= size(root(A)) * size(root(B))\n unite(A, B)\n inconvs.insert(0, inconv)\n \nprint('\\n'.join(inconvs))\n \n ", 'N, M = map(int, input().split())\nils = [map(int, input().split()) for _ in range(M)]\n\npar = [-1 for i in range(N)]\n\ndef root(x):\n if par[x] < 0:\n return x\n else:\n par[x] = root(par[x])\n return par[x]\n \ndef unite(x, y):\n x = root(x)\n y = root(y)\n if x == y:\n return\n if size(x) < size(y):\n x, y = y, x\n par[x] += par[y]\n par[y] = x\n \ndef same(x, y):\n return root(x) == root(y)\n\ndef size(x):\n return - par[root(x)]\n \n \ninconv = N * (N - 1) // 2\nresult = [0] * M\nfor i in range(M - 1, -1, -1):\n A, B = ils[i]\n A -= 1\n B -= 1\n result[i] = inconv\n if not same(A, B):\n inconv -= size(A) * size(B)\n unite(A, B)\n \nfor i in result:\n print(i)'] | ['Runtime Error', 'Accepted'] | ['s823093402', 's902489456'] | [3064.0, 51684.0] | [18.0, 855.0] | [570, 748] |
p03108 | u211160392 | 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())\nbri = [[int(i) for i in input().split()]for i in range(M)]\n\ndef benri(x,con):\n \n if x in con :\n return con\n else:\n con.append(x)\n \n for i in bri:\n if x in i:\n con=(benri(i[i[0]==x],con))\n return con\n\nfor i in range(1,M+1):\n bri.pop(0)\n \n sima = []\n fuben = []\n for j in range(1,N+1):\n if not(j in sima):\n \n fubencount = 0\n AAA = benri(j,[])\n for k in AAA:\n sima.append(k)\n fuben.append(len(AAA))\n fubendo = 0\n \n f = (N*(N-1))/2\n for j in fuben:\n f -= (j*(j-1))/2\n print(f)\n', 'N,M = map(int,input().split())\nAB = list(list(map(int,input().split()))for i in range(M))\nAB.reverse()\nnode = [[i,[i]]for i in range(N)]\nans = [(N*(N-1))//2]\nfor a,b in AB:\n a,b = min(node[a-1][0],node[b-1][0]),max(node[a-1][0],node[b-1][0])\n if a != b:\n ans.append(ans[-1]-len(node[a][1])*len(node[b][1]))\n for i in node[b][1]:\n node[i][0] = a\n node[i][1] = [i]\n node[a][1].append(i)\n else:\n ans.append(ans[-1])\nans.reverse()\n\nfor i in ans[1:]:\n print(i)\n'] | ['Runtime Error', 'Accepted'] | ['s334916886', 's188430037'] | [22980.0, 52776.0] | [2105.0, 1265.0] | [775, 522] |
p03108 | u215329188 | 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 _ in range(M):\n a, b = list(map(int, input().split()))\n A.append(a)\n B.append(b)\n\nclass UnionFind:\n def __init__(self, n: int) -> None:\n \n self.nodes = [-1]*n\n \n def find_root(self, x: int) -> int:\n if self.nodes[x] < 0:\n return x\n else:\n self.nodes[x] = self.find_root(self.nodes[x])\n return self.nodes[x]\n \n def unite(self, x: int, y: int) -> None:\n x, y = self.find_root(x), self.find_root(y)\n \n if (x != y):\n if (x < y):\n self.nodes[y] += self.nodes[x]\n self.nodes[x] = y\n else:\n self.nodes[x] += self.nodes[y]\n self.nodes[y] = x\n def get_rank(self, x: int) -> int:\n return (self.nodes[x])\n\nu = UnionFind(N+1)\np = N * (N - 1) // 2\nans = [p]\nfor a, b in zip(A[:-1:-1],B[:-1:-1]):\n pa = u.find_root(a)\n pb = u.find_root(b)\n if pa != pb:\n p -= u.get_rank(pa) * u.get_rank(pb)\n u.unite(pa, pb)\n ans.append(p)\nprint(*ans[::-1], sep="\\n")\n', 'N, M = list(map(int, input().split()))\nA = []\nB = []\nfor _ in range(M):\n a, b = list(map(int, input().split()))\n A.append(a)\n B.append(b)\n\nclass UnionFind:\n def __init__(self, n: int) -> None:\n \n self.nodes = [-1]*n\n \n def find_root(self, x: int) -> int:\n if self.nodes[x] < 0:\n return x\n else:\n self.nodes[x] = self.find_root(self.nodes[x])\n return self.nodes[x]\n \n def unite(self, x: int, y: int) -> None:\n x, y = self.find_root(x), self.find_root(y)\n \n if (x != y):\n if (x < y):\n self.nodes[y] += self.nodes[x]\n self.nodes[x] = y\n else:\n self.nodes[x] += self.nodes[y]\n self.nodes[y] = x\n def get_rank(self, x: int) -> int:\n return (self.nodes[x])\n\nu = UnionFind(N+1)\np = N * (N - 1) // 2\nans = [p]\nfor a, b in zip(A[1:][::-1],B[1:][::-1]):\n pa = u.find_root(a)\n pb = u.find_root(b)\n if pa != pb:\n p -= u.get_rank(pa) * u.get_rank(pb)\n u.unite(pa, pb)\n ans.append(p)\nprint(*ans[::-1], sep="\\n")\n'] | ['Wrong Answer', 'Accepted'] | ['s436865876', 's726817292'] | [11876.0, 19112.0] | [345.0, 652.0] | [1237, 1241] |
p03108 | u223133214 | 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())\npar = [-1] * n \n\n\n\ndef find(x):\n if par[x] < 0:\n return x\n else:\n par[x] = find(par[x])\n return find(par[x])\n\n\n\ndef size(x):\n return -par[find(x)]\n\n\n\ndef unite(x, y):\n \n x, y = find(x), find(y)\n\n \n if x == y:\n return\n\n \n if size(x) < size(y):\n x, y = y, x\n\n \n par[x] += par[y]\n \n par[y] = x\n\n\n\ndef same(x, y):\n return find(x) == find(y)\n\n\nbridges = [list(map(int, input().split())) for _ in range(m)]\nbridges.reverse()\nhuben = n * (n - 1) // 2\nans = []\n\nfor i in range(m):\n ans.append(huben)\n a, b = bridges[i]\n a, b = a - 1, b - 1\n if same(a, b):\n continue\n else:\n huben -= size(a) * size(b)\n unite(a, b)\nans = ans.reverse()\nfor i in range(m):\n print(ans[i])\n', 'n, m = map(int, input().split())\npar = [-1] * n \n\n\n\ndef find(x):\n if par[x] < 0:\n return x\n else:\n par[x] = find(par[x])\n return find(par[x])\n\n\n\ndef size(x):\n return -par[find(x)]\n\n\n\ndef unite(x, y):\n \n x, y = find(x), find(y)\n\n \n if x == y:\n return\n\n \n if size(x) < size(y):\n x, y = y, x\n\n \n par[x] += par[y]\n \n par[y] = x\n\n\n\ndef same(x, y):\n return find(x) == find(y)\n\n\nbridges = [list(map(int, input().split())) for _ in range(m)]\nbridges.reverse()\nhuben = n * (n - 1) // 2\nans = []\nfor i in range(m):\n ans.append(huben)\n a, b = bridges[i]\n a, b = a - 1, b - 1\n if same(a, b):\n continue\n else:\n huben -= size(a) * size(b)\n unite(a, b)\nans.reverse()\nfor i in range(m):\n print(ans[i])\n'] | ['Runtime Error', 'Accepted'] | ['s038545963', 's855443615'] | [33436.0, 34652.0] | [716.0, 799.0] | [1139, 1132] |
p03108 | u226912938 | 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 UnionFindBySize():\n def __init__(self, n):\n self.parents = list(range(n+1))\n self.size = [1] * (n+1)\n\n def find(self, x):\n if self.parents[x] == x:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.size[x] < self.size[y]:\n self.size[y] += self.size[x]\n self.parents[x] = y\n else:\n self.size[x] += self.size[y]\n self.parents[y] = x\n\nn, m = map(int, input().split())\nAB = []\nfor _ in range(m):\n a, b = map(int, input().split())\n AB.append([a,b])\n\nans = 0\nfor i in range(1,n):\n ans += i\nprint(ans)\n\nUF = UnionFindBySize(n)\n\nfor i in range(m):\n ab = AB[-1-i]\n a = ab[0]\n b = ab[1]\n if UF.same_check(a,b) == True:\n pass\n else:\n a_size = UF.size[UF.find(a)]\n b_size = UF.size[UF.find(b)]\n ans -= a_size*b_size\n UF.union(a,b)\n if i == m-1:\n break\n print(ans)\n', 'class UnionFindBySize():\n def __init__(self, n):\n self.parents = list(range(n+1))\n self.size = [1] * (n+1)\n\n def find(self, x):\n if self.parents[x] == x:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.size[x] < self.size[y]:\n self.size[y] += self.size[x]\n self.parents[x] = y\n else:\n self.size[x] += self.size[y]\n self.parents[y] = x\n\nn, m = map(int, input().split())\nAB = []\nfor _ in range(m):\n a, b = map(int, input().split())\n AB.append([a,b])\n\nAns = []\nans = 0\nfor i in range(1,n):\n ans += i\nAns.append(ans)\n\nUF = UnionFindBySize(n)\nfor i in range(m):\n ab = AB[-1-i]\n a = ab[0]\n b = ab[1]\n if UF.same_check(a,b) == True:\n pass\n else:\n a_size = UF.size[UF.find(a)]\n b_size = UF.size[UF.find(b)]\n ans -= a_size*b_size\n UF.union(a,b)\n if i == m-1:\n break\n Ans.append(ans)\n\nfor i in range(m):\n print(Ans[-1-i])'] | ['Wrong Answer', 'Accepted'] | ['s592736061', 's574758956'] | [27368.0, 26376.0] | [839.0, 841.0] | [1246, 1304] |
p03108 | u228223940 | 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 j in range(m)]\n\nclass UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n+1)]\n self.rank = [0] * (n+1)\n self.size = [1 for _ in range(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 self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\nbridge = 0\n\nfor i in range(m):\n ins = UnionFind(n)\n for j in range(m):\n if j == i:\n continue\n if not ins.same_check(ab[j][0],ab[j][1]):\n ins.union(ab[j][0],ab[j][1])\n \n #print(ins.size[1],ins.size[ins.find(2)])\n if ins.size[ins.find(ab[0][0])] != n:\n bridge += 1\n \nprint(bridge)\n ', 'class UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n+1)]\n self.rank = [0] * (n+1)\n self.size = [1 for _ in range(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 self.size[y] += self.size[x]\n else:\n self.par[y] = x\n self.size[x] += self.size[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n \n \ndef main():\n N, M = [int(_) for _ in input().split()]\n bridge = [tuple(map(int, input().split())) for _ in range(M)]\n #print(bridge[M-1][0])\n #print(bridge)\n last = []\n last.append(int(N * (N-1) * 0.5))\n \n ins = UnionFind(N)\n last_temp = 0\n #print(last)\n ##print(ins.par)\n for i in range(M-1):\n #print(ins.par)\n if ins.same_check(bridge[M-1-i][0],bridge[M-1-i][1]):\n last.append(last[-1])\n #ins.union(bridge[M-1-i][0],bridge[M-1-i][1])\n else:\n last_temp = last[-1] - (ins.size[ins.find(bridge[M-1-i][0])]) * (ins.size[ins.find(bridge[M-1-i][1])])\n #print(ins.size,i)\n last.append(last_temp)\n ins.union(bridge[M-1-i][0],bridge[M-1-i][1])\n \n [print(last[M-i-1]) for i in range(M)]\n exit()\n \nmain()'] | ['Wrong Answer', 'Accepted'] | ['s244569932', 's465020388'] | [31032.0, 24932.0] | [2105.0, 813.0] | [1267, 1675] |
p03108 | u232320761 | 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=[int(x) for x in input().split()]\nI=[[] for n in range(N)]\nG=[n for n in range(N)]\nW=[1 for n in range(N)]\nE=[]\n\nresult=[]\nans = int(N * (N-1) / 2)\n\ndef union(i,g):\n if(G[i]!=g):\n G[i]=g\n for n in I[i]:\n union(n,g)\n\n#for A in range(M):\n# E.append((A,A+1))\n#from random import shuffle\n\nfor m in range(M):\n A,B=[int(x) for x in input().split()]\n E.append((A-1,B-1))\n\nfor m in range(M+1):\n result.append(ans)\n print(E)\n if(ans>0):\n A,B=E.pop()\n Ga,Gb=G[A],G[B]\n Wa,Wb=W[Ga],W[Gb]\n print("%i=%i-(%i*%i)" % (ans-(Wa*Wb),ans,Wa,Wb))\n ans=ans-(Wa*Wb)\n I[A].append(B)\n I[B].append(A)\n if (Wb>Wa):\n union(Ga,Gb)\n W[Gb]=Wa+Wb\n else:\n union(Gb,Ga)\n W[Ga]=Wa+Wb\n print(I)\n print(G)\n print(W)\n print("----")\n\nfor r in reversed(result):\n print(r)\n#print(result[M-1])\n', 'N,M=[int(x) for x in input().split()]\nI=[[] for i in range(N)]\nE=[]\nV=[0 for i in range(N)]\n\ndef visit(n):\n total=0\n if (V[n]==0):\n V[n]=1\n total=1\n for i in I[n]:\n total+=visit(i)\n return total\n\nfor i in range(M):\n A,B=[int(x) for x in input().split()]\n A,B=A-1,B-1\n I[A].append(B)\n E.append((A,B))\n\nwhile len(E)>0:\n A,B=E.pop(0)\n I[A].pop(I[A].index(B))\n V=[0 for i in range(N)]\n\n Z=N\n i=0\n for n in range(N):\n if(V[n]==0):\n total=visit(n)\n Z=Z-total\n i=i+(total*Z)\n print(i)\n\n', 'N,M=[int(x) for x in input().split()]\nG=[-1] * N\nW=[0] * N\nE=[]\n\nresult=[]\nans = int(N * (N-1) / 2)\n\ndef union(i,j):\n gi=find(i)\n gj=find(j)\n\n if(gi!=gj):\n if W[gi] > W[gj]:\n G[gi]+=G[gj]\n G[gj]=gi\n else:\n G[gj]+=G[gi]\n G[gi]=gj\n if W[gi]==W[gj]:\n W[gj]+=1\n\ndef find(i):\n if G[i]<0:\n return i;\n else:\n G[i]=find(G[i])\n return G[i]\n\nfor m in range(M):\n A,B=[int(x) for x in input().split()]\n E.append((A-1,B-1))\n\nfor m in range(M):\n result.append(ans)\n if(ans>0):\n A,B=E.pop()\n ga,gb=find(A),find(B)\n if (ga!=gb):\n ans=ans-(G[ga]*G[gb])\n union(A,B)\n\nfor r in reversed(result):\n print(r)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s664086167', 's738764518', 's728689668'] | [115920.0, 30300.0, 19320.0] | [2106.0, 2105.0, 636.0] | [940, 593, 764] |
p03108 | u240354680 | 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 func(n):\n return (n * (n - 1)) // 2\n\n\nnode_size, input_size = [int(i) for i in input().split()]\n\nbr = [func(node_size)]\nfor _ in range(input_size):\n br.append([int(i) for i in input().split()])\n\ncnt_list = [func(node_size)]\n\nindex = 0\nnode_to_group = {}\ngroup_to_index = {}\nindex_size = {}\n\nfor j in range(1, input_size + 1):\n flag1, flag2 = br[-j][0] in node_to_group, br[-j][1] in node_to_group\n\n if flag1 and flag2:\n if group_to_index[node_to_group[br[-j][0]]] == group_to_index[node_to_group[br[-j][1]]]:\n tmp = cnt_list[0]\n else:\n tmp = cnt_list[0] + func(index_size[group_to_index[node_to_group[br[-j][0]]]]) + \\\n func(index_size[group_to_index[node_to_group[br[-j][1]]]]) - \\\n func(index_size[group_to_index[node_to_group[br[-j][0]]]] +\n index_size[group_to_index[node_to_group[br[-j][1]]]])\n index_size[group_to_index[node_to_group[br[-j][0]]]] += index_size[group_to_index[node_to_group[br[-j][1]]]]\n del index_size[group_to_index[node_to_group[br[-j][1]]]]\n group_to_index[node_to_group[br[-j][1]]] = group_to_index[node_to_group[br[-j][0]]]\n\n elif flag1:\n tmp = cnt_list[0] - index_size[group_to_index[node_to_group[br[-j][0]]]]\n node_to_group[br[-j][1]] = node_to_group[br[-j][0]]\n index_size[group_to_index[node_to_group[br[-j][0]]]] += 1\n elif flag2:\n tmp = cnt_list[0] - index_size[group_to_index[node_to_group[br[-j][1]]]]\n node_to_group[br[-j][0]] = node_to_group[br[-j][1]]\n index_size[group_to_index[node_to_group[br[-j][1]]]] += 1\n else:\n tmp = cnt_list[0] - 1\n node_to_group[br[-j][0]] = br[-j][0]\n node_to_group[br[-j][1]] = br[-j][0]\n group_to_index[br[-j][0]] = index\n index_size[index] = 2\n index += 1\n print(index_size)\n if tmp == 0:\n for _ in range(input_size - j):\n print(0)\n break\n cnt_list.insert(0, tmp)\n\nfor i in cnt_list:\n print(i)', 'def search_root(l, n):\n i = n\n while l[i] != i:\n i = l[i]\n return i\n\n\ndef set_root(l, root_index, start_index):\n i = start_index\n while l[i] != root_index:\n tmp = i\n i = l[i]\n l[tmp] = root_index\n\n\ndef func(n):\n return (n * (n - 1)) // 2\n\n\nnode_size, input_size = [int(i) for i in input().split()]\n\nbr = []\nfor _ in range(input_size):\n br.append([int(i) for i in input().split()])\n\ncnt_list = [0]\nsize_list = [1 for _ in range(node_size + 1)]\nnode_list = [i for i in range(node_size + 1)]\n\nfor i in range(1, input_size + 1):\n node1, node2 = br[-i]\n\n root1, root2 = search_root(node_list, node1), search_root(node_list, node2)\n\n if root1 == root2:\n cnt_list.append(cnt_list[-1])\n else:\n cnt_list.append(cnt_list[-1] + (size_list[root1] * size_list[root2]))\n if size_list[root1] < size_list[root2]:\n node_list[root1] = root2\n size_list[root2] += size_list[root1]\n else:\n node_list[root2] = root1\n size_list[root1] += size_list[root2]\n\nval = func(node_size)\nfor i in cnt_list[::-1][1:]:\n print(val - i)'] | ['Runtime Error', 'Accepted'] | ['s244488060', 's545449709'] | [119440.0, 30892.0] | [2105.0, 586.0] | [2035, 1135] |
p03108 | u242196904 | 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. | ["from itertools import combinations\nfrom itertools import combinations\nfrom collections import Counter\nimport numpy as np\n\n\nn,m = list(map(int, input().split()))\na = []\nb = []\nfor _ in range(m):\n aa, bb = list(map(int, input().split()))\n a.append(aa)\n b.append(bb)\na = a[::-1]\nb = b[::-1]\n\n\ndef findRoot(key, hists = []):\n temp = dic[key]\n if temp == key:\n return key\n else:\n key = findRoot(temp)\n return findRoot(temp)\n\n# %%time\nanss = [int(n*(n-1)/2)]\ndic = {}\nfor k in range(1, n+1):\n dic[k] = k\nturn = 0\n\n\nimport time\nt = time.time()\nfor turn in range(m):\n# print('----')\n# print(time.time() - t)\n if dic[b[turn]] == a[turn]:\n pass\n else:\n dic[a[turn]] = b[turn]\n \n roots = []\n for key in dic.keys():\n root = findRoot(key)\n# print(key)\n dic[key] = root\n roots.append(root)\n\n# print(time.time() - t)\n c = Counter(roots)\n\n# print(time.time() - t)\n\n# for comb in combinations(list(c.values()), 2):\n\n x = list(c.values())\n xs = np.sum(x)\n s = 0\n for xx in x:\n s += (xs - xx) * xx\n s = int(s/2)\n \n anss.append(s)\nfor s in anss[::-1]:\n print(s)", "%%time\ndef saiki(now, reachable):\n# print(now)\n cand = copy.deepcopy(dic[now])\n cue = []\n cand = dic[now]\n while len(cand) > 0:\n c = cand[0]\n cand.pop(0)\n \n# print(cand)\n if c in reachable:\n pass\n else:\n reachable += [c]\n cand += saiki(c, reachable)\n \n return reachable\n\ndef saiki_check(now, reachable, reachable_check_target):\n# print(now)\n cue = []\n cand = copy.deepcopy(dic[now])\n ans = False\n while len(cand) > 0:\n c = cand[0]\n cand.pop(0)\n \n# print(cand)\n if c in reachable:\n pass\n else:\n reachable += [c]\n if c == reachable_check_target:\n ans = True\n break\n out = saiki_check(c, reachable, reachable_check_target)\n cand = cand + out[0]\n ans = out[1]\n if ans:\n break\n return reachable, ans\nimport copy\nanss = [0]\nfor k_start in range(1, m + 1):\n dic = {}\n for k in range(1, n+1):\n dic[k] = []\n for k in range(k_start, m):\n dic[a[k]] += [b[k]]\n dic[b[k]] += [a[k]]\n cutted = [a[k_start-1], b[k_start-1]]\n \n# print(dic)\n if saiki_check(cutted[0], [cutted[0]], cutted[1])[1]:\n# print(dic)\n# reachable = []\n s = anss[-1]\n# print('a')\n else:\n nodes = list(range(1,n+1))\n rs = []\n while len(nodes) > 0:\n reachable = saiki(nodes[0], [nodes[0]])\n# print(reachable)\n for r in reachable:\n nodes.remove(r)\n rs.append(len(reachable))\n # print(rs)\n s = 0\n for c in combinations(rs, 2):\n s += c[0] * c[1]\n anss.append(s)\n\n print(s)\n", 'class UnionFind():\n def __init__(self, size):\n self.pre = [i for i in range(size)]\n self.size = [1 for i in range(size)]\n def find(self, x):\n# print(x)\n if x == self.pre[x]:\n return x\n else:\n self.pre[x] = self.find(self.pre[x])\n return self.pre[x]\n def check(self, x, y):\n return self.find(x) == self.find(y)\n \n def union(self, x, y):\n if self.check(x,y):\n pass\n else:\n s1 = self.size[x]\n s2 = self.size[y]\n if s1 == s2:\n self.size[self.find(x)] += s2\n self.pre[y] = x\n else:\n if s1 > s2:\n self.size[self.find(x)] +=s2\n self.pre[y] = x\n else:\n self.size[self.find(y)] += s1\n self.pre[x] = y\n\nn,m = list(map(int, input().split()))\na = []\nb = []\nfor _ in range(m):\n aa, bb = list(map(int, input().split()))\n a.append(aa)\n b.append(bb)\n\na = a[::-1]\nb = b[::-1]\n\na = [aa - 1 for aa in a]\nb = [bb - 1 for bb in b]\n\nk = 0\nans = int(n * (n-1) / 2)\nans_rec = [ans]\nuf = UnionFind(n)\n\nfor k in range(m):\n if uf.check(a[k], b[k]):\n pass\n else:\n ans -= uf.size[uf.find(a[k])] * uf.size[uf.find(b[k])]\n uf.union(a[k], b[k])\n ans_rec.append(ans)\n# print(ans)\n\nfor ans in ans_rec[::-1]:\n print(ans)', 'import sys\nsys.setrecursionlimit(100000)\n\nn,m = list(map(int, input().split()))\na = []\nb = []\nfor _ in range(m):\n aa, bb = list(map(int, input().split()))\n a.append(aa-1)\n b.append(bb-1)\n\na = a[::-1]\nb = b[::-1]\n\nans = int(n * (n - 1) /2)\nans_rec = [0] * m\nans_rec[-1] = ans\n\np = [-1 for i in range(n)]\nsize = [1 for i in range(n)]\n\ndef find(x):\n# print(x, p[x])\n px = p[x]\n if px <0:\n return x\n else:\n pxx = find(px)\n p[x] = pxx\n return pxx\n\nfor k in range(m-1):\n pa = find(a[k])\n pb = find(b[k])\n if pa == pb:\n pass\n else:\n ans -= size[pa] * size[pb]\n size[pa] += size[pb]\n p[pb] = pa\n ans_rec[- k - 2] = ans\nfor aa in ans_rec:\n print(aa)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s516448513', 's536562445', 's561724427', 's936671465'] | [51524.0, 2940.0, 20952.0, 32464.0] | [2110.0, 17.0, 828.0, 584.0] | [1242, 1827, 1467, 736] |
p03108 | u244070045 | 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 \n def size(self,x):\n return -self.parents[self.find(x)]\n\n def connect(self, a, b):\n a = self.find(a)\n b = self.find(b)\n if a == b:\n return False\n \n \n \n if self.parents[a] > self.parents[b]:\n a,b = b,a\n\n self.parents[a] += self.parents[b]\n self.parents[b] = a\n return True\n\nn, m = map(int,input().split())\n\nA = [0] * m\nB = [0] * m\nans = [0]*m\nans[m-1] = n * (n-1) / 2\n\n\nfor i in range(m):\n A[i],B[i] = map(int,input().split())\n A[i] -= 1\n B[i] -= 1\n\n\nUni = UnionFind(n)\n\n\nfor i in range(m-1, 0, -1):\n ans[i-1] = ans[i]\n if Uni.find(A[i]) != Uni.find(B[i]):\n ans[i - 1] -= Uni.size(A[i]) * Uni.size(B[i])\n Uni.connect(A[i], B[i])\n\nfor i in range(m):\n print(ans[i])\n\n\n', 'class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n \n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n \n def size(self,x):\n return -self.parents[self.find(x)]\n\n def connect(self, a, b):\n a = self.find(a)\n b = self.find(b)\n if a == b:\n return False\n \n \n \n if self.parents[a] > self.parents[b]:\n a,b = b,a\n\n self.parents[a] += self.parents[b]\n self.parents[b] = a\n return True\n\nn, m = map(int,input().split())\n\nA = [0] * m\nB = [0] * m\nans = [0]*m\nans[m-1] = n * (n-1) / 2\n\n\nfor i in range(m):\n A[i],B[i] = map(int,input().split())\n A[i] -= 1\n B[i] -= 1\n\n\nUni = UnionFind(n)\n\n\nfor i in range(m-1, 0, -1):\n ans[i-1] = ans[i]\n if Uni.find(A[i]) != Uni.find(B[i]):\n ans[i - 1] -= Uni.size(A[i]) * Uni.size(B[i])\n Uni.connect(A[i], B[i])\n\nfor i in range(m):\n print(int(ans[i]))\n'] | ['Wrong Answer', 'Accepted'] | ['s161069112', 's792170532'] | [16388.0, 16252.0] | [823.0, 821.0] | [1266, 1269] |
p03108 | u270681687 | 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.rank = [0] * n\n self.parent = [i for i in range(n)]\n self.num = [1] * n\n\n\n def find(self, x):\n if self.parent[x] == x:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[x]\n\n\n def merge(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.rank[x] < self.rank[y]:\n self.parent[x] = y\n self.num[y] += self.num[x]\n elif self.rank[x] > self.rank[y]:\n self.parent[y] = x\n self.num[x] += self.num[y]\n else:\n self.parent[x] = y\n self.rank[y] += 1\n self.num[y] += self.num[x]\n\n\nn, m = map(int, input().split())\nbridge = [list(map(int, input().split())) for _ in range(m)]\n\nbridge = bridge[::-1]\n\nnc2 = n*(n-1)//2\n\nans = []\n\nuf = UnionFind(n)\n\nres = 0\nfor i, (a, b) in enumerate(bridge):\n a -= 1\n b -= 1\n ans.append(nc2 - res)\n if uf.num[uf.find(a)] == 1 and uf.num[uf.find(b)] == 1:\n res += 1\n else:\n if uf.num[uf.find(a)] == 1:\n res += uf.num[uf.find(b)] * (uf.num[uf.find(b)] + 1) // 2 - uf.num[uf.find(b)] * (uf.num[uf.find(b)] - 1) // 2\n elif uf.num[uf.find(b)] == 1:\n res += uf.num[uf.find(a)] * (uf.num[uf.find(a)] + 1) // 2 - uf.num[uf.find(a)] * (uf.num[uf.find(a)] - 1) // 2\n else:\n na = uf.num[uf.find(a)]\n nb = uf.num[uf.find(b)]\n res += (na + nb) * (na + nb - 1) // 2 - (na * (na - 1) // 2) - (nb * (nb - 1) // 2)\n uf.merge(a, b)\n\nans = ans[::-1]\nfor i in ans:\n print(i)\n', 'class UnionFind:\n def __init__(self, n):\n self.rank = [0] * n\n self.parent = [i for i in range(n)]\n self.num = [1] * n\n\n\n def find(self, x):\n if self.parent[x] == x:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[x]\n\n\n def merge(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n if self.rank[x] < self.rank[y]:\n self.parent[x] = y\n self.num[y] += self.num[x]\n elif self.rank[x] > self.rank[y]:\n self.parent[y] = x\n self.num[x] += self.num[y]\n else:\n self.parent[x] = y\n self.rank[y] += 1\n self.num[y] += self.num[x]\n\n\nn, m = map(int, input().split())\nbridge = [list(map(int, input().split())) for _ in range(m)]\n\nbridge = bridge[::-1]\n\nnc2 = n*(n-1)//2\n\nans = []\n\nuf = UnionFind(n)\n\nres = 0\nfor i, (a, b) in enumerate(bridge):\n a -= 1\n b -= 1\n ans.append(nc2 - res)\n if uf.find(a) == uf.find(b):\n pass\n elif uf.num[uf.find(a)] == 1 and uf.num[uf.find(b)] == 1:\n res += 1\n else:\n if uf.num[uf.find(a)] == 1:\n res += uf.num[uf.find(b)] * (uf.num[uf.find(b)] + 1) // 2 - uf.num[uf.find(b)] * (uf.num[uf.find(b)] - 1) // 2\n elif uf.num[uf.find(b)] == 1:\n res += uf.num[uf.find(a)] * (uf.num[uf.find(a)] + 1) // 2 - uf.num[uf.find(a)] * (uf.num[uf.find(a)] - 1) // 2\n else:\n na = uf.num[uf.find(a)]\n nb = uf.num[uf.find(b)]\n res += (na + nb) * (na + nb - 1) // 2 - (na * (na - 1) // 2) - (nb * (nb - 1) // 2)\n uf.merge(a, b)\n\nans = ans[::-1]\nfor i in ans:\n print(i)\n'] | ['Wrong Answer', 'Accepted'] | ['s652095401', 's752028713'] | [39324.0, 39324.0] | [1035.0, 1184.0] | [1688, 1736] |
p03108 | u271469978 | 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\nn , m, *e = map(int,sys.stdin.read().split())\ntotal = n*(n-1)//2\nans =[total]\nu = [-1]*(n+1)\n\ndef find(x):\n if u[x] < 0 :\n return x\n else:\n return find(u[x])\n\nfor x , y in zip(e[-2:1:-2],e[:1:-2]):\n x = find(x)\n y = find(y)\n if x != y:\n total -= u[x] * u[y]\n u[x] += u[y]\n u[y] = x\u3000\u3000\n ans += [total]\n print(u)\n\nprint(*ans[::-1], sep="\\n")', 'import sys\nn , m, *e = map(int,sys.stdin.read().split())\ntotal = n*(n-1)//2\nans =[total]\nu = [-1]*(n+1)\n\ndef find(x):\n if u[x] < 0 :\n return x\n else:\n return find(u[x])\n\nfor x , y in zip(e[-2:1:-2],e[:1:-2]):\n x = find(x)\n y = find(y)\n x, y =sorted((x,y))\n if x != y:\n total -= u[x] * u[y]\n u[x] += u[y]\n u[y] = x\n ans += [total]\n\nprint(*ans[::-1], sep="\\n")'] | ['Runtime Error', 'Accepted'] | ['s922653686', 's402491407'] | [3064.0, 25332.0] | [17.0, 463.0] | [409, 414] |
p03108 | u272963916 | 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. | ['# -*- coding: utf-8 -*-\n\n\nclass UnionFindbySize:\n def __init__(self, n):\n self.parent = [-1 for i in range(n)]\n\n def root(self, x):\n if self.parent[x] < 0:\n return x\n else:\n return self.parent[x] = self.root(self.parent[x])\n\n def issame(self, x, y):\n return self.root(x) == self.root(y)\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n else:\n self.parent[y] += self.parent[x] \n self.parent[x] = y\n return True\n\n def size(self, x):\n return -self.parent[self.root(x)]\n\nN, 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 A[i] -= 1\n B[i] -= 1\n\nuf = UnionFindbySize(N)\nres = [0] * (M)\nres[-1] = N*(N-1)//2\n\ni = 1\nfor a, b in zip(A[::-1], B[::-1]):\n id = M - 1 - i\n if id < 0:\n break\n if uf.issame(a, b):\n res[id] = res[id+1]\n else:\n sa = uf.size(a)\n sb = uf.size(b)\n res[id] = res[id+1] - sa*sb\n uf.unite(a, b)\n i+=1\n\nfor r in res:\n print(r)\n', '# -*- coding: utf-8 -*-\n\n\nclass UnionFindbySize:\n def __init__(self, n):\n self.parent = [-1 for i in range(n)]\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 issame(self, x, y):\n return self.root(x) == self.root(y)\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n else:\n self.parent[y] += self.parent[x] \n self.parent[x] = y\n return True\n\n def size(self, x):\n return -self.parent[self.root(x)]\n\nN, 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 A[i] -= 1\n B[i] -= 1\n\nuf = UnionFindbySize(N)\nres = [0] * (M)\nres[-1] = N*(N-1)//2\n\ni = 1\nfor a, b in zip(A[1::-1], B[1::-1]):\n if uf.issame(a, b):\n res[-1-i] = res[-i]\n else:\n sa = uf.size(a)\n sb = uf.size(b)\n res[-1-i] = res[-i] - sa*sb\n uf.unite(a, b)\n i+=1\n\nfor r in res[1:]:\n print(r)\n', '# -*- coding: utf-8 -*-\n\n\nclass UnionFindbySize:\n def __init__(self, n):\n self.parent = [-1 for i in range(n)]\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 issame(self, x, y):\n return self.root(x) == self.root(y)\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n else:\n self.parent[y] += self.parent[x] \n self.parent[x] = y\n return True\n\n def size(self, x):\n return -self.parent[self.root(x)]\n\nN, 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 A[i] -= 1\n B[i] -= 1\n\nuf = UnionFindbySize(N)\nres = [0] * (M)\nres[-1] = N*(N-1)//2\n\ni = 1\nfor a, b in zip(A[:-1:-1], B[:-1:-1]):\n if uf.issame(a, b):\n res[-1-i] = res[-i]\n else:\n sa = uf.size(a)\n sb = uf.size(b)\n res[-1-i] = res[-i] - sa*sb\n uf.unite(a, b)\n i+=1\n\nfor r in res[1:]:\n print(r)\n', '# -*- coding: utf-8 -*-\n\nimport sys\nsys.setrecursionlimit(10**6) \n\nclass UnionFindbySize:\n def __init__(self, n):\n self.parent = [-1 for i in range(n)]\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 issame(self, x, y):\n return self.root(x) == self.root(y)\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return False\n else:\n self.parent[y] += self.parent[x] \n self.parent[x] = y\n return True\n\n def size(self, x):\n return -self.parent[self.root(x)]\n\nN, 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 A[i] -= 1\n B[i] -= 1\n\nuf = UnionFindbySize(N)\nres = [0] * (M)\nres[-1] = N*(N-1)//2\n\ni = 1\nfor a, b in zip(A[::-1], B[::-1]):\n id = M - 1 - i\n if id < 0:\n break\n if uf.issame(a, b):\n res[id] = res[id+1]\n else:\n sa = uf.size(a)\n sb = uf.size(b)\n res[id] = res[id+1] - sa*sb\n uf.unite(a, b)\n i+=1\n\nfor r in res:\n print(r)\n'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s185077719', 's532115149', 's861111856', 's719156266'] | [2940.0, 14152.0, 14196.0, 31164.0] | [17.0, 428.0, 391.0, 846.0] | [1249, 1234, 1236, 1317] |
p03108 | u286955577 | 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. | ["from collections import defaultdict\n\nclass UnionFind():\n def __init__(self):\n self.__table = {}\n self.__size = defaultdict(lambda: 1)\n\n def __root(self, x):\n if x not in self.__table:\n self.__table[x] = x\n elif x != self.__table[x]:\n self.__table[x] = self.__root(self.__table[x])\n return self.__table[x]\n\n def same(self, x, y):\n return self.__root(x) == self.__root(y)\n\n def union(self, x, y):\n x = self.__root(x)\n y = self.__root(y)\n if x != y:\n self.__size[x] += self.__size[y]\n self.__size[y] = self.__size[x]\n self.__table[x] = y\n\n def size(self, x):\n return self.__size[self.__root(x)]\n\ndef solve():\n uf = UnionFind()\n N, M = map(int, input().split())\n bridges = [[int(i) for i in input().split()] for i in range(M)]\n ans = [N * (N - 1) // 2]\n for A, B in reversed(bridges):\n if uf.same(A, B):\n ans.append(ans[-1])\n else:\n try:\n sa, sb = uf.size(A), uf.size(B)\n uf.union(A, B)\n except:\n sa, sb = 1, 0\n ans.append(ans[-1] - uf.size(A) * uf.size(B))\n ans.pop()\n return '\\n'.join(map(str, reversed(ans)))\n\nprint(solve())\n", "import collections\n\nN, M = map(int, input().split())\nbridges = reversed([[int(i) for i in input().split()] for i in range(M)])\n\nclass UnionFind(object):\n def __init__(self, n=1):\n self.par = [i for i in range(n)]\n self.rank = [0 for _ in range(n)]\n\n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\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 _y = self.par[y]\n for i in range(N):\n if self.par[i] == _y: self.par[i] = x\n\n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n\ndef solve():\n uf = UnionFind(N)\n ans = [str(N * (N - 1) // 2)]\n for bridge in bridges:\n uf.union(bridge[0] - 1, bridge[1] - 1)\n C = collections.Counter(uf.par)\n n = N\n a = 0\n for c in C.values():\n n -= c\n a += n * c\n ans.append(str(a))\n return '\\n'.join(reversed(ans))\n\nprint(solve())\n", "import collections\n\nN, M = map(int, input().split())\nbridges = reversed([[int(i) for i in input().split()] for i in range(M)])\n\nclass UnionFind(object):\n def __init__(self, n=1):\n self.par = [i for i in range(n)]\n self.rank = [0 for _ in range(n)]\n\n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\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 _y = self.par[y]\n for i in range(N):\n if self.par[i] == _y: self.par[i] = x\n\n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n\ndef solve():\n uf = UnionFind(N)\n ans = [str(N * (N - 1) // 2)]\n for bridge in bridges:\n uf.union(bridge[0] - 1, bridge[1] - 1)\n C = collections.Counter(uf.par)\n n = N\n a = 0\n for c in C.values():\n n -= c\n a += n * c\n ans.append(str(a))\n return '\\n'.join(reversed(ans))\n\nprint(solve())\n", "import collections\n\nN, M = map(int, input().split())\nbridges = reversed([[int(i) for i in input().split()] for i in range(M)])\n\nclass UnionFind(object):\n def __init__(self, n=1):\n self.par = [i for i in range(n)]\n self.rank = [0 for _ in range(n)]\n\n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\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 _y = self.par[y]\n for i in range(N):\n if self.par[i] == _y: self.par[i] = x\n\n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n\ndef solve():\n uf = UnionFind(N)\n ans = [str(N * (N - 1) // 2)]\n for bridge in bridges:\n uf.union(bridge[0] - 1, bridge[1] - 1)\n C = collections.Counter(uf.par)\n n = N\n a = 0\n for c in C.values():\n n -= c\n a += n * c\n ans.append(str(a))\n return '\\n'.join(reversed(ans))\n\nprint(solve())\n", "import collections\n\nN, M = map(int, input().split())\nbridges = reversed([[int(i) for i in input().split()] for i in range(M)])\n\nclass UnionFind(object):\n def __init__(self, n=1):\n self.par = [i for i in range(n)]\n self.rank = [0 for _ in range(n)]\n\n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\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 _y = self.par[y]\n for i in range(N):\n if self.par[i] == _y: self.par[i] = x\n\n def is_same(self, x, y):\n return self.find(x) == self.find(y)\n\ndef solve():\n uf = UnionFind(N)\n ans = [str(N * (N - 1) // 2)]\n for bridge in bridges:\n uf.union(bridge[0] - 1, bridge[1] - 1)\n C = collections.Counter(uf.par)\n n = N\n a = 0\n for c in C.values():\n n -= c\n a += n * c\n ans.append(str(a))\n return '\\n'.join(reversed(ans))\n\nprint(solve())\n", "class UnionFind:\n def __init__(self, size):\n \n self.parent = [-1 for i in range(size)]\n\n def root(self, x): \n if self.parent[x] < 0: return x\n else:\n self.parent[x] = self.root(self.parent[x]) \n return self.parent[x]\n\n def union(self, x, y): \n x = self.root(x)\n y = self.root(y)\n if x == y: return False\n if self.size(x) < self.size(y): x, y = y, x\n self.parent[x] += self.parent[y] \n self.parent[y] = x \n return True\n\n def same(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\ndef solve():\n N, M = map(int, input().split())\n bridges = [[int(i) - 1 for i in input().split()] for i in range(M)]\n ans = [N * (N - 1) // 2]\n\n uf = UnionFind(N)\n for bridge in reversed(bridges):\n A, B = bridge\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 uf.union(A, B)\n ans.pop(-1)\n return '\\n'.join(map(str, reversed(ans)))\n\nprint(solve())\n"] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s223953383', 's256263232', 's493490625', 's795105740', 's870514227', 's828540495'] | [50900.0, 48872.0, 48868.0, 48868.0, 48932.0, 34272.0] | [1115.0, 2106.0, 2109.0, 2106.0, 2110.0, 727.0] | [1288, 1185, 1185, 1185, 1185, 1458] |
p03108 | u305965165 | 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. | ['\nclass UnionFind():\n def __init__(self, N):\n self.par = [i for i in range(N)]\n self.N = N\n\n \n def root(self, x):\n return x if self.par[x] == x else self.root(self.par[x])\n\n \n def same(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n return rx == ry\n\n \n def unite(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n if(rx != ry):\n self.par = [ry if i == rx else i for i in self.par]\n\ndef output(uf):\n count = 0\n for i in range(uf.N):\n sub_par = uf.par[i+1:]\n count += len(sub_par) - sub_par.count(uf.par[i])\n\n return count\n\n\n\nn, m = (int(i) for i in input().split())\ninput_arr = [[int(i) for i in input().split()] for i in range(m)] \n\nuf = UnionFind(n)\n#input_arr = [[1,2],[3,4],[1,3],[2,3],[1,4]]\n\n\nresult = [output(uf)]\nfor i in input_arr[::-1]:\n a = i[0]-1\n b = i[1]-1\n if not uf.same(a,b):\n uf.unite(a,b)\n result.append(output(uf))\n result.append(result[-1])\n\nfor i in result[::-1][1:]:\n print(i)\n\n\n', '\nclass UnionFind():\n def __init__(self, N):\n self.par = [i for i in range(N)]\n self.size = [1] * N\n self.N = N\n\n \n def root(self, x):\n if self.par[x] == x:\n return x\n else: \n self.par[x] = self.root(self.par[x])\n return self.root(self.par[x])\n\n \n def same(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n return rx == ry\n\n \n def unite(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n if self.size[rx] < self.size[ry]:\n self.par[rx] = ry\n self.size[ry] += self.size[rx]\n else:\n self.par[ry] = rx\n self.size[rx] += self.size[ry]\n\n\nn, m = (int(i) for i in input().split())\ninput_arr = [[int(i) for i in input().split()] for i in range(m)] \n\nuf = UnionFind(n)\n#input_arr = [[1,2],[3,4],[1,3],[2,3],[1,4]]\n\n\nresult = [output(uf)]\nfor i in input_arr[::-1]:\n a = i[0]-1\n b = i[1]-1\n if not uf.same(a,b):\n x = uf.size[uf.root(a)] * uf.size[uf.root(b)]\n uf.unite(a,b)\n result.append(result[-1]-x)\n else:\n result.append(result[-1])\n\nfor i in result[::-1][1:]:\n print(i)\n\n\n', '\nclass UnionFind():\n def __init__(self, N):\n self.par = [i for i in range(N)]\n self.size = [1] * N\n self.N = N\n\n \n def root(self, x):\n if self.par[x] == x:\n return x\n else: \n self.par[x] = self.root(self.par[x])\n return self.root(self.par[x])\n\n \n def same(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n return rx == ry\n\n \n def unite(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n if self.size[rx] < self.size[ry]:\n self.par[rx] = ry\n self.size[ry] += self.size[rx]\n else:\n self.par[ry] = rx\n self.size[rx] += self.size[ry]\n\nn, m = (int(i) for i in input().split())\ninput_arr = [[int(i) for i in input().split()] for i in range(m)] \n\nuf = UnionFind(n)\n#input_arr = [[1,2],[3,4],[1,3],[2,3],[1,4]]\n\n\nresult = [n*(n-1)/2]\nfor i in input_arr[::-1]:\n a = i[0]-1\n b = i[1]-1\n if not uf.same(a,b):\n x = uf.size[uf.root(a)] * uf.size[uf.root(b)]\n uf.unite(a,b)\n result.append(result[-1]-x)\n else:\n result.append(result[-1])\n\nfor i in result[::-1][1:]:\n print(i)\n\n\n', '\nclass UnionFind():\n def __init__(self, N):\n self.par = [i for i in range(N)]\n self.size = [1] * N\n self.N = N\n\n \n def root(self, x):\n if self.par[x] == x:\n return x\n else: \n self.par[x] = self.root(self.par[x])\n return self.root(self.par[x])\n\n \n def same(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n return rx == ry\n\n \n def unite(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n if self.size[rx] < self.size[ry]:\n self.par[rx] = ry\n self.size[ry] += self.size[rx]\n else:\n self.par[ry] = rx\n self.size[rx] += self.size[ry]\n\nn, m = (int(i) for i in input().split())\ninput_arr = [[int(i) for i in input().split()] for i in range(m)] \n\nuf = UnionFind(n)\n#input_arr = [[1,2],[3,4],[1,3],[2,3],[1,4]]\n\n\nresult = [int(n*(n-1)/2)]\nfor i in input_arr[::-1]:\n a = i[0]-1\n b = i[1]-1\n if not uf.same(a,b):\n x = uf.size[uf.root(a)] * uf.size[uf.root(b)]\n uf.unite(a,b)\n result.append(int(result[-1]-x))\n else:\n result.append(result[-1])\n\nfor i in result[::-1][1:]:\n print(i)\n\n\n'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s352870571', 's645019134', 's671371124', 's717889333'] | [26748.0, 26064.0, 31860.0, 30768.0] | [2105.0, 314.0, 914.0, 915.0] | [1242, 1383, 1381, 1391] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.