Optimization of detection networks. II. Tree structures