結果

問題 No.2563 色ごとのグループ
ユーザー noriaokinoriaoki
提出日時 2023-12-02 16:00:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 470 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 151,656 KB
最終ジャッジ日時 2023-12-02 16:00:29
合計ジャッジ時間 7,189 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,460 KB
testcase_01 AC 31 ms
53,460 KB
testcase_02 AC 33 ms
53,460 KB
testcase_03 AC 30 ms
53,460 KB
testcase_04 AC 31 ms
53,460 KB
testcase_05 AC 30 ms
53,460 KB
testcase_06 AC 29 ms
53,460 KB
testcase_07 AC 30 ms
53,460 KB
testcase_08 AC 33 ms
53,460 KB
testcase_09 AC 34 ms
53,460 KB
testcase_10 AC 32 ms
53,460 KB
testcase_11 AC 33 ms
53,460 KB
testcase_12 AC 31 ms
53,460 KB
testcase_13 AC 34 ms
53,460 KB
testcase_14 AC 57 ms
70,920 KB
testcase_15 AC 58 ms
70,912 KB
testcase_16 AC 60 ms
70,916 KB
testcase_17 AC 58 ms
70,920 KB
testcase_18 AC 41 ms
62,340 KB
testcase_19 AC 80 ms
76,896 KB
testcase_20 AC 78 ms
78,580 KB
testcase_21 AC 73 ms
78,432 KB
testcase_22 AC 74 ms
78,432 KB
testcase_23 AC 82 ms
78,700 KB
testcase_24 AC 206 ms
112,584 KB
testcase_25 AC 166 ms
102,092 KB
testcase_26 AC 218 ms
114,768 KB
testcase_27 AC 179 ms
105,852 KB
testcase_28 AC 269 ms
117,544 KB
testcase_29 AC 298 ms
132,900 KB
testcase_30 AC 293 ms
132,904 KB
testcase_31 AC 303 ms
133,028 KB
testcase_32 AC 323 ms
133,028 KB
testcase_33 AC 421 ms
151,488 KB
testcase_34 AC 422 ms
151,656 KB
testcase_35 AC 470 ms
151,528 KB
testcase_36 AC 436 ms
151,492 KB
testcase_37 AC 436 ms
151,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
C = list(map(int, input().split()))
UV = [map(int, input().split()) for _ in range(M)]

graph = [[] for _ in range(N)]
for U, V in UV:
    U -= 1
    V -= 1
    if C[U] == C[V]:
        graph[U].append(V)
        graph[V].append(U)

ac = [False] * N
col = [False] * N
ans = 0
for i in range(N):
    if ac[i]:
        continue
    if col[C[i]-1]:
        ans += 1
    col[C[i]-1] = True
    q = [i]
    while q:
        now = q.pop()
        if ac[now]:
            continue
        ac[now] = True
        for g in graph[now]:
            if ac[g]:
                continue
            q.append(g)
print(ans)
0