結果

問題 No.1390 Get together
ユーザー ああいいああいい
提出日時 2022-01-08 20:51:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 82,276 KB
実行使用メモリ 96,248 KB
最終ジャッジ日時 2024-04-26 19:30:37
合計ジャッジ時間 9,207 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,396 KB
testcase_01 AC 36 ms
53,220 KB
testcase_02 AC 38 ms
52,288 KB
testcase_03 AC 89 ms
76,652 KB
testcase_04 AC 84 ms
76,460 KB
testcase_05 AC 93 ms
76,928 KB
testcase_06 AC 86 ms
76,452 KB
testcase_07 AC 82 ms
76,452 KB
testcase_08 AC 83 ms
76,280 KB
testcase_09 AC 93 ms
76,696 KB
testcase_10 AC 38 ms
54,040 KB
testcase_11 AC 38 ms
52,672 KB
testcase_12 AC 37 ms
52,892 KB
testcase_13 AC 38 ms
52,960 KB
testcase_14 AC 38 ms
52,024 KB
testcase_15 AC 37 ms
52,948 KB
testcase_16 AC 195 ms
92,952 KB
testcase_17 AC 304 ms
95,924 KB
testcase_18 AC 187 ms
92,812 KB
testcase_19 AC 362 ms
95,572 KB
testcase_20 AC 365 ms
95,836 KB
testcase_21 AC 368 ms
95,724 KB
testcase_22 AC 278 ms
95,012 KB
testcase_23 AC 296 ms
95,308 KB
testcase_24 AC 293 ms
95,200 KB
testcase_25 AC 360 ms
96,032 KB
testcase_26 AC 362 ms
95,668 KB
testcase_27 AC 373 ms
96,248 KB
testcase_28 AC 355 ms
95,436 KB
testcase_29 AC 352 ms
95,760 KB
testcase_30 AC 353 ms
95,892 KB
testcase_31 AC 359 ms
95,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
import sys
sys.setrecursionlimit(10 ** 6)

parent = [-1] * (M + 1)
def find(i):
    if parent[i] < 0:
        return i
    parent[i] = find(parent[i])
    return parent[i]
def unite(i,j):
    I = find(i)
    J = find(j)
    if I == J:return False
    if -parent[I] > -parent[J]:
        I,J = J,I
    parent[J] += parent[I]
    parent[I] = J
    return True

col = [[] for _ in range(N+1)]
for _ in range(N):
    b,c = map(int,input().split())
    col[c].append(b)
for i in range(1,N+1):
    if len(col[i]) >= 2:
        for b in col[i]:
            unite(b,col[i][0])
ans = 0
for i in range(1,M+1):
    if parent[i] < 0:
        ans += -parent[i] - 1
print(ans)
0