Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Dreamhack
- redux state값 유지
- 꿀팁 환영
- 코딩테스트
- 블로그 뉴비
- Redux
- 티스토리챌린지
- 프로그래머스
- 새로고침
- React
- web-view
- 드림핵
- python
- API 활용 신청
- 훈수 가능
- 사업계획서
- 부산 맛집 OPEN API
- react-router-dom
- url 랜더링
- php-1
- 공공데이터 포털
- level3
- apk 빌드
- 고고학 최고의 발견
- 창업 300
- 오블완
- 보안
- 개발
- expo
Archives
- Today
- Total
1223v
[BOJ] Python 백준 해킹(10282) 본문
https://www.acmicpc.net/problem/10282
기본적인 다익스트라 알고리즘 문제이다.
import sys
input = sys.stdin.readline
import heapq
def dijkstra(graph, start):
time = [int(1e9)] * (N+1)
time[start] = 0
hq = []
heapq.heappush(hq,(0,start))
while hq:
c_time, c_com = heapq.heappush(hq)
for s, a in graph[c_com]:
if c_time+s < time[a]:
time[a] = c_time+s
heapq.heappush(hq,(c_time+s,a))
count, endTime = 0,0
for t in time:
if t < int(1e9):
count += 1
if t > endTime:
endTime = t
return count, endTime
TC = int(input())
for _ in range(TC):
N, D, C = map(int,input().split())
graph = [[] for _ in range(N+1)]
for _ in range(D):
a, b, s = map(int,input().split())
graph[b].append((s,a))
count, endTime = dijkstra(graph, C)
print(count, endTime)
회고,
기본에 충실한 다익스트라 문제로 다시금 개념을 잡는데 도움이 되어 좋았다. ㅎㅎ
728x90
'PS' 카테고리의 다른 글
[BOJ] Python 백준 타임머신(11657) (0) | 2025.01.13 |
---|---|
[BOJ] Python 백준 침투(13565) (1) | 2024.12.18 |
[BOJ] Python 백준 가장 긴 바이토닉 부분 수열(11054) (1) | 2024.11.28 |
[BOJ] Python 백준 줄세우기(2631) (0) | 2024.11.28 |
[BOJ] Python 백준 상자넣기(1965) (0) | 2024.11.26 |