ces Help                                                            
class Tree
  attr_accessor :root, :childs, :cost,:id
  def initialize id,root,cost
    @id = id
    @root = root
    @cost = cost
    @childs = []
  end
  def set_child node
    @childs << node
    node.root = self
  end
end
def getalltime root
  sum = 0
  return sum if root.childs.size == 0
  root.childs.each do |node|
    sum += getalltime node
  end
  return (sum+root.cost)
end
def getgreatertime root,count,greater
    return count > greater ? count : greater if root.childs.size == 0
    count += root.cost
    root.childs.each do |node|
       greater = getgreatertime node,count,greater
    end
    return greater
end
until (n = gets.chomp.to_i) == 0
  tree = Array.new
  tree[1]  = Tree.new(1,nil,0)
  (n-1).times do
    root,id,cost = gets.chomp.split.map!(&:to_i)
    tree[id]  = Tree.new(id,nil,cost)
    tree[root].set_child tree[id]
  end
  p (getalltime tree[1])*2 - (getgreatertime tree[1],0,0)
end