import sys
sys.stdin = open('input.txt')
input = sys.stdin.readline
from heapq import heappop, heappush
def dijkstra(q):
while q:
val, node = heappop(q)
if dist[node] < val:
continue
for next_node, next_val in graph[node]:
temp = val+next_val
if dist[next_node] > temp:
dist[next_node] = temp
heappush(q, [temp, next_node])
N = int(input())
lives = list(map(int, input().split()))
lives = set(lives)
M = int(input())
graph = [[] for _ in range(N+1)]
for _ in range(M):
a, b, c = map(int, input().split())
graph[a].append((b, c))
graph[b].append((a, c))
dist = [float('inf')] * (N+1)
dist[0] = 0
q = []
for i in lives:
dist[i] = 0
heappush(q, [0, i])
dijkstra(q)
result, temp = 0, 0
for idx, v in enumerate(dist):
if v > result:
result = v
temp = idx
print(temp)
'ALGORITHM > 다익스트라, 벨만포드, 플로이드워셜' 카테고리의 다른 글
[백준 2665번] 파이썬 - 미로 만들기 (0) | 2023.11.12 |
---|---|
[백준 1939번] 파이썬 - 중량제한 (1) | 2023.10.28 |
[백준 17368번] 파이썬 - 백도어 (0) | 2023.10.11 |
[백준 20183번] 파이썬 - 골목 대장 호석 - 효율성 2 (1) | 2023.10.04 |
[백준 1445번] 파이썬 - 일요일 아침의 데이트 (1) | 2023.10.02 |