結果

問題 No.2563 色ごとのグループ
ユーザー LucagonLucagon
提出日時 2023-12-02 15:53:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,796 ms / 2,000 ms
コード長 614 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 384,212 KB
最終ジャッジ日時 2023-12-02 15:54:13
合計ジャッジ時間 11,468 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,608 KB
testcase_01 AC 36 ms
55,608 KB
testcase_02 AC 36 ms
55,608 KB
testcase_03 AC 37 ms
55,608 KB
testcase_04 AC 42 ms
55,608 KB
testcase_05 AC 36 ms
55,604 KB
testcase_06 AC 35 ms
55,608 KB
testcase_07 AC 36 ms
55,608 KB
testcase_08 AC 38 ms
55,604 KB
testcase_09 AC 39 ms
55,608 KB
testcase_10 AC 35 ms
55,608 KB
testcase_11 AC 37 ms
55,608 KB
testcase_12 AC 36 ms
55,608 KB
testcase_13 AC 36 ms
55,608 KB
testcase_14 AC 61 ms
73,112 KB
testcase_15 AC 62 ms
73,100 KB
testcase_16 AC 62 ms
73,100 KB
testcase_17 AC 64 ms
73,100 KB
testcase_18 AC 46 ms
64,544 KB
testcase_19 AC 69 ms
76,556 KB
testcase_20 AC 103 ms
79,180 KB
testcase_21 AC 74 ms
77,048 KB
testcase_22 AC 73 ms
76,684 KB
testcase_23 AC 78 ms
76,796 KB
testcase_24 AC 170 ms
99,108 KB
testcase_25 AC 153 ms
101,636 KB
testcase_26 AC 197 ms
117,212 KB
testcase_27 AC 215 ms
134,800 KB
testcase_28 AC 210 ms
121,520 KB
testcase_29 AC 262 ms
135,496 KB
testcase_30 AC 260 ms
135,484 KB
testcase_31 AC 265 ms
135,484 KB
testcase_32 AC 283 ms
135,488 KB
testcase_33 AC 728 ms
162,248 KB
testcase_34 AC 1,796 ms
384,212 KB
testcase_35 AC 951 ms
210,908 KB
testcase_36 AC 1,779 ms
382,160 KB
testcase_37 AC 886 ms
222,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
from collections import defaultdict
setrecursionlimit(10**9)

def dfs(pos):
    if pos in visited: return
    visited.add(pos)

    for i in g[pos]:
        dfs(i)

n,m = map(int,input().split())
c = list(map(int,input().split()))
d = defaultdict(int)

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

visited = set()
for i in range(n):
    if i not in visited:
        dfs(i)
        d[c[i]] += 1

ans = 0
for i in d.values():
    ans += (i - 1)

print(ans)
0