Skip to content

Commit

Permalink
2024-07-12
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Jul 12, 2024
1 parent bafecdf commit 815d1ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@
| 60차시 | 2024.06.07 | 그리디 | <a href="https://www.acmicpc.net/problem/14939">불 끄기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/209
| 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
| 64차시 | 2024.07.12 | 최소 공통 조상 | <a href="https://www.acmicpc.net/problem/11812">K진 트리</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/217
---
24 changes: 24 additions & 0 deletions tgyuuAn/최소 공통 조상/K진 트리.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys

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

N, K, Q = map(int,input().split())

for _ in range(Q):
start, dest = map(int, input().split())
answer = 0

if K == 1:
print(abs(start - dest))
continue

while start != dest:
if start > dest:
start = (start-2)//K+1
answer += 1

if dest > start:
dest = (dest-2)//K+1
answer += 1

print(answer)

0 comments on commit 815d1ac

Please sign in to comment.