結果

問題 No.2072 Anatomy
ユーザー Akijin_007Akijin_007
提出日時 2022-09-16 22:08:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 512 ms / 2,000 ms
コード長 1,558 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 87,348 KB
実行使用メモリ 105,588 KB
最終ジャッジ日時 2023-08-23 15:43:04
合計ジャッジ時間 10,287 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,240 KB
testcase_01 AC 72 ms
71,224 KB
testcase_02 AC 83 ms
75,032 KB
testcase_03 AC 83 ms
75,276 KB
testcase_04 AC 77 ms
70,976 KB
testcase_05 AC 82 ms
75,288 KB
testcase_06 AC 78 ms
75,204 KB
testcase_07 AC 82 ms
75,148 KB
testcase_08 AC 512 ms
102,004 KB
testcase_09 AC 293 ms
99,840 KB
testcase_10 AC 429 ms
102,016 KB
testcase_11 AC 346 ms
101,776 KB
testcase_12 AC 293 ms
96,352 KB
testcase_13 AC 399 ms
103,444 KB
testcase_14 AC 367 ms
94,484 KB
testcase_15 AC 239 ms
92,624 KB
testcase_16 AC 411 ms
103,516 KB
testcase_17 AC 332 ms
101,072 KB
testcase_18 AC 229 ms
90,716 KB
testcase_19 AC 409 ms
103,700 KB
testcase_20 AC 482 ms
105,016 KB
testcase_21 AC 274 ms
100,336 KB
testcase_22 AC 404 ms
103,588 KB
testcase_23 AC 284 ms
100,476 KB
testcase_24 AC 281 ms
100,468 KB
testcase_25 AC 393 ms
103,484 KB
testcase_26 AC 73 ms
71,276 KB
testcase_27 AC 277 ms
100,476 KB
testcase_28 AC 454 ms
105,588 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