ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 9373 |
문제명 | 복도 뚫기 |
레벨 | 플래티넘 2 |
분류 |
MST |
시간복잡도 | O(T*V^2) |
인풋사이즈 | T<=100, V<=1000 |
사용한 언어 | Python |
제출기록 | 32952KB / 4108ms |
최고기록 | 4108ms |
해결날짜 | 2022/10/14 |
태그 |
"""Solution code for "BOJ 9373. 복도 뚫기".
- Problem link: https://www.acmicpc.net/problem/9373
- Solution link: http://www.teferi.net/ps/problems/boj/9373
"""
import sys
import math
def main():
T = int(sys.stdin.readline())
for _ in range(T):
w = int(sys.stdin.readline())
n = int(sys.stdin.readline())
censors = [
[int(x) for x in sys.stdin.readline().split()] for _ in range(n)
]
if n == 0:
print(w / 2)
continue
dists = {i: max(0, x - r) for i, (x, y, r) in enumerate(censors)}
closest_node = min(range(n), key=dists.__getitem__)
dist_to_right = w
answer = dists[closest_node] / 2
while closest_node is not None:
u_x, u_y, u_r = censors[closest_node]
del dists[closest_node]
dist_to_right = min(dist_to_right, max(0, w - u_x - u_r))
closest_node, min_dist = None, dist_to_right
for v, dist_v in dists.items():
v_x, v_y, v_r = censors[v]
d = max(0, math.dist((u_x, u_y), (v_x, v_y)) - (u_r + v_r))
if d < dist_v:
dist_v = dists[v] = d
if dist_v < min_dist:
closest_node, min_dist = v, dist_v
answer = max(answer, min_dist / 2)
print(answer if answer > 0 else '0')
if __name__ == '__main__':
main()