Skip to content

Commit

Permalink
Merge pull request #112 from AlgoLeadMe/30-Dolchae
Browse files Browse the repository at this point in the history
30-Dolchae
  • Loading branch information
Dolchae authored Feb 26, 2024
2 parents daf60df + af522dd commit 94cbc2d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions Dolchae/DFS&BFS/2644 μ΄Œμˆ˜κ³„μ‚°.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
n = int(input())
a,b = map(int, input().split())
node_num = int(input())
graph = [[] for _ in range(n+1)]
visited = [False] * (n+1)
result = []

for _ in range(node_num):
x, y = map(int, input().split())
graph[x].append(y)
graph[y].append(x)

def dfs(v, num):
num += 1
visited[v] = True

if v == b:
result.append(num)

for i in graph[v]:
if not visited[i]:
dfs(i, num)

dfs(a, 0)
if len(result) == 0:
print(-1)
else:
print(result[0]-1)
3 changes: 2 additions & 1 deletion Dolchae/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
| 26μ°¨μ‹œ| 2024.02.05 | κ΅¬ν˜„ | [18110 solved.ac](https://www.acmicpc.net/problem/18110) | [#93](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/93) |
| 27μ°¨μ‹œ| 2024.02.08 | μ •λ ¬ | [1302 λ² μŠ€νŠΈμ…€λŸ¬](https://www.acmicpc.net/problem/1302) | [#97](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/97) |
| 28μ°¨μ‹œ| 2024.02.15 | 이진 탐색 | [6236 용돈 관리](https://www.acmicpc.net/problem/1302) | [#107](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/107) |
| 29μ°¨μ‹œ| 2024.02.15 | 브루트포슀 | [2961 λ„μ˜μ΄κ°€ λ§Œλ“  λ§›μžˆλŠ” μŒμ‹](https://www.acmicpc.net/problem/2961) | [#109](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/109) |
| 29μ°¨μ‹œ| 2024.02.19 | 브루트포슀 | [2961 λ„μ˜μ΄κ°€ λ§Œλ“  λ§›μžˆλŠ” μŒμ‹](https://www.acmicpc.net/problem/2961) | [#109](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/109) |
| 30μ°¨μ‹œ| 2024.02.22 | DFS | [2644 μ΄Œμˆ˜κ³„μ‚°](https://www.acmicpc.net/problem/2961) | [#112](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/112) |

0 comments on commit 94cbc2d

Please sign in to comment.