Skip to content

Commit

Permalink
Merge branch 'main' into 72-tgyuuAn
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn authored Sep 2, 2024
2 parents 6855b04 + 972724c commit 0f57352
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 3 deletions.
38 changes: 38 additions & 0 deletions H0ngJu/DFS/์นœ๊ตฌ๋น„.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys
from collections import deque, defaultdict

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

N, M, k = map(int, input().split())
friend_money = list(map(int, input().split()))
relation = defaultdict(set)
visited = [0] * N
total = 0

for _ in range(M):
a, b = map(int, input().split())
relation[a-1].add(b-1)
relation[b-1].add(a-1)

for i in range(N):
if not visited[i]:
visited[i] = True
friends = []
q = deque([i])

while q:
f = q.popleft()
friends.append(f)
for p in relation[f]:
if not visited[p]:
visited[p] = True
q.append(p)

if friends:
cost = min(friend_money[friend] for friend in friends)
total += cost

if total <= k:
print(total)
else:
print("Oh no")
2 changes: 2 additions & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
| 22์ฐจ์‹œ | 2024.08.06 | ํ•ด์‹œ | [์˜์ƒ](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/224 |
| 23์ฐจ์‹œ | 2024.08.10 | ํ•ด์‹œ | [๋ฒ ์ŠคํŠธ์•จ๋ฒ”](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 |
| 24์ฐจ์‹œ | 2024.08.17 | BFS | [์•„๊ธฐ์ƒ์–ด](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 |
| 25์ฐจ์‹œ | 2024.08.17 | DFS | [์นœ๊ตฌ๋น„](https://www.acmicpc.net/problem/16562) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/234 |
| 26์ฐจ์‹œ | 2024.08.24 | ๊ทธ๋ฆฌ๋”” | [์‹ ์ž…์‚ฌ์›](https://www.acmicpc.net/problem/1946) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/237 |

---
19 changes: 19 additions & 0 deletions H0ngJu/๊ทธ๋ฆฌ๋””/์‹ ์ž…์‚ฌ์›.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys

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

T = int(input())

for _ in range(T):
N = int(input())
apply = [list(map(int, input().split())) for _ in range(N)]
apply = sorted(apply)
top = 0
cnt = 1

for i in range(1, N):
if apply[i][1] < apply[top][1]:
top = i
cnt += 1

print(cnt)
36 changes: 36 additions & 0 deletions alstjr7437/BFS/DSLR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from collections import deque
import sys

input = sys.stdin.readline

T = int(input())

def command(register, cmd):
if cmd == 0:
return ((register * 2) % 10000, "D")
elif cmd == 1:
return (9999 if register == 0 else register - 1, "S")
elif cmd == 2:
return (register % 1000 * 10 + register // 1000, "L")
elif cmd == 3:
return (register // 10 + (register % 10) * 1000, "R")

for _ in range(T):
A, B = map(int, input().split())

visited = [False] * 10000
visited[A] = True

queue = deque([(A, "")])
while queue:
cur, result = queue.popleft()

if cur == B:
print(result)
break

for i in range(4):
register, cmd = command(cur, i)
if not visited[register]:
visited[register] = True
queue.append((register, result + cmd))
7 changes: 4 additions & 3 deletions alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
| 27์ฐจ์‹œ | 2024.05.26 | ์šฐ์„ ์ˆœ์œ„ ํ | <a href="https://www.acmicpc.net/problem/7662">์ด์ค‘ ์šฐ์„ ์ˆœ์œ„ ํ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/198 |
| 28์ฐจ์‹œ | 2024.05.30 | ๋ธŒ๋ฃจํŠธ ํฌ์Šค | <a href="https://www.acmicpc.net/problem/6064">์นด์ž‰ ๋‹ฌ๋ ฅ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/203 |
| 29์ฐจ์‹œ | 2024.06.11 | ์ด๋ถ„ ํƒ์ƒ‰ | <a href="https://www.acmicpc.net/problem/2805">๋‚˜๋ฌด ์ž๋ฅด๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/210 |
| 30์ฐจ์‹œ | 2024.06.19 | ๋ฐฉ ๋ฒˆํ˜ธ | <a href="https://www.acmicpc.net/problem/1475">๊ตฌํ˜„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/211 |
| 31์ฐจ์‹œ | 2024.06.19 | ๊ฒŒ์ž„ ๋งต ์ตœ๋‹จ๊ฑฐ๋ฆฌ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/1844">BFS</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/218 |
| 32์ฐจ์‹œ | 2024.08.15 | ๊ณผ์ผ ํƒ•ํ›„๋ฃจ | <a href="https://www.acmicpc.net/problem/30804">ํˆฌ ํฌ์ธํ„ฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/230 |
| 30์ฐจ์‹œ | 2024.06.19 | ๊ตฌํ˜„ | <a href="https://www.acmicpc.net/problem/1475">๋ฐฉ ๋ฒˆํ˜ธ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/211 |
| 31์ฐจ์‹œ | 2024.06.19 | BFS | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/1844">๊ฒŒ์ž„ ๋งต ์ตœ๋‹จ๊ฑฐ๋ฆฌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/218 |
| 32์ฐจ์‹œ | 2024.08.15 | ํˆฌ ํฌ์ธํ„ฐ | <a href="https://www.acmicpc.net/problem/30804">๊ณผ์ผ ํƒ•ํ›„๋ฃจ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/230 |
| 33์ฐจ์‹œ | 2024.08.21 | BFS | <a href="https://www.acmicpc.net/problem/9019">DSLR</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/236 |
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
| 68์ฐจ์‹œ | 2024.08.06 | ๊ทธ๋ฆฌ๋”” | <a href="https://www.acmicpc.net/problem/24337">๊ฐ€ํฌ์™€ ํƒ‘</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/226
| 69์ฐจ์‹œ | 2024.08.10 | ๋ˆ„์ ํ•ฉ, ์ˆ˜ํ•™ | <a href="https://www.acmicpc.net/problem/9527">1์˜ ๊ฐœ์ˆ˜ ์„ธ๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/228
| 70์ฐจ์‹œ | 2024.08.16 | ์Šคํƒ | <a href="https://www.acmicpc.net/problem/22866">ํƒ‘ ๋ณด๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/232
| 71์ฐจ์‹œ | 2024.08.20 | ๋‹ค์ต์ŠคํŠธ๋ผ | <a href="https://www.acmicpc.net/problem/24042">๋‹ค์ต์ŠคํŠธ๋ผ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/235
| 72์ฐจ์‹œ | 2024.08.23 | DFS + ํŠธ๋ฆฌ | <a href="https://www.acmicpc.net/problem/20188">๋“ฑ์‚ฐ ๋งˆ๋‹ˆ์•„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/238
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from collections import defaultdict
from heapq import *
import sys

def input(): return sys.stdin.readline().rstrip()
MAX = 100_000 * 700_000 + 1
N, M = map(int, input().split())

graph = defaultdict(lambda : defaultdict(list))

for idx in range(1,M+1):
start, destination = map(int, input().split())
graph[start][destination].append(idx)
graph[destination][start].append(idx)

costs = [MAX for _ in range(N+1)]
visited = set()
heap = [(0, 1)]
while heap:
now_cost, now_idx = heappop(heap)

if now_idx in visited: continue
visited.add(now_idx)

if costs[now_idx] <= now_cost: continue
costs[now_idx] = now_cost

if now_idx == N: break

for neighbor in graph[now_idx]:
if neighbor in visited: continue

for neighbor_idx in graph[now_idx][neighbor]:

real_idx = now_cost % M
if real_idx < neighbor_idx:
heappush(heap, (neighbor_idx - real_idx + now_cost, neighbor))
else:
heappush(heap, (now_cost + M - real_idx + neighbor_idx, neighbor))
print(costs[-1])

0 comments on commit 0f57352

Please sign in to comment.