eolymp
bolt
Try our new interface for solving problems
Problems

Map Generator

Map Generator

The scene of the new computer game "Battles in Space: Unification" (\textit{BSU}) is laid in far future. Mankind is scattered on \textbf{N} planets hostile to each other. A player of the game is a leader of one the planets. Using diplomatic tricks and military the player needs to occupy the rest of the planets and, doing so, reunite mankind. Special \textit{hyperspace tunnels} are used to travel from one planet to another. Each tunnel connects two of the planets and can be used for communication in both directions. Two planets \textbf{can not} be connected by more then one tunnel. The set of all tunnels connecting the planets is called the \textit{map of the game}. Currently, developers of \textit{BSU} are working on generator of maps of the game. It has been decided to use the special algorithm called "Fine Artificial Model of Intelligence" (\textit{FAMI}) for this purpose. The algorithm operates in the following way. For each pair of planets \textbf{i} и \textbf{j} (\textbf{1} ≤ \textbf{i} < \textbf{j} ≤ \textbf{N}) a random real number \textbf{X_ij} (\textbf{0} ≤ \textbf{X_ij} ≤ \textbf{1}) is generated. Uniform distribution is used to generate random numbers and numbers \textbf{X_ij} are generated independently. Next, if \textbf{X_ij} ≤ \textbf{P}, where parameter \textbf{P} is a real number, then the hyperspace tunnel connecting planets \textbf{i} and \textbf{j} is added into the map being generated. Developers wish the map generator produced \textit{connected} maps. A map is said to be \textit{connected} when between any pair of planets there is a path, consisting of one or more hyperspace tunnels. Unfortunately, it appears that maps generated by \textit{FAMI} algorithm sometimes are not \textit{connected}. You are assigned to research this phenomenon. You need to write a program which being given numbers \textbf{N} and \textbf{P} calculates probability of generating \textit{connected} map by \textit{FAMI} algorithm. \InputFile Input file consists of two lines. The first line contains an integer number \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{20}), while the second line contains a real number \textbf{P} (\textbf{0} ≤ \textbf{P} ≤ \textbf{1}). \OutputFile Output file needs to contain an answer - the single real number which is the probability of generating \textit{connected} map by \textit{FAMI} algorithm. Absolute error of the answer must not exceed \textbf{10^\{-2\}}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3
0.5
Output example #1
0.500000000000000
Source ACM Programming Contest 2005, Minsk, October 2005