Cascade Centrality
InterviewTime limit1sMemory limit1024 MB
Given a tree, find the mean cascade centrality of its nodes, where each path adds the reciprocal of the product of degrees along it.
Problem
Given an undirected graph , the cascade centrality of node in is defined as where is the set of all simple paths from node to node . The degree sequence product of a path is the product of the degrees of all nodes along the path, including the ending node but excluding the starting node.
Since is a tree, always contains exactly one path. Find the mean of the cascade centralities of the nodes in .
Input
The first line contains an integer , the number of nodes in the tree. Each of the next lines contains two space-separated integers and , denoting an undirected edge between nodes and . No edge connects a node to itself, and there is at most one edge between any pair of nodes. The given graph is connected and has no cycles.
Output
Print the mean of the cascade centralities of the nodes in the graph. Your answer is accepted if it differs from the judge answer by at most in relative or absolute error.