def get_weight_kids(tree, node, weights):
	"""
	Computes the weight (i.e the number of direct and indirect dependents) for each node.
	
	Recursive function called inside optimal_linearization.

	Parameters
	----------
	tree : Tree
		a dependency Tree in dict format
	node : dict
		the dict corresponding to the current root node
	weights : dict
		the dict updated with each node's weight

	Returns
	-------
	weights : dict
		the dict updated with each node's weight
	"""
	kids = node.get("kids").keys()
	weights[node["id"]] = 0
	if not kids:
		return weights
	for k in kids:
		weights[node["id"]] +=1
		weights = get_weight_kids(tree, tree[k], weights)
		weights[node["id"]] += weights[k]
	return weights