Compare commits
2 Commits
de61542c0b
...
9cd5b1b7f9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cd5b1b7f9 | ||
|
|
638d55d489 |
45
code_study/Baekjoon/python/11779.py
Normal file
45
code_study/Baekjoon/python/11779.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import heapq
|
||||||
|
|
||||||
|
n, m = map(int, [input(), input()])
|
||||||
|
graph = [[] for _ in range(n+1)]
|
||||||
|
|
||||||
|
for _ in range(m) :
|
||||||
|
u, v, w = map(int, input().split())
|
||||||
|
graph[u].append((v,w))
|
||||||
|
|
||||||
|
start, end = map(int, input().split())
|
||||||
|
|
||||||
|
inf = float("inf")
|
||||||
|
distance = [inf for _ in range(n+1)]
|
||||||
|
distance[start] = 0
|
||||||
|
|
||||||
|
prevNode = [0]*(n+1)
|
||||||
|
|
||||||
|
heap = []
|
||||||
|
heapq.heappush(heap, (0, start))
|
||||||
|
|
||||||
|
while len(heap) != 0 :
|
||||||
|
cur_dist, now = heapq.heappop(heap)
|
||||||
|
|
||||||
|
if distance[now] < cur_dist :
|
||||||
|
continue
|
||||||
|
|
||||||
|
for Next in graph[now] :
|
||||||
|
next, nw = Next
|
||||||
|
|
||||||
|
if distance[next] > distance[now] + nw :
|
||||||
|
distance[next] = distance[now] + nw
|
||||||
|
heapq.heappush(heap, (distance[next], next))
|
||||||
|
prevNode[next] = now
|
||||||
|
|
||||||
|
channel = [end]
|
||||||
|
ptr = end
|
||||||
|
while ptr != start :
|
||||||
|
ptr = prevNode[ptr]
|
||||||
|
channel.append(ptr)
|
||||||
|
|
||||||
|
channel.reverse()
|
||||||
|
|
||||||
|
print(distance[end])
|
||||||
|
print(len(channel))
|
||||||
|
print(*channel)
|
||||||
3
code_study/Baekjoon/ts/2558.ts
Normal file
3
code_study/Baekjoon/ts/2558.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export {};
|
||||||
|
const input = require("fs").readFileSync(0).toString().trim().split('\n').map(Number);
|
||||||
|
console.log(input[0]+input[1]);
|
||||||
Loading…
x
Reference in New Issue
Block a user