結果

問題 No.2072 Anatomy
ユーザー 粟野翔太粟野翔太
提出日時 2022-09-16 22:08:53
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 635 ms / 2,000 ms
コード長 1,558 bytes
コンパイル時間 293 ms
使用メモリ 111,460 KB
最終ジャッジ日時 2023-01-11 07:12:20
合計ジャッジ時間 12,328 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 77 ms
75,804 KB
testcase_01 AC 75 ms
75,764 KB
testcase_02 AC 82 ms
80,352 KB
testcase_03 AC 86 ms
80,248 KB
testcase_04 AC 79 ms
75,764 KB
testcase_05 AC 84 ms
80,248 KB
testcase_06 AC 83 ms
80,088 KB
testcase_07 AC 87 ms
80,380 KB
testcase_08 AC 635 ms
108,924 KB
testcase_09 AC 384 ms
105,256 KB
testcase_10 AC 566 ms
107,484 KB
testcase_11 AC 467 ms
107,424 KB
testcase_12 AC 386 ms
102,292 KB
testcase_13 AC 528 ms
108,220 KB
testcase_14 AC 457 ms
100,540 KB
testcase_15 AC 325 ms
97,628 KB
testcase_16 AC 539 ms
109,720 KB
testcase_17 AC 444 ms
106,324 KB
testcase_18 AC 306 ms
96,236 KB
testcase_19 AC 537 ms
109,236 KB
testcase_20 AC 629 ms
111,172 KB
testcase_21 AC 407 ms
106,980 KB
testcase_22 AC 535 ms
109,496 KB
testcase_23 AC 404 ms
106,848 KB
testcase_24 AC 396 ms
106,936 KB
testcase_25 AC 523 ms
109,644 KB
testcase_26 AC 75 ms
75,672 KB
testcase_27 AC 398 ms
106,740 KB
testcase_28 AC 591 ms
111,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#int(input())
#map(int, input().split())
#list(map(int, input().split()))

import sys
sys.setrecursionlimit(200000)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
v = [0] * M
for i in range(M):
    v[i] = list(map(int, input().split()))

u = UnionFind(N)

a = [0] * N
for i in range(M):
    p, q = v[M-i-1]
    p, q = p-1, q-1
    m = max(a[u.find(p)], a[u.find(q)]) + 1
    u.union(p, q)
    a[u.find(p)] = m

print(max(a))
0