結果
問題 | No.2072 Anatomy |
ユーザー | dn6049949 |
提出日時 | 2022-09-16 22:16:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 511 ms / 2,000 ms |
コード長 | 1,489 bytes |
コンパイル時間 | 269 ms |
コンパイル使用メモリ | 87,132 KB |
実行使用メモリ | 106,512 KB |
最終ジャッジ日時 | 2023-08-23 15:55:16 |
合計ジャッジ時間 | 10,473 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 91 ms
71,924 KB |
testcase_01 | AC | 94 ms
71,484 KB |
testcase_02 | AC | 97 ms
76,752 KB |
testcase_03 | AC | 97 ms
76,376 KB |
testcase_04 | AC | 94 ms
72,228 KB |
testcase_05 | AC | 96 ms
76,696 KB |
testcase_06 | AC | 96 ms
72,196 KB |
testcase_07 | AC | 97 ms
76,736 KB |
testcase_08 | AC | 511 ms
103,704 KB |
testcase_09 | AC | 243 ms
100,616 KB |
testcase_10 | AC | 425 ms
101,192 KB |
testcase_11 | AC | 322 ms
101,100 KB |
testcase_12 | AC | 277 ms
96,348 KB |
testcase_13 | AC | 429 ms
103,684 KB |
testcase_14 | AC | 383 ms
95,720 KB |
testcase_15 | AC | 205 ms
92,772 KB |
testcase_16 | AC | 440 ms
103,604 KB |
testcase_17 | AC | 277 ms
101,632 KB |
testcase_18 | AC | 195 ms
90,288 KB |
testcase_19 | AC | 437 ms
104,304 KB |
testcase_20 | AC | 511 ms
106,512 KB |
testcase_21 | AC | 247 ms
101,504 KB |
testcase_22 | AC | 457 ms
105,448 KB |
testcase_23 | AC | 253 ms
101,568 KB |
testcase_24 | AC | 241 ms
101,496 KB |
testcase_25 | AC | 413 ms
104,124 KB |
testcase_26 | AC | 90 ms
71,532 KB |
testcase_27 | AC | 257 ms
101,520 KB |
testcase_28 | AC | 389 ms
104,928 KB |
ソースコード
from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 class UnionFind: __slots__ = ["par", "rank", "size"] def __init__(self, n): self.par = list(range(n)) self.rank = [0]*n self.size = [1]*n def root(self, x): if x == self.par[x]: return x self.par[x] = self.root(self.par[x]) return self.par[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 return def main(): n,m = LI() edges = LIR(m) uf = UnionFind(n) f = [0]*n for a,b in reversed(edges): a -= 1 b -= 1 ra = uf.root(a) rb = uf.root(b) if ra != rb: uf.unite(a,b) f[uf.root(a)] = max(f[ra],f[rb])+1 else: f[ra] += 1 print(max(f)) return if __name__ == "__main__": main()