結果

問題 No.1390 Get together
ユーザー 👑 timitimi
提出日時 2021-03-01 16:53:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 781 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 82,488 KB
実行使用メモリ 109,984 KB
最終ジャッジ日時 2024-04-14 03:44:32
合計ジャッジ時間 9,287 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
67,564 KB
testcase_01 AC 46 ms
67,472 KB
testcase_02 AC 46 ms
67,304 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 48 ms
68,160 KB
testcase_15 AC 47 ms
67,036 KB
testcase_16 AC 197 ms
92,472 KB
testcase_17 AC 314 ms
107,832 KB
testcase_18 AC 189 ms
92,384 KB
testcase_19 AC 471 ms
109,984 KB
testcase_20 AC 437 ms
109,356 KB
testcase_21 AC 402 ms
108,716 KB
testcase_22 AC 311 ms
103,316 KB
testcase_23 AC 288 ms
102,540 KB
testcase_24 AC 311 ms
103,436 KB
testcase_25 AC 425 ms
109,352 KB
testcase_26 AC 419 ms
109,224 KB
testcase_27 AC 430 ms
108,928 KB
testcase_28 AC 446 ms
109,220 KB
testcase_29 AC 409 ms
109,352 KB
testcase_30 AC 431 ms
109,588 KB
testcase_31 AC 417 ms
108,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
f=2*10**5+1
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(N):
  d=find(i)
  if E[d]==0:
    E[d]=1
  else:
    ans+=1
print(ans)
0