### constant

INF = 1 << 30

### subroutines

def roundtrip(from, to)
  #p ["roundtrip", from, to]
  if $rtcache[from][to]
    #p ["  roundtrip", from, to, $rtcache[from][to]]
    return $rtcache[from][to]
  end

  tr = $edges[from][to] * 3 + $wghts[to]
  for v in $nbrs[to]
    if v != from
      tr += roundtrip(to, v)
    end
  end
  #p ["  roundtrip", from, to, tr]
  $rtcache[from][to] = tr
end

def oneway(from, to)
  nbrs0 = $nbrs[to].select{|nbr| nbr != from}
  #p ["oneway", from, to, nbrs0]

  ow = $edges[from][to] * 2 + $wghts[to]
  if nbrs0.empty?
    return ow
  end

  min_t = INF

  for v in nbrs0
    t = ow + oneway(to, v)
    nbrs0.each{|v0| t += (v0 == v) ? 0 : roundtrip(to, v0)}
    min_t = t if min_t > t
  end

  #p ["  oneway", from, to, min_t]
  min_t
end

### main

loop do
  $n = gets.to_i
  break if $n == 0

  ps = [nil] + gets.split.map(&:to_i)
  ds = [nil] + gets.split.map(&:to_i)
  
  $edges = $n.times.map{$n.times.map{nil}}
  $wghts = $n.times.map{0}
  $nbrs = $n.times.map{[]}

  for i in (1...$n)
    j = ps[i] - 1
    $edges[i][j] = $edges[j][i] = ds[i]
    $nbrs[i] << j
    $nbrs[j] << i
  end

  for i in (0...$n)
    if $nbrs[i].length == 1 && $wghts[i] == 0
      j = $nbrs[i].first
      $wghts[j] += $edges[i][j]
      $nbrs[i] = []
      $nbrs[j].delete(i)
      $edges[i][j] = $edges[j][i] = nil
    end
  end
  #p $edges
  #p $wghts
  #p $nbrs

  terms = (0...$n).select{|i| $nbrs[i].length == 1}
  nterms = terms.length
  #p terms

  min_t = INF
  
  if nterms == 0
    min_t = $wghts.max
  else
    $rtcache = $n.times.map{$n.times.map{nil}}
    for from in terms
      t = $wghts[from] + oneway(from, $nbrs[from].first)
      min_t = t if min_t > t
    end
  end

  puts min_t
end