require "tsort" class Array include TSort alias tsort_each_node each def tsort_each_child(node) yield self[node] end end n=gets.to_i l,s=([[0,0]]+$<.map{|l|l.split.map(&:to_i)}).transpose ans=l.inject(:+)/2.0 gone=[] s.each_strongly_connected_component{|a| t=a.min_by{|i|l[i]} ans+=l[t]/2.0 unless gone[s[t]] a.map{|i|gone[i]=1} } p ans