結果

問題 No.2563 色ごとのグループ
ユーザー あ
提出日時 2023-12-13 23:50:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,378 ms / 2,000 ms
コード長 651 bytes
コンパイル時間 466 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 65,164 KB
最終ジャッジ日時 2023-12-13 23:51:07
合計ジャッジ時間 18,304 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,112 KB
testcase_01 AC 31 ms
10,112 KB
testcase_02 AC 29 ms
10,112 KB
testcase_03 AC 29 ms
10,112 KB
testcase_04 AC 31 ms
10,112 KB
testcase_05 AC 30 ms
10,112 KB
testcase_06 AC 29 ms
10,112 KB
testcase_07 AC 31 ms
10,112 KB
testcase_08 AC 30 ms
10,112 KB
testcase_09 AC 31 ms
10,112 KB
testcase_10 AC 29 ms
10,112 KB
testcase_11 AC 30 ms
10,112 KB
testcase_12 AC 29 ms
10,112 KB
testcase_13 AC 30 ms
10,112 KB
testcase_14 AC 34 ms
10,368 KB
testcase_15 AC 38 ms
10,368 KB
testcase_16 AC 41 ms
10,368 KB
testcase_17 AC 37 ms
10,368 KB
testcase_18 AC 32 ms
10,496 KB
testcase_19 AC 52 ms
10,368 KB
testcase_20 AC 86 ms
13,568 KB
testcase_21 AC 71 ms
11,648 KB
testcase_22 AC 61 ms
11,008 KB
testcase_23 AC 90 ms
11,392 KB
testcase_24 AC 586 ms
24,492 KB
testcase_25 AC 502 ms
26,724 KB
testcase_26 AC 627 ms
35,956 KB
testcase_27 AC 542 ms
45,484 KB
testcase_28 AC 732 ms
38,940 KB
testcase_29 AC 1,019 ms
47,428 KB
testcase_30 AC 1,011 ms
47,428 KB
testcase_31 AC 974 ms
47,428 KB
testcase_32 AC 995 ms
47,428 KB
testcase_33 AC 1,378 ms
65,164 KB
testcase_34 AC 1,370 ms
65,104 KB
testcase_35 AC 1,362 ms
64,976 KB
testcase_36 AC 1,369 ms
65,164 KB
testcase_37 AC 1,343 ms
65,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)

def dfs(now, g, visited):
    visited[now] = True
    for nex in g[now]:
        if visited[nex]:
            continue
        dfs(nex, g, visited)

n, m = map(int, input().split())
g = [[] for _ in range(n)]
c = list(map(int, input().split()))
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    if c[u] == c[v]:
        g[u].append(v)
        g[v].append(u)

com = [0] * n
visited = [False] * n
for i in range(n):
    if not visited[i]:
        dfs(i, g, visited)
        com[c[i] - 1] += 1

ans = 0
for i in range(n):
    if com[i] != 0:
        ans += com[i] - 1

print(ans)
0