Skip to content

Commit

Permalink
Merge branch 'main' into 76-tgyuuAn
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn authored Sep 20, 2024
2 parents be43cdf + 0fa761d commit c0afee5
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 1 deletion.
28 changes: 28 additions & 0 deletions H0ngJu/DFS/ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
sys.setrecursionlimit(10**9)
def input() : return sys.stdin.readline().rstrip()

n = int(input())
tree = [[] for _ in range(n+1)]
visited = [-1] * (n+1)
visited[1] = 0

for i in range(n-1):
v, u, w = map(int, input().split())
tree[v].append((u, w))
tree[u].append((v, w))

def dfs(start, dis):
for node, node_dis in tree[start]:
if visited[node] == -1:
visited[node] = dis + node_dis
dfs(node, dis + node_dis)

dfs(1,0)

far_node = visited.index(max(visited))
visited = [-1] * (n+1)
visited[far_node] = 0
dfs(far_node, 0)

print(max(visited))
3 changes: 2 additions & 1 deletion H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
| 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 |

| 27์ฐจ์‹œ | 2024.08.27 | DFS | [ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„](https://www.acmicpc.net/problem/1967) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/240 |
| 28์ฐจ์‹œ | 2024.09.04 | ๋ฒจ๋งŒํฌ๋“œ | [ํƒ€์ž„๋จธ์‹ ](https://www.acmicpc.net/problem/11657) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/244 |
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys

INF = 1e8

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

N, M = map(int, input().split())
bus = [[] for _ in range(N+1)]
distance = [INF] * (N+1)

for i in range(M):
A, B, C = map(int, input().split())
bus[A].append([B, C])

def BellmanFord(start):
distance[start] = 0

for i in range(N):
for j in range(1, N+1):
for n, w in bus[j]:
if distance[j] != INF and distance[n] > distance[j] + w:
distance[n] = distance[j] + w
if i == N-1:
return True
return False

check_negative = BellmanFord(1)

if check_negative:
print("-1")
else:
for i in range(2, N+1):
if distance[i] == INF:
print("-1")
else:
print(distance[i])
53 changes: 53 additions & 0 deletions tgyuuAn/BFS/Rain (Small).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from collections import deque
import sys

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

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

T = int(input())

for test_idx in range(T):
row, col = map(int, input().split())
board = [list(map(int,input().split())) for _ in range(row)]
new_board = [[0 for _ in range(col)] for _ in range(row)]

for height in range(1, 1001):
for start_row in range(row):
for start_col in range(col):
if board[start_row][start_col] >= height: continue

deq = deque()
deq.append((start_row, start_col))
history = {(start_row, start_col),}

visited = set()
visited.add((start_row, start_col))

while deq:
now_row, now_col = deq.popleft()

# ๊ฐ€์žฅ์ž๋ฆฌ์— ๋ฌผ์ด ํ˜๋ €๋‹ค๋Š” ๊ฒƒ์ด๋ฏ€๋กœ break
if now_row in (0, row-1): break
if now_col in (0, col-1): break

for dir in range(4):
new_row = now_row + dy[dir]
new_col = now_col + dx[dir]

if new_row < 0 or new_row >= row: continue
if new_col < 0 or new_col >= col: continue
if (new_row, new_col) in visited: continue
if board[new_row][new_col] >= height: continue

deq.append((new_row, new_col))
history.add((new_row, new_col))
visited.add((new_row, new_col))

# ๊ฐ€์žฅ์ž๋ฆฌ์— ๋ฌผ์ด ํ๋ฅด์ง€ ์•Š์•„ break๋˜์ง€ ์•Š์•˜์œผ๋ฉด,
else:
for history_row, history_col in history:
new_board[history_row][history_col] = height - board[history_row][history_col]

print(f"Case #{test_idx+1}: {sum([sum(row) for row in new_board])}")
19 changes: 19 additions & 0 deletions tgyuuAn/DP/์‚ฐ ๋ชจ์–‘ ํƒ€์ผ๋ง.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def solution(n, tops):
top = set()
DIV = 10_007

count = 0
for idx, element in enumerate(tops):
if element==1:
count += 1
top.add(2*(idx+1)+count)

DP = [0 for _ in range((n*2)+1+count+1)]
DP[1] = 1
DP[2] = 2

for now_idx in range(3,len(DP)):
if (now_idx-1) in top: DP[now_idx] = (DP[now_idx-3] % DIV) + (DP[now_idx-1] % DIV) % DIV
else: DP[now_idx] = (DP[now_idx-2] % DIV) + (DP[now_idx-1] % DIV) % DIV

return DP[-1] % DIV
3 changes: 3 additions & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,8 @@
| 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
| 73์ฐจ์‹œ | 2024.08.26 | BFS | <a href="https://www.acmicpc.net/problem/14324">Rain (Small)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/239
| 74์ฐจ์‹œ | 2024.08.30 | BFS | <a href="https://www.acmicpc.net/problem/11967">๋ถˆ ์ผœ๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/242
| 75์ฐจ์‹œ | 2024.09.02 | DP | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/258705">์‚ฐ ๋ชจ์–‘ ํƒ€์ผ๋ง</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/243
| 76์ฐจ์‹œ | 2024.09.06 | DFS + ํŠธ๋ฆฌ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/150367">ํ‘œํ˜„ ๊ฐ€๋Šฅํ•œ ์ด์ง„ํŠธ๋ฆฌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/246
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from collections import deque, defaultdict
import sys

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

N, M = map(int, input().split())
board = [[False for _ in range(N+1)] for _ in range(N+1)]
board[1][1] = True

switch = defaultdict(list)

for _ in range(M):
x, y, a, b = map(int, input().split())
switch[(x, y)].append((a,b))

deq = deque()
deq.append((1,1))
dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]
visited = {(1, 1),}
dedicates = {(1, 1),}

while deq:
now_x, now_y = deq.popleft()

for turn_on in switch[(now_x, now_y)]:
if turn_on not in dedicates: # <<<------- ์ด ์ฝ”๋“œ ํ•œ์ค„์— 3์‹œ๊ฐ„ ๋‚ ๋ฆผ
dedicates.add(turn_on)

if turn_on in visited:
deq.append(turn_on)

for dir in range(4):
new_x = now_x + dx[dir]
new_y = now_y + dy[dir]

if new_x <= 0 or new_x >= N+1: continue
if new_y <= 0 or new_y >= N+1: continue
if (new_x, new_y) in visited: continue

visited.add((new_x, new_y))

if (new_x, new_y) in dedicates:
deq.append((new_x, new_y))

print(len(dedicates))

0 comments on commit c0afee5

Please sign in to comment.