結果

問題 No.1390 Get together
ユーザー 👑 timitimi
提出日時 2021-03-01 17:03:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 548 ms / 2,000 ms
コード長 778 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 109,852 KB
最終ジャッジ日時 2024-04-14 03:44:43
合計ジャッジ時間 10,039 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,816 KB
testcase_01 AC 37 ms
53,136 KB
testcase_02 AC 36 ms
53,068 KB
testcase_03 AC 90 ms
77,064 KB
testcase_04 AC 92 ms
77,100 KB
testcase_05 AC 93 ms
77,148 KB
testcase_06 AC 90 ms
77,028 KB
testcase_07 AC 90 ms
77,044 KB
testcase_08 AC 91 ms
76,732 KB
testcase_09 AC 110 ms
77,212 KB
testcase_10 AC 45 ms
53,028 KB
testcase_11 AC 45 ms
53,672 KB
testcase_12 AC 45 ms
52,264 KB
testcase_13 AC 45 ms
52,584 KB
testcase_14 AC 45 ms
53,696 KB
testcase_15 AC 44 ms
52,948 KB
testcase_16 AC 203 ms
92,604 KB
testcase_17 AC 341 ms
107,948 KB
testcase_18 AC 194 ms
92,632 KB
testcase_19 AC 548 ms
109,852 KB
testcase_20 AC 528 ms
109,364 KB
testcase_21 AC 460 ms
109,216 KB
testcase_22 AC 329 ms
103,516 KB
testcase_23 AC 306 ms
102,916 KB
testcase_24 AC 324 ms
103,856 KB
testcase_25 AC 443 ms
109,228 KB
testcase_26 AC 449 ms
109,352 KB
testcase_27 AC 527 ms
109,188 KB
testcase_28 AC 514 ms
109,356 KB
testcase_29 AC 456 ms
109,088 KB
testcase_30 AC 473 ms
109,340 KB
testcase_31 AC 446 ms
109,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
F=max(N,M)
par=[i for i in range(F)]
rank=[0]*(F)
friend=[0]*F
block=[0]*F
size=[1]*F
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
 
D={}
for i in range(N):
  a,b=map(int,input().split())
  a-=1
  b-=1
  if b not in D:
    D[b]=[a]
  else:
    D[b].append(a)

for i in D:
  d=D[i]
  for j in range(len(d)-1):
    union(d[j],d[j+1])
E=[0]*F
ans=0
for i in range(F):
  d=find(i)
  if E[d]==0:
    E[d]=1
  else:
    ans+=1
print(ans)
0