Skip to content

Commit

Permalink
Merge branch 'main' into 5-ljedd2-02
Browse files Browse the repository at this point in the history
  • Loading branch information
LJEDD2 authored Jul 31, 2024
2 parents cd7997b + 5d5ad2c commit d5709e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 0 additions & 1 deletion LJEDD2/2024-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
| 3차시 | 2024.07.24 | 깊이/너비 우선 탐색(DFS/BFS) | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/43164">여행경로</a> | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/131) |
| 4차시 | 2024.07.27 | 그래프 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/49189">가장 먼 노드</a> | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/133) |
| 5차시 | 2024.07.31 | 다이나믹프로그래밍 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/43105">정수 삼각형</a> | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/139) |
---
23 changes: 23 additions & 0 deletions LJEDD2/2024-2/그래프/가장 먼 노드.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from collections import deque

def solution(n, edge):
graph = [[] for _ in range(n + 1)]
visited = [0] * (n + 1)

# 인접 리스트 방식의 그래프 구현
for a, b in edge:
graph[a].append(b)
graph[b].append(a)

queue = deque([(1)])
visited[1] = 1

while queue:
x = queue.popleft()
for nx in graph[x]:
if not visited[nx]: # 방문한 적이 없는 경우
visited[nx] = visited[x] + 1 # 거리 계산
queue.append(nx)

max_value = max(visited)
return visited.count(max_value) # 최댓값을 가지는 요소의 개수

0 comments on commit d5709e9

Please sign in to comment.