private void computeWeights(Node node){
  int wsum=0;
  for (  Node child : node.children) {
    computeWeights(child);
    wsum+=child.weight;
  }
  node.weight=Math.max(1,wsum);
}

private void computeWeights ( Node node ) { int wsum = 0 ; for ( Node child : node . children ) { computeWeights ( child ) ; wsum += child . weight ; } node . weight = Math . max ( 1 , wsum ) ; }
recursively assign node weights .
