Colonization
시간 제한4초메모리 제한1024 MB
두 집단 사이의 평균 거리가 가장 작은 두 집단을 반복해서 합치고, 그 합병 순서와 거리를 출력한다.
문제
The yoghurt bottle is populated with 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 and the distance between them is known. The distance for the colonies and is calculated as the average distance between all pairs of bacteria:
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 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 -- the number of bacteria ().
The following lines contain the description of the distance matrix . Each line contains characters. The character in the -th position of the -th line specifies the distance between the -th and -th bacteria.
It is guaranteed that , , for all , = .
출력
Assign numbers to each initial colony, from to . The colony obtained on the -th step, , will have the number .
The input file must contain lines. The -th line must contain three numbers: the numbers of colonies merged on the -th step, and the distance between them with an absolute or relative error not greater than ().