Skip to content

Commit 4f2f8f8

Browse files
committed
면접보는 승범이네 풀이
1 parent 88accd9 commit 4f2f8f8

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# 그래프 이론, 최단 경로, 데이크스트라
2+
# https://www.acmicpc.net/problem/17835
3+
4+
"""
5+
6 10 2
6+
2 6 2
7+
1 4 1
8+
6 1 5
9+
2 5 1
10+
5 1 4
11+
4 5 6
12+
6 2 3
13+
3 5 1
14+
3 1 1
15+
5 2 2
16+
1 2
17+
"""
18+
19+
input = __import__("sys").stdin.readline
20+
N,M,K = map(int, input().split()) # 도시, 도로, 면접장
21+
graph = [[] for _ in range(N+1)]
22+
23+
for _ in range(M):
24+
a,b,c = map(int, input().split())
25+
graph[b].append((a,c))
26+
27+
hires = set(map(int, input().split()))
28+
INF = int(1e11)
29+
30+
def dijkstra(starts):
31+
import heapq
32+
33+
global far_city, far_cost
34+
35+
dist = [INF] * (N+1)
36+
heap = []
37+
for start in starts:
38+
heapq.heappush(heap, (0, start))
39+
dist[start] = 0
40+
41+
while heap:
42+
cost, node = heapq.heappop(heap)
43+
44+
if dist[node] < cost: continue
45+
46+
for nxt_node, nxt_cost in graph[node]:
47+
sum_cost = dist[node] + nxt_cost
48+
49+
if sum_cost >= dist[nxt_node]:
50+
continue
51+
52+
dist[nxt_node] = sum_cost
53+
heapq.heappush(heap, (sum_cost, nxt_node))
54+
55+
return dist
56+
57+
58+
dist = dijkstra(hires)
59+
60+
far_city = N+1
61+
far_cost = 0
62+
63+
for city in range(1, N+1):
64+
if city in hires:
65+
continue
66+
if far_cost < dist[city] and dist[city] != INF:
67+
far_city = city
68+
far_cost = dist[city]
69+
70+
print(f"{far_city}\n{far_cost}")

0 commit comments

Comments
 (0)