ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 4485 |
문제명 | 녹색 옷 입은 애가 젤다지? |
레벨 | 골드 4 |
분류 |
다익스트라 |
시간복잡도 | O(t*n^2logn) |
인풋사이즈 | t<=?, n<=125 |
사용한 언어 | Python |
제출기록 | 42256KB, 188ms |
최고기록 | 120ms |
해결날짜 | 2022/09/19 |
"""Solution code for "BOJ 4485. 녹색 옷 입은 애가 젤다지?".
- Problem link: https://www.acmicpc.net/problem/4485
- Solution link: http://www.teferi.net/ps/problems/boj/4485
Tags: [Dijkstra]
"""
import itertools
import sys
from teflib import graph as tgraph
def main():
for prob_no in itertools.count(start=1):
n = int(sys.stdin.readline())
if n == 0:
break
grid = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)
]
grid_arr = list(itertools.chain.from_iterable(grid))
wgraph = [
{v: grid_arr[v] for v in adj_u} for adj_u in tgraph.GridGraph(n, n)
]
source, dest = 0, n * n - 1
costs = tgraph.dijkstra(wgraph, source, dest=dest)
cost_to_dest = grid_arr[0] + costs[dest]
print('Problem {}: {}'.format(prob_no, cost_to_dest))
if __name__ == '__main__':
main()