結果

問題 No.2072 Anatomy
ユーザー kyskys
提出日時 2022-09-16 21:52:25
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 565 ms / 2,000 ms
コード長 2,418 bytes
コンパイル時間 549 ms
使用メモリ 105,860 KB
最終ジャッジ日時 2023-01-11 06:38:03
合計ジャッジ時間 10,247 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 70 ms
75,544 KB
testcase_01 AC 71 ms
75,504 KB
testcase_02 AC 74 ms
80,232 KB
testcase_03 AC 75 ms
80,452 KB
testcase_04 AC 74 ms
75,772 KB
testcase_05 AC 79 ms
79,968 KB
testcase_06 AC 82 ms
80,256 KB
testcase_07 AC 84 ms
80,308 KB
testcase_08 AC 545 ms
105,272 KB
testcase_09 AC 223 ms
101,240 KB
testcase_10 AC 448 ms
102,176 KB
testcase_11 AC 334 ms
102,348 KB
testcase_12 AC 290 ms
97,144 KB
testcase_13 AC 484 ms
104,956 KB
testcase_14 AC 409 ms
95,832 KB
testcase_15 AC 210 ms
94,904 KB
testcase_16 AC 480 ms
104,408 KB
testcase_17 AC 293 ms
102,284 KB
testcase_18 AC 205 ms
92,520 KB
testcase_19 AC 474 ms
104,396 KB
testcase_20 AC 565 ms
105,860 KB
testcase_21 AC 209 ms
101,980 KB
testcase_22 AC 444 ms
105,444 KB
testcase_23 AC 211 ms
102,064 KB
testcase_24 AC 211 ms
102,176 KB
testcase_25 AC 436 ms
104,604 KB
testcase_26 AC 70 ms
75,828 KB
testcase_27 AC 213 ms
102,068 KB
testcase_28 AC 375 ms
105,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    from sys import stdin, setrecursionlimit
    # setrecursionlimit(1000000)
    input = stdin.readline
    def iinput(): return int(input())
    def sinput(): return input().rstrip()
    def i0input(): return int(input()) - 1
    def linput(): return list(input().split())
    def liinput(): return list(map(int, input().split()))
    def miinput(): return map(int, input().split())
    def li0input(): return list(map(lambda x: int(x) - 1, input().split()))
    def mi0input(): return map(lambda x: int(x) - 1, input().split())
    INF = 1000000000000000000
    MOD = 1000000007

    class UnionFindTree:
        def __init__(self, initial_size:int) -> None:
            self.n_nodes = initial_size
            self.parents = [i for i in range(initial_size)]
            self.ranks = [0 for i in range(initial_size)]
            self.size = [1 for i in range(initial_size)]
            self.n_roots = initial_size
        def root(self, n:int) -> int:
            if self.parents[n] == n:
                return n
            else:
                self.parents[n] = self.root(self.parents[n])
                return self.parents[n]
        def same(self, n:int, m:int) -> bool:
            return (self.root(n) == self.root(m))
        def unite(self, n:int, m:int) -> None:
            if self.same(n, m):
                return
            self.n_roots -= 1
            n, m = self.root(n), self.root(m)
            if self.ranks[n] < self.ranks[m]:
                self.parents[n] = m
                self.size[m] += self.size[n]
            else:
                self.parents[m] = n
                self.size[n] += self.size[m]
                if self.ranks[n] == self.ranks[m]:
                    self.ranks[n] += 1
        def get_roots(self) -> set:
            return set([self.root(x) for x in range(self.n_nodes)])
        def count_roots(self) -> int:
            return self.n_roots
        def get_tree_size(self, n:int) -> int:
            return self.size[self.root(n)]

    N, M = miinput()
    uf = UnionFindTree(N)
    UV = []
    for _ in [0] * M:
        u, v = mi0input()
        UV.append((u, v))
    
    ctr = [0] * N
    for u, v in UV[::-1]:
        u = uf.root(u)
        v = uf.root(v)
        if u == v:
            ctr[u] += 1
        else:
            uf.unite(u, v)
            r = uf.root(u)
            ctr[r] = max(ctr[u], ctr[v]) + 1
    print(max(ctr))
    

main()
0