Exact Inference on Hierarchical Clustering in Particle Physics and Cancer Genomics