BOJ - 2219 - 보안 시스템 설치
Updated:
import sys
def solution():
_INF = 1e6
N, M = map(int, sys.stdin.readline().split())
network = [[_INF for _ in range(N)] for _ in range(N)]
check = [[0 for _ in range(N)] for _ in range(N)]
for _ in range(M):
A, B, C = map(int, sys.stdin.readline().split())
network[A-1][B-1] = min(network[A-1][B-1], C)
network[B-1][A-1] = min(network[B-1][A-1], C)
for k in range(N):
for i in range(N):
for j in range(N):
network[i][j] = min(network[i][j], network[i][k] + network[k][j])
result = 0
temp = _INF
for i in range(N):
sumValue = 0
for j in range(N):
if network[i][j] == _INF: break
else: sumValue += network[i][j]
if temp > sumValue:
result = i
temp = sumValue
print(result+1)
solution()
https://www.acmicpc.net/problem/2219
Leave a comment