結果

問題 No.2072 Anatomy
ユーザー titiatitia
提出日時 2022-09-18 03:11:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,005 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 50,048 KB
最終ジャッジ日時 2024-06-01 15:23:46
合計ジャッジ時間 18,678 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 AC 34 ms
10,880 KB
testcase_02 AC 30 ms
10,624 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 31 ms
10,752 KB
testcase_08 AC 867 ms
44,544 KB
testcase_09 AC 812 ms
47,232 KB
testcase_10 AC 840 ms
43,776 KB
testcase_11 AC 840 ms
46,976 KB
testcase_12 AC 645 ms
38,528 KB
testcase_13 AC 982 ms
48,896 KB
testcase_14 AC 596 ms
34,688 KB
testcase_15 AC 534 ms
34,560 KB
testcase_16 AC 974 ms
48,896 KB
testcase_17 AC 853 ms
48,512 KB
testcase_18 AC 461 ms
30,848 KB
testcase_19 AC 987 ms
50,048 KB
testcase_20 AC 1,005 ms
49,920 KB
testcase_21 AC 853 ms
50,048 KB
testcase_22 AC 987 ms
50,048 KB
testcase_23 AC 884 ms
50,048 KB
testcase_24 AC 851 ms
49,920 KB
testcase_25 AC 994 ms
49,920 KB
testcase_26 AC 29 ms
10,752 KB
testcase_27 AC 877 ms
49,920 KB
testcase_28 AC 759 ms
49,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline


N,M=map(int,input().split())
E=[tuple(map(int,input().split())) for i in range(M)]

# UnionFind

Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

ANS=[0]*(N+1)

for a,b in E[::-1]:
    x=find(a)
    y=find(b)

    Union(a,b)

    ANS[find(a)]=max(ANS[x],ANS[y])+1

print(max(ANS))
0