結果

問題 No.2563 色ごとのグループ
ユーザー あ
提出日時 2023-12-13 23:51:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,091 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 184,800 KB
最終ジャッジ日時 2023-12-13 23:51:36
合計ジャッジ時間 10,631 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 38 ms
53,460 KB
testcase_10 AC 36 ms
53,460 KB
testcase_11 AC 39 ms
53,460 KB
testcase_12 AC 39 ms
53,460 KB
testcase_13 AC 41 ms
53,460 KB
testcase_14 AC 67 ms
73,020 KB
testcase_15 AC 69 ms
73,348 KB
testcase_16 AC 69 ms
73,348 KB
testcase_17 AC 73 ms
72,964 KB
testcase_18 AC 46 ms
62,096 KB
testcase_19 AC 77 ms
76,036 KB
testcase_20 AC 86 ms
77,048 KB
testcase_21 AC 82 ms
76,420 KB
testcase_22 AC 81 ms
76,164 KB
testcase_23 AC 90 ms
76,420 KB
testcase_24 AC 248 ms
89,748 KB
testcase_25 AC 210 ms
92,140 KB
testcase_26 AC 289 ms
101,916 KB
testcase_27 AC 217 ms
105,840 KB
testcase_28 AC 291 ms
104,064 KB
testcase_29 AC 373 ms
106,816 KB
testcase_30 AC 396 ms
106,816 KB
testcase_31 AC 371 ms
106,792 KB
testcase_32 AC 369 ms
106,816 KB
testcase_33 AC 1,091 ms
184,800 KB
testcase_34 AC 855 ms
158,684 KB
testcase_35 AC 829 ms
158,572 KB
testcase_36 AC 1,082 ms
182,672 KB
testcase_37 AC 859 ms
161,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')

import sys
sys.setrecursionlimit(10 ** 8)

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