{"trustable":false,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eConsider a rooted tree with \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e nodes, numbered \u003cspan class\u003d\"tex2jax_process\"\u003e$1..n$\u003c/span\u003e. Each node will have a fixed integer \u003cspan class\u003d\"tex2jax_process\"\u003e$b$\u003c/span\u003e, and for each, a uniform random real number is chosen in the interval \u003cspan class\u003d\"tex2jax_process\"\u003e$[0..b]$\u003c/span\u003e.\u003c/p\u003e \n\u003cp\u003eWhat is the probability that the random numbers chosen cause the tree to form a \u003ci class\u003d\"itshape\"\u003eHeap\u003c/i\u003e (i.e., the random value in each node is less than the random values in its children)?\u003c/p\u003e \n\u003cp\u003eThis probability can always be expressed as a rational number \u003cspan class\u003d\"tex2jax_process\"\u003e$\\frac{P}{Q}$\u003c/span\u003e, with \u003cspan class\u003d\"tex2jax_process\"\u003e$Q{\\not\\equiv }0 \\pmod{10^9{+}7}$\u003c/span\u003e. You are to output the probability as \u003cspan class\u003d\"tex2jax_process\"\u003e$P{\\cdot }Q^{-1} \\bmod {10^9{+}7}$\u003c/span\u003e, where \u003cspan class\u003d\"tex2jax_process\"\u003e$Q^{-1}$\u003c/span\u003e is an integer, which is the multiplicative inverse of \u003cspan class\u003d\"tex2jax_process\"\u003e$Q$\u003c/span\u003e modulo \u003cspan class\u003d\"tex2jax_process\"\u003e$10^9{+}7$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$Q\\! \\cdot \\! Q^{-1}\\! \\equiv \\! 1 \\pmod{10^9{+}7}$\u003c/span\u003e). (Note: \u003cspan class\u003d\"tex2jax_process\"\u003e$P{\\cdot }Q^{-1}\\bmod {10^9{+}7}$\u003c/span\u003e does not depend on whether \u003cspan class\u003d\"tex2jax_process\"\u003e$P$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$Q$\u003c/span\u003e are relatively prime, only on their ratio \u003cspan class\u003d\"tex2jax_process\"\u003e$\\frac{P}{Q}$\u003c/span\u003e.)\u003c/p\u003e "}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eEach test case will begin with a line with a single integer \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1\\! \\le \\! n\\! \\le \\! 300$\u003c/span\u003e), which is the number of nodes in the tree.\u003c/p\u003e \n\u003cp\u003eEach of the next \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e lines will contain a pair of space-separated integers \u003cspan class\u003d\"tex2jax_process\"\u003e$b$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1\\! \\le \\! b\\! \\le \\! 10^9$\u003c/span\u003e) and \u003cspan class\u003d\"tex2jax_process\"\u003e$p$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$0\\! \\le \\! p\\! \\le \\! n$\u003c/span\u003e) describing a node of the tree, where \u003cspan class\u003d\"tex2jax_process\"\u003e$b$\u003c/span\u003e is the fixed integer value in the node and \u003cspan class\u003d\"tex2jax_process\"\u003e$p$\u003c/span\u003e is the node number of its parent. The nodes are listed in order; node \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e is first, then node \u003cspan class\u003d\"tex2jax_process\"\u003e$2$\u003c/span\u003e, and so on. A single node will have a parent \u003cspan class\u003d\"tex2jax_process\"\u003e$p{\u003d}0$\u003c/span\u003e. This is the root of the tree.\u003c/p\u003e "}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eOutput a single integer, which is the probability expressed as \u003cspan class\u003d\"tex2jax_process\"\u003e$(P{\\cdot }Q^{-1}) \\bmod ({10^9{+}7})$\u003c/span\u003e.\u003c/p\u003e"}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\n1000000000 0\n1000000000 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e500000004\n\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Sample 2","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5\n2 3\n2 3\n1 0\n2 3\n2 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e87500001\n\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}