The court shall have the power to assess the cost of a hearing held pursuant to the terms of this division, including the fee of the guardian ad litem, to the plaintiffs; provided, that should some of the defendants file counterclaims or should certain persons intervene, the cost shall be assessed by the court as justice may require.