結果
問題 | No.2072 Anatomy |
ユーザー | shotoyoo |
提出日時 | 2022-09-16 22:31:08 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 344 ms / 2,000 ms |
コード長 | 1,722 bytes |
コンパイル時間 | 260 ms |
コンパイル使用メモリ | 86,900 KB |
実行使用メモリ | 104,784 KB |
最終ジャッジ日時 | 2023-08-23 16:06:49 |
合計ジャッジ時間 | 8,641 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 92 ms
71,920 KB |
testcase_01 | AC | 85 ms
71,676 KB |
testcase_02 | AC | 86 ms
72,276 KB |
testcase_03 | AC | 87 ms
71,920 KB |
testcase_04 | AC | 87 ms
72,044 KB |
testcase_05 | AC | 85 ms
71,912 KB |
testcase_06 | AC | 85 ms
71,976 KB |
testcase_07 | AC | 85 ms
71,984 KB |
testcase_08 | AC | 336 ms
100,756 KB |
testcase_09 | AC | 246 ms
101,884 KB |
testcase_10 | AC | 344 ms
100,828 KB |
testcase_11 | AC | 324 ms
102,176 KB |
testcase_12 | AC | 265 ms
97,560 KB |
testcase_13 | AC | 326 ms
103,692 KB |
testcase_14 | AC | 263 ms
94,584 KB |
testcase_15 | AC | 207 ms
93,252 KB |
testcase_16 | AC | 326 ms
103,756 KB |
testcase_17 | AC | 318 ms
103,060 KB |
testcase_18 | AC | 198 ms
91,780 KB |
testcase_19 | AC | 337 ms
104,652 KB |
testcase_20 | AC | 325 ms
104,784 KB |
testcase_21 | AC | 282 ms
103,764 KB |
testcase_22 | AC | 342 ms
104,552 KB |
testcase_23 | AC | 291 ms
103,736 KB |
testcase_24 | AC | 287 ms
103,464 KB |
testcase_25 | AC | 335 ms
104,656 KB |
testcase_26 | AC | 86 ms
71,980 KB |
testcase_27 | AC | 296 ms
103,468 KB |
testcase_28 | AC | 276 ms
104,192 KB |
ソースコード
import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18 LI = lambda : list(map(int, input().split())); II=lambda : int(input()) def debug(_l_): for s in _l_.split(): print(f"{s}={eval(s)}", end=" ") print() def dlist(*l, fill=0): if len(l)==1: return [fill]*l[0] ll = l[1:] return [dlist(*ll, fill=fill) for _ in range(l[0])] class UF: # unionfind def __init__(self, n): self.n = n self.parent = list(range(n)) self.size = [1] * n self.es = [0] * n def check(self): return [self.root(i) for i in range(self.n)] def root(self, i): inter = set() while self.parent[i]!=i: inter.add(i) i = self.parent[i] r = i for i in inter: self.parent[i] = r return r def merge(self, i, j, t): # 繋いだかどうかを返す ri = self.root(i) rj = self.root(j) if ri==rj: self.es[ri] += 1 return False if self.size[ri]>self.size[rj]: ri,rj = rj,ri self.parent[ri] = rj self.size[rj] += self.size[ri] self.es[rj] = max(self.es[rj], self.es[ri]) + 1 return True def rs(self): return sorted(set([self.root(i) for i in range(self.n)])) n,m = LI() uv = [LI() for _ in range(m)] uf = UF(n) e = n val = 0 ans = 0 for i in range(m)[::-1]: u,v = uv[i] u -= 1 v -= 1 uf.merge(u,v,ans) ans = uf.es[uf.root(0)] print(ans)