結果

問題 No.2563 色ごとのグループ
ユーザー ああいいああいい
提出日時 2023-12-02 19:48:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 125,012 KB
最終ジャッジ日時 2023-12-02 19:48:40
合計ジャッジ時間 7,429 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 37 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 39 ms
53,460 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
testcase_12 AC 37 ms
53,460 KB
testcase_13 AC 37 ms
53,460 KB
testcase_14 AC 62 ms
68,788 KB
testcase_15 AC 63 ms
68,796 KB
testcase_16 AC 63 ms
68,796 KB
testcase_17 AC 63 ms
68,796 KB
testcase_18 AC 41 ms
59,440 KB
testcase_19 AC 66 ms
72,948 KB
testcase_20 AC 94 ms
76,964 KB
testcase_21 AC 78 ms
76,148 KB
testcase_22 AC 91 ms
76,276 KB
testcase_23 AC 76 ms
76,020 KB
testcase_24 AC 185 ms
94,612 KB
testcase_25 AC 144 ms
96,896 KB
testcase_26 AC 199 ms
110,416 KB
testcase_27 AC 177 ms
124,568 KB
testcase_28 AC 214 ms
113,708 KB
testcase_29 AC 244 ms
125,012 KB
testcase_30 AC 258 ms
125,008 KB
testcase_31 AC 256 ms
125,008 KB
testcase_32 AC 264 ms
125,008 KB
testcase_33 AC 432 ms
107,164 KB
testcase_34 AC 414 ms
106,576 KB
testcase_35 AC 404 ms
106,576 KB
testcase_36 AC 400 ms
107,164 KB
testcase_37 AC 416 ms
107,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 8)


N,M = map(int,input().split())
C = list(map(int,input().split()))

parent = list(range(N))
def find(i):
    if parent[i] == i: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
    parent[i] = J
    parent[I] = J
    return True

col = set(C)
count = 0
for _ in range(M):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    if C[u] != C[v]:continue
    if unite(u,v):
        count += 1
print(N - len(col) - count)
0