Optimal risk allocation in reinsurance networks