Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

85-tgyuuAn #264

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading