結果
問題 | No.2072 Anatomy |
ユーザー |
|
提出日時 | 2022-09-16 22:31:08 |
言語 | PyPy3 (7.3.8) |
結果 |
AC
|
実行時間 | 362 ms / 2,000 ms |
コード長 | 1,722 bytes |
コンパイル時間 | 267 ms |
使用メモリ | 109,588 KB |
最終ジャッジ日時 | 2023-01-11 07:44:18 |
合計ジャッジ時間 | 9,335 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
76,556 KB |
testcase_01 | AC | 89 ms
76,748 KB |
testcase_02 | AC | 91 ms
76,580 KB |
testcase_03 | AC | 92 ms
76,484 KB |
testcase_04 | AC | 91 ms
76,684 KB |
testcase_05 | AC | 92 ms
76,748 KB |
testcase_06 | AC | 93 ms
76,632 KB |
testcase_07 | AC | 94 ms
76,468 KB |
testcase_08 | AC | 360 ms
106,060 KB |
testcase_09 | AC | 265 ms
106,564 KB |
testcase_10 | AC | 356 ms
106,280 KB |
testcase_11 | AC | 338 ms
107,216 KB |
testcase_12 | AC | 286 ms
102,048 KB |
testcase_13 | AC | 362 ms
108,744 KB |
testcase_14 | AC | 288 ms
99,500 KB |
testcase_15 | AC | 221 ms
98,784 KB |
testcase_16 | AC | 340 ms
108,340 KB |
testcase_17 | AC | 345 ms
107,808 KB |
testcase_18 | AC | 210 ms
96,772 KB |
testcase_19 | AC | 354 ms
109,328 KB |
testcase_20 | AC | 355 ms
109,588 KB |
testcase_21 | AC | 302 ms
108,432 KB |
testcase_22 | AC | 346 ms
109,480 KB |
testcase_23 | AC | 305 ms
108,500 KB |
testcase_24 | AC | 292 ms
108,504 KB |
testcase_25 | AC | 339 ms
109,324 KB |
testcase_26 | AC | 91 ms
76,684 KB |
testcase_27 | AC | 294 ms
108,516 KB |
testcase_28 | AC | 279 ms
109,264 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)