結果

問題 No.1390 Get together
ユーザー NoaSaberNoaSaber
提出日時 2021-03-09 10:11:45
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 687 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 98,816 KB
最終ジャッジ日時 2024-04-19 08:23:31
合計ジャッジ時間 9,517 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,224 KB
testcase_01 AC 43 ms
51,968 KB
testcase_02 AC 48 ms
52,224 KB
testcase_03 AC 112 ms
76,800 KB
testcase_04 AC 95 ms
76,800 KB
testcase_05 RE -
testcase_06 AC 104 ms
77,312 KB
testcase_07 RE -
testcase_08 AC 87 ms
75,136 KB
testcase_09 AC 99 ms
77,440 KB
testcase_10 AC 41 ms
52,224 KB
testcase_11 RE -
testcase_12 AC 41 ms
52,224 KB
testcase_13 RE -
testcase_14 AC 41 ms
51,968 KB
testcase_15 AC 40 ms
52,096 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 206 ms
95,652 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 384 ms
97,664 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
l=[[] for i in range(N)]
for i in range(N):
    b,c=map(int,input().split())
    b-=1
    c-=1
    l[c].append(b)
root=[i for i in range(M)]
height=[0]*M
def find(a):
    f=a
    if a==root[a]:
        return a
    while a!=root[a]:
        a=root[a]
    root[f]=a
    return a
def union(a,b):
    A=find(a)
    B=find(b)
    if A==B:
        return
    if height[A]>height[B]:
        root[B]=root[A]
        return 1
    else:
        root[A]=root[B]
        if height[A]==height[B]:
            height[B]+=1
        return 1
ans=0
for i in l:
    if len(i)<2:
        continue
    S=i[0]
    for j in range(1,len(i)):
        ans+=union(i[j],S)
print(ans)
0