結果

問題 No.2563 色ごとのグループ
ユーザー ngng628ngng628
提出日時 2023-12-02 15:27:06
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 713 bytes
コンパイル時間 10,641 ms
コンパイル使用メモリ 295,152 KB
実行使用メモリ 72,116 KB
最終ジャッジ日時 2023-12-02 15:27:24
合計ジャッジ時間 15,190 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 AC 15 ms
7,552 KB
testcase_21 AC 9 ms
6,676 KB
testcase_22 AC 7 ms
6,676 KB
testcase_23 AC 11 ms
6,676 KB
testcase_24 AC 111 ms
31,260 KB
testcase_25 AC 91 ms
39,596 KB
testcase_26 AC 131 ms
51,076 KB
testcase_27 AC 130 ms
51,024 KB
testcase_28 AC 151 ms
55,984 KB
testcase_29 AC 193 ms
68,280 KB
testcase_30 AC 197 ms
68,280 KB
testcase_31 AC 192 ms
68,280 KB
testcase_32 AC 193 ms
68,280 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = read_line.split.map &.to_i64
c = read_line.split.map &.to_i64.pred
sizes = c.tally
graph = Array.new(n) { |color| Array(Array(Int64)).new(sizes[color]? || 0) { [] of Int64 } }
hash = Array.new(n) { Hash(Int64, Int32).new }
m.times do
  u, v = read_line.split.map &.to_i64.pred
  if c[u] == c[v]
    color = c[u]
    hash[color][u] = hash[color].size unless hash[color].has_key?(u)
    hash[color][v] = hash[color].size unless hash[color].has_key?(v)
    u2 = hash[color][u]
    v2 = hash[color][v]
    graph[color][u2] << v2
    graph[color][v2] << u2
  end
end

ans = n.times.sum { |color|
  n_edges = graph[color].sum(&.size) // 2
  Math.max(0_i64, (sizes.fetch(color, 0_i64) - 1) - n_edges)
}

puts ans
0