結果

問題 No.2563 色ごとのグループ
ユーザー ちーぴんちーぴん
提出日時 2023-12-02 15:26:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 112,888 KB
最終ジャッジ日時 2023-12-02 15:26:56
合計ジャッジ時間 7,395 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 40 ms
53,460 KB
testcase_10 AC 39 ms
53,460 KB
testcase_11 AC 41 ms
53,460 KB
testcase_12 AC 39 ms
53,460 KB
testcase_13 AC 39 ms
53,460 KB
testcase_14 AC 73 ms
70,940 KB
testcase_15 AC 65 ms
70,940 KB
testcase_16 AC 65 ms
70,940 KB
testcase_17 AC 68 ms
70,940 KB
testcase_18 AC 50 ms
62,368 KB
testcase_19 AC 71 ms
73,372 KB
testcase_20 AC 89 ms
77,052 KB
testcase_21 AC 83 ms
76,572 KB
testcase_22 AC 79 ms
76,188 KB
testcase_23 AC 86 ms
76,444 KB
testcase_24 AC 190 ms
89,880 KB
testcase_25 AC 154 ms
91,996 KB
testcase_26 AC 193 ms
102,044 KB
testcase_27 AC 176 ms
112,180 KB
testcase_28 AC 219 ms
105,680 KB
testcase_29 AC 284 ms
112,000 KB
testcase_30 AC 255 ms
112,000 KB
testcase_31 AC 258 ms
111,872 KB
testcase_32 AC 259 ms
112,000 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
考察
色違いの場合、辺はないと考えて良さそう
色ごとのグループ数 - 1 の和が答え

色ごとの頂点数を数えておく
辺を結ぶたびに、その色の頂点数を1減らす
"""

N, M = map(int, input().split())
C = list(map(lambda x:int(x)-1, input().split()))

cnt = [0] * N
for c in C:
    cnt[c] += 1

G = [[] for _ in range(N)]
for _ 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)
        cnt[C[a]] -= 1
ans = sum(c - 1 for c in cnt if c > 0)
print(ans)
0