import scala.io.StdIn._



object Main extends App {
  var n = readInt()
  while (n != 0) {
    val parents = readLine.trim.split(' ').map(_.toInt - 1)
    val lengths = readLine.trim.split(' ').map(_.toInt)
    val allRemove = lengths.sum
    if (n == 2) {
      println(allRemove)
    }else {
      val islands = Array.fill(n) {
        Nil: List[Bridge]
      }
      for (i ← parents.indices) {
        islands(i + 1) ::= Bridge(parents(i), lengths(i))
        islands(parents(i)) ::= Bridge(i + 1, lengths(i))
      }
      val isLeaf = islands.map {
        _.lengthCompare(1) == 0
      }
      val minLength = Array.fill(n) {
        Int.MaxValue
      }

      def setMax(current: Int, len: Int = 0): Unit = {
        if (minLength(current) > len) {
          minLength(current) = len
          for (Bridge(next, length) ← islands(current)) {
            setMax(next, len + length)
          }
        }
      }

      setMax(0)
      val start = islands.indices.filterNot(isLeaf).maxBy(minLength)
      minLength.indices.foreach(i ⇒ minLength(i) = Int.MaxValue)
      setMax(start)
      val doubleMove = islands.indices.map { i ⇒ if (isLeaf(i)) 0 else islands(i).filterNot(e ⇒ isLeaf(e.to)).map(_.length).sum }.sum
      val singleMove = islands.indices.filterNot(isLeaf).map(minLength).max
      println(allRemove + doubleMove - singleMove)
    }
    n = readInt()
  }

  case class Bridge(to: Int, length: Int)

}
