Skip to content

Commit

Permalink
2025-01-09
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Jan 16, 2025
1 parent d39d389 commit a1d6859
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
3 changes: 1 addition & 2 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@
| 61์ฐจ์‹œ | 2024.06.20 | ํฌ๋ฃจ์Šค์นผ | <a href="https://www.acmicpc.net/problem/1774">์šฐ์ฃผ์‹ ๊ณผ์˜ ๊ต๊ฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/212
| 62์ฐจ์‹œ | 2024.07.01 | DP | <a href="https://www.acmicpc.net/problem/1949">์šฐ์ˆ˜ ๋งˆ์„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/214
| 63์ฐจ์‹œ | 2024.07.08 | BFS | <a href="https://www.acmicpc.net/problem/3108">๋กœ๊ณ </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/216
| 62์ฐจ์‹œ | 2024.07.01 | DP | <a href="https://www.acmicpc.net/problem/1949">์šฐ์ˆ˜ ๋งˆ์„</a> | https://github.com/AlgoLeadMe/AlgoLeadMse-1/pull/214
| 63์ฐจ์‹œ | 2024.07.08 | BFS | <a href="https://www.acmicpc.net/problem/3108">๋กœ๊ณ </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/216
| 64์ฐจ์‹œ | 2024.07.12 | ์ตœ์†Œ ๊ณตํ†ต ์กฐ์ƒ | <a href="https://www.acmicpc.net/problem/11812">K์ง„ ํŠธ๋ฆฌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/217
| 65์ฐจ์‹œ | 2024.07.19 | ์ตœ์†Œ ๊ณตํ†ต ์กฐ์ƒ | <a href="https://www.acmicpc.net/problem/3584">๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๊ณตํ†ต ์กฐ์ƒ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/220
| 66์ฐจ์‹œ | 2024.07.22 | DP | <a href="https://www.acmicpc.net/problem/2169">๋กœ๋ด‡ ์กฐ์ข…ํ•˜๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/222
Expand All @@ -88,4 +86,5 @@
| 82์ฐจ์‹œ | 2024.11.22 | ํฌ์†Œ ๋ฐฐ์—ด | <a href="https://www.acmicpc.net/problem/17435">ํ•ฉ์„ฑํ•จ์ˆ˜์™€ ์ฟผ๋ฆฌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/257
| 83์ฐจ์‹œ | 2024.12.01 | ์ˆ˜ํ•™ + ๊ตฌํ˜„ | <a href="https://www.acmicpc.net/problem/1033">์นตํ…Œ์ผ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/259
| 84์ฐจ์‹œ | 2024.12.31 | BFS | <a href="https://www.acmicpc.net/problem/4179">๋ถˆ!</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/261
| 85์ฐจ์‹œ | 2025.01.09 | ๋‹ค์ต์ŠคํŠธ๋ผ + ์ด๋ถ„ ํƒ์ƒ‰ | <a href="https://www.acmicpc.net/problem/1800">์ธํ„ฐ๋„ท ์„ค์น˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/264
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import sys
from heapq import *

def input(): return sys.stdin.readline().rstrip()

N, P, K = map(int, input().split())
graph = [[int(1e9) for _ in range(N+1)] for _ in range(N+1)]

for _ in range(P):
start, destination, cost = map(int, input().split())
graph[start][destination] = min(graph[start][destination], cost)
graph[destination][start] = min(graph[destination][start], cost)

def check(mid):
if dijkstra(mid): return True
return False

def dijkstra(_max):
visited = set()
DP = [[int(1e9) for _ in range(K+1)] for _ in range(N+1)]
DP[1][K] = 0

# ๊ฐ„์„  ์ฝ”์ŠคํŠธ, ๋‚จ์€ ๊ธฐํšŒ, ํ˜„์žฌ ๋…ธ๋“œ
heap = [(0, K, 1)]
while heap:
now_cost, now_remain, now_node = heappop(heap)

if (now_node, now_remain) in visited: continue
visited.add((now_node, now_remain))

if DP[now_node][now_remain] < now_cost: continue
DP[now_node][now_remain] = now_cost

if now_node == N:
return True

for idx, cost in enumerate(graph[now_node]):
if idx == 0: continue
if cost == int(1e9): continue

if cost <= _max:
if (idx, now_remain) in visited: continue
if DP[idx][now_remain] > cost: heappush(heap, (cost, now_remain, idx))

elif cost > _max and now_remain >= 1:
if (idx, now_remain-1) in visited: continue
if DP[idx][now_remain-1] > cost: heappush(heap, (cost, now_remain-1, idx))

for idx in range(1, K+1):
if DP[N][idx] != int(1e9): return True

return False

answer = int(1e9)
left = -1
right = 1_000_001
while left+1<right:
mid = (left + right) // 2

if check(mid):
right = mid
answer = mid
else: left = mid

if answer != int(1e9): print(answer)
else: print(-1)

0 comments on commit a1d6859

Please sign in to comment.