Background
Tom is a military recruit for an elite army unit. As the last part of his final exams, he will be put into unknown terrain and has to find his way to a designated exit point, carrying all his heavy military gear.
As Tom is a little bit afraid of this task, he has used Google Maps to obtain satellite images of the training area. He has identified all the possible entry and exit spots and possible connections with their estimated length. This relation between sites does not need to be symmetric due to different terrain heights.
However, he does not know, from which site to which site he will have to march. Unfortunately, he quickly realizes that he won't be able to successfully perform the march in the worst-case of the two sites that have the maximum distance to each other, no matter how hard he practices.
Common sense tells him that his instructors will always pick distinct sites for the entry and exit sites, and he assumes that every pair of distinct sites has equal probability to become his task.
Problem
Given a set of sites, possible connections between some of the sites together with their length and Tom's desired success probability p, you are to compute the minimum distance Tom must be comfortable with so that he will pass his exam with at least probability p, assuming that every pair of distinct sites is equally likely.