| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 4343 |
| 문제명 | Arctic Network |
| 레벨 | 골드 3 |
| 분류 |
최소 신장 트리 |
| 시간복잡도 | O(n^2) |
| 인풋사이즈 | n<=500 |
| 사용한 언어 | Python |
| 제출기록 | 32952KB / 284ms |
| 최고기록 | 284ms |
| 해결날짜 | 2022/10/02 |
| 태그 | |
"""Solution code for "BOJ 4343. Arctic Network".
- Problem link: https://www.acmicpc.net/problem/4343
- Solution link: http://www.teferi.net/ps/problems/boj/4343
Tags: [Minimum spanning tree]
"""
import math
import sys
from teflib import graph as tgraph
def main():
N = int(sys.stdin.readline())
for _ in range(N):
S, P = [int(x) for x in sys.stdin.readline().split()]
coords = [
[int(x) for x in sys.stdin.readline().split()] for _ in range(P)
]
mat_graph = tgraph.create_mat_graph(
P, lambda u, v: math.dist(coords[u], coords[v]))
mst_edges = tgraph.minimum_spanning_tree_dense(mat_graph)
answer = mst_edges[-S][2]
print(f'{answer:.2f}')
if __name__ == '__main__':
main()