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

31320번 - Colonization 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 1024 MB0000.000%

문제

The yoghurt bottle is populated with $N$ bacteria. But bacteria want company, so they form colonies, and this happens in the following way. Initially each bacterium is a colony consisting of itself. While there are at least two colonies in the yoghurt, two nearest colonies are chosen at each step and merged together.

Initially for each pair of bacteria $u$ and $v$ the distance $d_{u,v}$ between them is known. The distance for the colonies $G$ and $H$ is calculated as the average distance between all pairs of bacteria: $$ \frac{ 1 }{|G| \cdot |H|} \sum_{u \in G} \sum_{v \in H} d_{u, v} $$

Bacteria aren't very particular when it comes to accuracy --- you cannot expect too much from single-cell organisms, anyway. So when there are several pairs of colonies with the distance within 10ドル^{-6}$ of the minimal, then any of these pairs can be selected for merging at this step.

You are to model the colony merging process and find one of the possible scenarios.

입력

The first line of the input file contains an integer $N$ -- the number of bacteria (2ドル \leq N \leq 2014$).

The following $N$ lines contain the description of the distance matrix $(d_{i,j})$. Each line contains $N$ characters. The character $d_{i,j}$ in the $j$-th position of the $i$-th line specifies the distance between the $i$-th and $j$-th bacteria.

It is guaranteed that $d_{i,i} = 0,ドル $d_{i, j} = d_{j, i},ドル 0ドル \leq d_{i, j} \leq 9$ for all $i,ドル $j$ = 1,ドル \ldots, N$.

출력

Assign numbers to each initial colony, from 1ドル$ to $N$. The colony obtained on the $i$-th step, $i = 1, \ldots, N-1,ドル will have the number $N + i$.

The input file must contain $N-1$ lines. The $i$-th line must contain three numbers: the numbers of colonies merged on the $i$-th step, and the distance between them with an absolute or relative error not greater than 10ドル^{-6}$ (1ドル \le i \le N-1$).

제한

예제 입력 1

4
0146
1025
4203
6530

예제 출력 1

1 2 1.000000
3 4 3.000000
5 6 4.250000

힌트

출처

Contest > Open Cup > 2014/2015 Season > Stage 2: Grand Prix of Siberia H번

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

출처

대학교 대회

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

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