結果

問題 No.2563 色ごとのグループ
ユーザー AngrySadEightAngrySadEight
提出日時 2023-11-24 01:33:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 895 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,256 KB
最終ジャッジ日時 2023-12-02 14:01:38
合計ジャッジ時間 7,049 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,604 KB
testcase_01 AC 39 ms
55,604 KB
testcase_02 AC 35 ms
55,604 KB
testcase_03 AC 36 ms
55,604 KB
testcase_04 AC 35 ms
55,604 KB
testcase_05 AC 35 ms
55,604 KB
testcase_06 AC 36 ms
55,604 KB
testcase_07 AC 36 ms
55,604 KB
testcase_08 AC 35 ms
55,604 KB
testcase_09 AC 40 ms
61,576 KB
testcase_10 AC 37 ms
55,604 KB
testcase_11 AC 41 ms
61,576 KB
testcase_12 AC 42 ms
62,208 KB
testcase_13 AC 39 ms
59,444 KB
testcase_14 AC 61 ms
70,992 KB
testcase_15 AC 60 ms
66,784 KB
testcase_16 AC 60 ms
66,788 KB
testcase_17 AC 63 ms
68,888 KB
testcase_18 AC 50 ms
66,560 KB
testcase_19 AC 194 ms
77,008 KB
testcase_20 AC 337 ms
77,672 KB
testcase_21 AC 236 ms
76,900 KB
testcase_22 AC 250 ms
77,264 KB
testcase_23 AC 792 ms
78,256 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
C = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for i in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    for i in range(M):
        if C[u] == C[v]:
            graph[u].append(v)
            graph[v].append(u)

ans = 0
Clen = [0 for _ in range(N + 1)]
for i in range(N):
    Clen[C[i]] += 1
isvisited = [False for _ in range(N)]
dq = deque()
for i in range(N):
    if isvisited[i]:
        continue
    isvisited[i] = True
    dq.append(i)
    while len(dq):
        Clen[C[i]] -= 1
        p = dq.popleft()
        for x in graph[p]:
            if isvisited[x]:
                continue
            isvisited[x] = True
            dq.append(x)
    Clen[C[i]] += 1
# print(Clen)
for i in range(1, N + 1):
    ans += max(0, Clen[i] - 1)
print(ans)
0