The problem with this solution is that I have to recompute Binomial cdf for every node (and this cannot be made faster than O(n) since this cdf is of length n). This gives us O(n) sampling for each node.