-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9c942e
commit 3196566
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def solution(n): | ||
arr = [] | ||
for i in range(n+1): | ||
if i == 0: | ||
arr.append(i) | ||
elif i == 1: | ||
arr.append(i) | ||
else: | ||
arr.append(arr[i-1]+arr[i-2]) | ||
return arr[n] % 1234567 | ||
|
||
|
||
if __name__ == '__main__': | ||
real_answer = solution(5) | ||
print(real_answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import sys | ||
from heapq import heappush, heappop | ||
|
||
input = sys.stdin.readline | ||
N = int(input()) | ||
M = int(input()) | ||
graph = [[] for _ in range(N + 1)] | ||
for i in range(M): | ||
a, b, c = map(int, input().split()) | ||
graph[a].append((b, c)) | ||
s, e = map(int, input().split()) | ||
|
||
|
||
def dijkstra(start, end): | ||
heap = [] | ||
heappush(heap, (0, start)) # 시작 지점 힙에 추가 | ||
distance = [sys.maxsize] * (N+1) # 각 정점사이의 거리 무한대로 초기화 | ||
distance[start] = 0 # 시작 지점 0으로 초기화 | ||
while heap: | ||
weight, index = heappop(heap) | ||
for e, c in graph[index]: | ||
if distance[e] > weight + c: | ||
distance[e] = weight + c | ||
heappush(heap, (weight+c, e)) | ||
print(distance) | ||
return distance[end] | ||
|
||
|
||
print(dijkstra(s, e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import sys | ||
import heapq | ||
|
||
input = sys.stdin.readline | ||
N = int(input()) | ||
M = int(input()) | ||
graph = [[] for _ in range(N+1)] | ||
for i in range(M): | ||
a, b, c = map(int, input().split()) | ||
graph[a].append((b, c)) | ||
s, e = map(int, input().split()) | ||
|
||
|
||
def dijkstra(start, end): | ||
heap = [] | ||
heapq.heappush(heap, (0, start)) | ||
distance = [sys.maxsize] * (N+1) | ||
distance[start] = 0 | ||
while heap: | ||
weight, index = heapq.heappop(heap) | ||
for n, w in graph[index]: | ||
if distance[n] > weight + w: | ||
distance[n] = weight + w | ||
heapq.heappush(heap, (weight+w, n)) | ||
return distance[end] | ||
|
||
|
||
print(dijkstra(s, e)) |