λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
πŸƒ algorithm/boj

BOJ 11265 - λλ‚˜μ§€ μ•ŠλŠ” νŒŒν‹°

by HandHand 2021. 6. 4.

문제

λ°±μ€€ 온라인 저지 - 11265번

풀이 κ³Όμ •

κ·Έλž˜ν”„κ°€ μ£Όμ–΄μ‘Œμ„ λ•Œ, μ΅œμ†Œ μ‹œκ°„μœΌλ‘œ 각 μ§€μ κ°„μ˜ 이동 λΉ„μš©μ„ κ΅¬ν•œ λ’€ μ œν•œ μ‹œκ°„λ‚΄μ— 도달 κ°€λŠ₯성을 νŒλ‹¨ν•˜λŠ” λ¬Έμ œμž…λ‹ˆλ‹€.
ν”Œλ‘œμ΄λ“œ 와샬 μ•Œκ³ λ¦¬μ¦˜ 을 μ‚¬μš©ν•΄μ„œ λͺ¨λ“  μ •μ κ°„μ˜ μ΅œμ†Œ λΉ„μš©μ„ κ΅¬ν•œ λ’€ μ‹œμž‘ 지점과 도착 지점을 ν™œμš©ν•΄μ„œ 닡을 ꡬ할 수 μžˆμŠ΅λ‹ˆλ‹€.

μ½”λ“œ


import sys


def floyd(graph):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])


def solution(current_party, next_party, remaining_time):
    is_possible = graph[current_party - 1][next_party - 1] <= remaining_time

    return 'Enjoy other party' if is_possible else 'Stay here'


if __name__ == '__main__':
    N, M = list(map(int, sys.stdin.readline().split()))
    graph = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
    participants = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

    floyd(graph)

    for participant in participants:
        answer = solution(*participant)
        print(answer)
λ°˜μ‘ν˜•

'πŸƒ algorithm > boj' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

BOJ 5980 - Corn Maze  (0) 2021.06.07
BOJ 1240 - λ…Έλ“œμ‚¬μ΄μ˜ 거리  (0) 2021.06.07
BOJ 10472 - μ‹­μžλ’€μ§‘κΈ°  (0) 2021.04.18
BOJ 13908 - λΉ„λ°€λ²ˆν˜Έ  (0) 2021.04.13
BOJ 14940 - μ‰¬μš΄ μ΅œλ‹¨κ±°λ¦¬  (0) 2021.04.13

πŸ’¬ λŒ“κΈ€