Post

๐ŸฆŠ ๋“ฑ์‚ฐ์ฝ”์Šค ์ •ํ•˜๊ธฐ

1. ๋ฌธ์ œ ๋งํฌ

๋“ฑ์‚ฐ์ฝ”์Šค ์ •ํ•˜๊ธฐ


2. ์ฝ”๋“œ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from itertools import product

def solution(k, n, reqs):
INF = 2000000000

def solution(n, paths, gates, summits):
    graph = []
    for i in range(n + 1):
        graph.append([])
    summits.sort()

    for i, j, w in paths:
        graph[i].append([j, w])
        graph[j].append([i, w])
    
    intensity = [INF] * (n + 1)
    result = [0, INF]

    q = []
    for gate in gates:
        q.append([0, gate])
        intensity[gate] = 0

    while q:
        current_intensity, current = q.pop(0)
        # ์‚ฐ๋ด‰์šฐ๋ฆฌ ๋˜๋Š” intensity ์˜ ์ตœ์†Œ๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด ํƒ์ƒ‰ ์ข…๋ฃŒ
        if current in summits or current_intensity > intensity[current]:
            continue 
        
    return result
  • ์ •ํ™•์„ฑ


3. ํ•ด์„ค

์žฌ๋„์ „ ํ•„์š”

This post is licensed under CC BY 4.0 by the author.