#!ruby -rtsort class Array include TSort alias tsort_each_node each_index def tsort_each_child(node) yield self[node] end end N=gets.to_i L=[] S=[] N.times.map{ a, b = gets.split.take(2).map(&:to_i) L << a S << b-1 } used = [] p S.strongly_connected_components.map{|a| t = a.min_by{|i|L[i]} n = a.map{|i| if i != t || used[S[i]] L[i]/2.0 else L[i] end }.sum.tap{ a.each{|i| used[i] = true } } }.sum*1.0