結果

問題 No.2072 Anatomy
ユーザー flygonflygon
提出日時 2022-09-16 22:21:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 625 ms / 2,000 ms
コード長 529 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 131,944 KB
最終ジャッジ日時 2023-08-23 16:01:48
合計ジャッジ時間 11,681 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
71,580 KB
testcase_01 AC 87 ms
71,400 KB
testcase_02 AC 95 ms
75,988 KB
testcase_03 AC 96 ms
76,528 KB
testcase_04 AC 88 ms
71,716 KB
testcase_05 AC 93 ms
76,244 KB
testcase_06 AC 92 ms
72,232 KB
testcase_07 AC 96 ms
76,732 KB
testcase_08 AC 619 ms
112,764 KB
testcase_09 AC 330 ms
118,496 KB
testcase_10 AC 514 ms
114,796 KB
testcase_11 AC 413 ms
115,400 KB
testcase_12 AC 331 ms
108,168 KB
testcase_13 AC 512 ms
117,404 KB
testcase_14 AC 446 ms
104,792 KB
testcase_15 AC 281 ms
103,824 KB
testcase_16 AC 547 ms
118,412 KB
testcase_17 AC 397 ms
127,648 KB
testcase_18 AC 268 ms
101,396 KB
testcase_19 AC 533 ms
118,100 KB
testcase_20 AC 625 ms
118,216 KB
testcase_21 AC 334 ms
131,944 KB
testcase_22 AC 536 ms
118,224 KB
testcase_23 AC 340 ms
131,940 KB
testcase_24 AC 337 ms
131,844 KB
testcase_25 AC 524 ms
118,064 KB
testcase_26 AC 87 ms
71,392 KB
testcase_27 AC 343 ms
131,720 KB
testcase_28 AC 502 ms
122,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
es = [list(map(int,input().split())) for i in range(m)]

p = [-1]*(n+1)
def find(x):
  if p[x] < 0:
    return x
  else:
    p[x] = find(p[x])
    return p[x]
def union(x,y):
  x = find(x)
  y = find(y)
  if x == y:
    return
  if p[x] > p[y]:
    x,y = y,x
  p[x] += p[y]
  p[y] = x

from collections import defaultdict
ps = defaultdict(int)
for i in range(m)[::-1]:
  u,v = es[i]
  uu,vv = find(u),find(v)
  mx = max(ps[uu],ps[vv])
  union(uu,vv)
  ps[find(uu)] = mx + 1

print(max(ps.values()))
0