Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
seongwon02 committed Aug 7, 2024
2 parents 12fe4ac + 577b0ce commit 280d02e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
6 changes: 4 additions & 2 deletions JYPARK/31to40/38.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#깊이 우선 탐색
from collections import defaultdict

def solution(graph, start):
answer = []
tree = defaultdict(list)
visited = set()

#그래프를 인접 리스트로 변환
for node in graph:
tree[node[0]].append(node[1])
Expand All @@ -13,8 +15,8 @@ def solution(graph, start):
def dfs(tree, node, visited, answer):
visited.add(node)
answer.append(node)
for i in tree.get(node, []):
if i not in visited: #방문한 노드가 아니라면
for i in tree.get(node, []): #node가 tree에 존재하지 않을경우, []를 반환함
if i not in visited: #방문한 노드가 아니라면
dfs(tree, i, visited, answer)
return answer

Expand Down
26 changes: 26 additions & 0 deletions JYPARK/31to40/39.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from collections import defaultdict, deque

def solution(graph, start):
tree = defaultdict(list)
visited = set()
answer = []
for i, j in graph:
tree[i].append(j)
return bfs(tree, start, visited, answer)

def bfs(tree, node, visited, answer):
q = deque()
q.append(node)

while q:
node = q.popleft()
if node not in visited:
visited.add(node)
answer.append(node)
q.extend(tree[node])
return answer

#graph = [(1, 2), (1, 3), (2, 4), (2, 5),(3, 6),(3, 7),(4, 8), (5, 8),(6, 9),(7, 9)]
graph = [(0,1), (1, 2), (2, 3), (3, 4),(4, 5),(5, 0)]
start = 1
print(solution(graph, start))
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<td> Python : 3&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
</tr> <tr>
<td> 김성원 </td>
<td> 54 </td>
<td> 54 </td>
<td> 46 </td>
<td> -46000 </td>
<td> Python : 54&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
<td> 55 </td>
<td> 55 </td>
<td> 45 </td>
<td> -45000 </td>
<td> Python : 55&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
</tr> <tr>
<td> 김희수 </td>
<td> 14 </td>
Expand All @@ -43,11 +43,11 @@
<td> Python : 14&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
</tr> <tr>
<td> 박지영 </td>
<td> 35 </td>
<td> 37 </td>
<td> 65 </td>
<td> -65000 </td>
<td> Python : 30&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 7&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
<td> 36 </td>
<td> 38 </td>
<td> 64 </td>
<td> -64000 </td>
<td> Python : 31&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 7&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
</tr> <tr>
<td> 손시연 </td>
<td> 12 </td>
Expand All @@ -71,7 +71,7 @@
<td> Python : 12&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
</tr></table>
<br>
총 Push 횟수 : 142회
총 Push 횟수 : 144회

# 업로드 방법
### 1. 파일명
Expand Down
2 changes: 1 addition & 1 deletion total_push_cnt.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142
144

0 comments on commit 280d02e

Please sign in to comment.