結果

問題 No.2072 Anatomy
ユーザー timitimi
提出日時 2022-09-17 01:28:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 589 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 118,300 KB
最終ジャッジ日時 2024-06-01 14:46:41
合計ジャッジ時間 9,369 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,544 KB
testcase_01 AC 38 ms
53,512 KB
testcase_02 AC 45 ms
59,828 KB
testcase_03 AC 45 ms
61,776 KB
testcase_04 AC 40 ms
54,068 KB
testcase_05 AC 45 ms
60,600 KB
testcase_06 AC 43 ms
59,300 KB
testcase_07 AC 46 ms
61,400 KB
testcase_08 AC 529 ms
112,820 KB
testcase_09 AC 267 ms
111,908 KB
testcase_10 AC 430 ms
111,692 KB
testcase_11 AC 330 ms
113,172 KB
testcase_12 AC 274 ms
104,504 KB
testcase_13 AC 430 ms
115,260 KB
testcase_14 AC 383 ms
101,136 KB
testcase_15 AC 226 ms
99,612 KB
testcase_16 AC 449 ms
115,884 KB
testcase_17 AC 319 ms
113,948 KB
testcase_18 AC 220 ms
96,724 KB
testcase_19 AC 437 ms
115,984 KB
testcase_20 AC 589 ms
118,300 KB
testcase_21 AC 277 ms
113,608 KB
testcase_22 AC 465 ms
116,248 KB
testcase_23 AC 272 ms
113,432 KB
testcase_24 AC 270 ms
113,360 KB
testcase_25 AC 421 ms
115,868 KB
testcase_26 AC 39 ms
52,584 KB
testcase_27 AC 266 ms
113,308 KB
testcase_28 AC 397 ms
117,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
par=[i for i in range(N)]
rank=[0]*(N)
friend=[0]*N
block=[0]*N
size=[1]*N
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
 
#同じ集合か判定
def same(x,y):
  return find(x)==find(y)
 
def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1
 
A=[] 
for i in range(M):
  a,b=map(int,input().split())
  a-=1
  b-=1
  A.append((a,b,i))
A=A[::-1]
D=[0]*N
for a,b,i in A:
  if find(a)==find(b):
    D[find(a)]+=1
  else:
    aa,bb=D[find(a)],D[find(b)]
    union(a,b)
    D[find(a)]=max(aa,bb)+1
print(max(D))
0