목차

녹색 옷 입은 애가 젤다지?

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()