結果

問題 No.2563 色ごとのグループ
ユーザー mymelochanmymelochan
提出日時 2023-12-02 14:47:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 107,456 KB
最終ジャッジ日時 2023-12-02 14:47:25
合計ジャッジ時間 5,915 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,724 KB
testcase_01 AC 38 ms
55,724 KB
testcase_02 AC 38 ms
55,724 KB
testcase_03 AC 37 ms
55,720 KB
testcase_04 AC 38 ms
55,724 KB
testcase_05 AC 38 ms
55,724 KB
testcase_06 AC 38 ms
55,724 KB
testcase_07 AC 38 ms
55,724 KB
testcase_08 WA -
testcase_09 AC 43 ms
55,724 KB
testcase_10 AC 48 ms
55,724 KB
testcase_11 AC 40 ms
55,724 KB
testcase_12 AC 46 ms
55,720 KB
testcase_13 AC 40 ms
55,724 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 56 ms
68,840 KB
testcase_17 WA -
testcase_18 AC 49 ms
64,432 KB
testcase_19 AC 58 ms
74,216 KB
testcase_20 AC 68 ms
77,440 KB
testcase_21 WA -
testcase_22 AC 65 ms
76,648 KB
testcase_23 AC 74 ms
76,776 KB
testcase_24 AC 128 ms
89,216 KB
testcase_25 AC 111 ms
91,672 KB
testcase_26 AC 166 ms
101,188 KB
testcase_27 AC 136 ms
107,456 KB
testcase_28 AC 152 ms
103,384 KB
testcase_29 AC 173 ms
107,068 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 181 ms
107,068 KB
testcase_33 AC 360 ms
106,772 KB
testcase_34 AC 334 ms
107,276 KB
testcase_35 AC 330 ms
107,276 KB
testcase_36 AC 364 ms
106,772 KB
testcase_37 AC 339 ms
106,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#############################################################

import sys
sys.setrecursionlimit(10**7)

from heapq import heappop,heappush
from collections import deque,defaultdict,Counter
from bisect import bisect_left, bisect_right
from itertools import product,combinations,permutations
from math import sin,cos
#from math import isqrt #DO NOT USE PyPy

ipt = sys.stdin.readline
iin = lambda :int(ipt())
lmin = lambda :list(map(int,ipt().split()))

#############################################################

N,M = lmin()
C = lmin()
G = [[] for _ in range(N)]
for _ in range(M):
    u,v = lmin()
    u,v = u-1,v-1
    if C[u] == C[v]:
        G[u].append(v)
        G[v].append(u)

cnt = [0]*(N+1)
visited = [0]*N
for i in range(N):
    if visited[i]:
        continue

    cnt[C[i]] += 1
    visited[i] = 1
    st = [i]
    while st:
        cur = st.pop()
        for nxt in G[cur]:
            if visited[nxt]:
                continue
            visited[nxt] = 1
            st.append(nxt)
    
ans = 0
for i in range(N):
    ans += max(0, cnt[i]-1)

print(ans)
0