Cascade Centrality

시간 제한1초메모리 제한1024 MB

요약
트리가 주어질 때, 모든 단순 경로에서 각 노드의 차수 곱의 역수를 더한 중심성 값의 평균을 구한다.
난이도

보통10점 중 5점

유형
트리, DFS, 수학, 동적 계획법
정답자
아직 제출이 없습니다

문제

Given an undirected graph G=(V,E)G=(V,E), the cascade centrality of node ii in VV is defined to be: 1+∑_j∈V∖i∑_P∈P_ij1χ_P,1 + \sum\_{j \in V \setminus \\{i\\}} \sum\_{P \in P\_{ij}} \frac{1}{\chi\_P}, where P_ijP\_{ij} is the set of all simple paths from node ii to node jj, and the degree sequence product χ_P\chi\_P of a path is the product of the degrees of all nodes along the path, including the ending node but excluding the starting node.

In this problem, GG is a tree, so that P_ijP\_{ij} always contains exactly one path. Find the mean of the cascade centralities of the nodes in GG.

입력

The first line of input consists of an integer NN (1≤N≤100)(1 \leq N \leq 100), the number of nodes in the tree.

The remaining N−1N-1 lines each contains two space-separated integers u_iu\_i and v_iv\_i (1≤u_i,v_i≤N)(1 \leq u\_i, v\_i \leq N), denoting an undirected edge from node u_iu\_i to node v_iv\_i. No edge connects a node to itself, and there is at most one edge between any pair of nodes.

The given graph is a tree: it is connected and does not contain a cycle.

출력

Print the mean of the cascade centralities of the nodes in the input graph. Your solution will be judged correct if it differs from the judge solution by at most 10−610^{-6} relative or absolute error.

예제3

  1. 예제 1

    입력
    1
    
    예상 출력
    1.000000
    
  2. 예제 2

    입력
    2
    1 2
    
    예상 출력
    2.000000
    
  3. 예제 3

    입력
    3
    1 3
    3 2
    
    예상 출력
    2.333333