結果

問題 No.2072 Anatomy
ユーザー dn6049949dn6049949
提出日時 2022-09-16 22:16:11
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 540 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 366 ms
使用メモリ 110,724 KB
最終ジャッジ日時 2023-01-11 07:28:02
合計ジャッジ時間 11,059 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 96 ms
76,688 KB
testcase_01 AC 98 ms
76,516 KB
testcase_02 AC 101 ms
81,024 KB
testcase_03 AC 102 ms
80,888 KB
testcase_04 AC 98 ms
76,744 KB
testcase_05 AC 102 ms
81,288 KB
testcase_06 AC 100 ms
76,472 KB
testcase_07 AC 104 ms
81,284 KB
testcase_08 AC 538 ms
107,072 KB
testcase_09 AC 262 ms
104,588 KB
testcase_10 AC 457 ms
104,520 KB
testcase_11 AC 341 ms
106,548 KB
testcase_12 AC 301 ms
100,904 KB
testcase_13 AC 469 ms
108,620 KB
testcase_14 AC 415 ms
99,836 KB
testcase_15 AC 218 ms
97,460 KB
testcase_16 AC 479 ms
108,384 KB
testcase_17 AC 291 ms
106,180 KB
testcase_18 AC 206 ms
94,788 KB
testcase_19 AC 474 ms
109,368 KB
testcase_20 AC 540 ms
110,724 KB
testcase_21 AC 258 ms
106,004 KB
testcase_22 AC 493 ms
109,564 KB
testcase_23 AC 273 ms
106,080 KB
testcase_24 AC 249 ms
105,952 KB
testcase_25 AC 456 ms
108,096 KB
testcase_26 AC 97 ms
76,872 KB
testcase_27 AC 275 ms
106,392 KB
testcase_28 AC 428 ms
110,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0