백준 4343번 Artic Network

문제

The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel.

Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.

Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.


문제풀이

사용한 알고리즘 : MST

(0) 생각

 S개의 위성 채널로는 S-1 개의 기지를 공짜로 연결할 수 있습니다.
 따라서 P-S 개의 통신 경로만 추가로 연결되면 됩니다.

(1) 코드 43~47

 비용이 작은 것이 위로 오게끔 priority_queue를 만들어 각 경로를 저장합니다.

(2) 코드 49~64

 과정(0)의 생각에 따라 P-S개의 경로만 추가되면 됩니다.
 MST를 사용하여 이를 구현합니다.
 비용이 작은 것이 위로 오는 priority_queue를 사용하므로 마지막 비용이 정답입니다.
 (구하고자 하는 답은 모든 기지를 하나의 컴포넌트가 되는데 필요한 최소 비용임을 생각합니다.)


댓글