結果

問題 No.19 ステージの選択
ユーザー gigurururu
提出日時 2015-01-01 22:49:15
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 407 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-06-13 01:10:43
合計ジャッジ時間 3,721 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require'tsort'
class Array
  include TSort
  alias tsort_each_node each_index
  def tsort_each_child(node, &block)
    block.call self[node]
  end
end

r=1..n=gets.to_i
s=[]
l=r.map{|i|a,b=gets.split;s[i-1]=b.to_i-1;a.to_f}

gone=[false]*n
sum=0
s.each_strongly_connected_component{|a|
  c=a.min_by{|i|l[i]}
  while c&&!gone[c]
    sum+=gone[s[c]]?l[c]/2:l[c]
    gone[c]=true
    c=s.index(c)
  end
}
p sum
0