結果

問題 No.2563 色ごとのグループ
コンテスト
ユーザー Basin-Bug
提出日時 2023-12-02 15:45:53
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 408 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 205 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 131,968 KB
最終ジャッジ日時 2026-04-13 19:49:38
合計ジャッジ時間 6,400 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict
N, M = map(int, input().split())
C = list(map(int, input().split()))
colors = defaultdict(int)
edges = defaultdict(int)

for i in range(N):
  colors[C[i]] += 1

for i in range(M):
  u, v = map(int, input().split())
  if C[u - 1] == C[v - 1]:
    edges[C[u - 1]] += 1

ans = 0
for i, j in colors.items():
  if edges[i] < j - 1:
    ans += (j - 1) - edges[i]

print(ans)

  
0