Logo
(追記) (追記ここまで)

21384번 - Average distance 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB43262261.111%

문제

Given a tree, calculate the average distance between two vertices in the tree. For example, the average distance between two vertices in the following tree is (d01 + d02 + d03 + d04 + d12 + d13 + d14 + d23 + d24 + d34)/10 = (6 + 3 + 7 + 9 + 9 + 13 + 15 + 10 + 12 + 2)/10 = 8.6.

Figure 1: The first sample case

입력

On the first line an integer t (1 ≤ t ≤ 100): the number of test cases. Then for each test case:

  • One line with an integer n (2 ≤ n ≤ 10 000): the number of nodes in the tree. The nodes are numbered from 0 to n − 1.
  • n − 1 lines, each with three integers a (0 ≤ a < n), b (0 ≤ b < n) and d (1 ≤ d ≤ 1 000). There is an edge between the nodes with numbers a and b of length d. The resulting graph will be a tree.

출력

For each testcase:

  • One line with the average distance between two vertices. This value should have either an absolute or a relative error of at most 10−6.

제한

예제 입력 1

1
5
0 1 6
0 2 3
0 3 7
3 4 2

예제 출력 1

8.6

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2007 A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /