結果

問題 No.762 PDCAパス
ユーザー siman
提出日時 2021-05-07 12:12:27
言語 Ruby
(3.4.1)
結果
AC  
実行時間 459 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 34,560 KB
最終ジャッジ日時 2024-09-15 00:47:44
合計ジャッジ時間 12,297 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

MOD = 10 ** 9 + 7
N, M = gets.split.map(&:to_i)
S = gets.chomp
E = Hash.new { |h, k| h[k] = [] }

M.times do
  u, v = gets.split.map(&:to_i)
  u -= 1
  v -= 1

  E[u] << v
  E[v] << u
end

counter = Hash.new(0)
que = []

S.chars.each_with_index do |s, idx|
  next if s != 'P'

  que << idx
  counter[idx] += 1
end

L = ['D', 'C', 'A']

3.times do |i|
  temp_counter = Hash.new(0)
  temp_que = Hash.new

  until que.empty?
    v = que.shift

    E[v].each do |u|
      next if S[u] != L[i]

      temp_counter[u] += counter[v]
      temp_counter[u] %= MOD
      temp_que[u] = true
    end
  end

  counter = temp_counter
  que = temp_que.keys
end

pp counter.values.sum % MOD
0