Skip to content

Commit

Permalink
Merge branch 'main' into 28-H0ngJu
Browse files Browse the repository at this point in the history
  • Loading branch information
H0ngJu authored Sep 20, 2024
2 parents bfd887e + a654144 commit 7a6bd20
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 6 deletions.
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))
11 changes: 5 additions & 6 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
| 20์ฐจ์‹œ | 2024.06.03 | ๋ฐฑํŠธ๋ž˜ํ‚น | [์Šคํƒ€ํŠธ์™€ ๋งํฌ](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/206 |
| 21์ฐจ์‹œ | 2024.06.07 | ๊ทธ๋ฆฌ๋”” | [ํ–‰๋ณต ์œ ์น˜์›](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 |
| 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 |

| 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 |
| 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 |

---
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])}")
2 changes: 2 additions & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@
| 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
---
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 7a6bd20

Please sign in to comment.