Skip to content

Commit

Permalink
1956 Floyd-Washall, Programmers implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrevile committed Jan 4, 2022
1 parent 53306cd commit c51f39e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
55 changes: 55 additions & 0 deletions BOJ PS/No.1956 운동.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import sys
import heapq
# 운동 경로를 찾는 것이 불가능한 경우에는 -1을 출력한다.
MAX = sys.maxsize
V,E = map(int,sys.stdin.readline().split(" "))

graph = {}
DP = [[MAX]*V for i in range(V)]
for i in range(1,V+1):
graph[i] = {}
for i in range(E):
a,b,c = map(int,sys.stdin.readline().split(" "))
graph[a][b] = c
DP[a-1][b-1] = c


def Dijkstra(start):
queue = []
distance = {}
for i in range(1,V+1):
distance[i] = MAX
distance[start] = 0
heapq.heappush(queue,[distance[start],start])

while queue:
current_distance,current_node = heapq.heappop(queue)

if current_distance > distance[current_node]:
continue;

for next_node,next_distance in graph[current_node].items():
temp_distance = next_distance + distance[current_node]
if temp_distance < distance[next_node]:
heapq.heappush(queue,[temp_distance,next_node])
distance[next_node] = temp_distance
return distance



for i in range(V):
for j in range(V):
for k in range(V):
if DP[j][k] > DP[j][i] + DP[i][k]:
DP[j][k] = DP[j][i] + DP[i][k]

MIN = MAX
for i in range(V):
if MIN > DP[i][i]:
MIN = DP[i][i]


if MIN > MAX:
print(-1)
else:
print(MIN)
11 changes: 11 additions & 0 deletions Programmers/124 나라의 숫자.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def solution(n):
digit = {1: "1", 2: "2", 0: "4"}
answer = ''
while n > 0:
mod = n % 3
n = n // 3
answer = digit[mod] + answer
if mod == 0:
n -= 1

return answer

0 comments on commit c51f39e

Please sign in to comment.