Skip to content

Commit 3d14cca

Browse files
committed
Fix count of areas with dfs snippet in graph week_12
1 parent 1d9187c commit 3d14cca

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Seminars/sem_12/playground_12.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@
452452
" for vertex in graph:\n",
453453
" if vertex in visited:\n",
454454
" continue\n",
455+
" visited.add(vertex)\n",
456+
" \n",
455457
" dfs(vertex, visited, graph)\n",
456458
" count += 1\n",
457459
"\n",

Tasks/tasks_12/count_of_areas/solution_dfs_recursive.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Solution using DFS with recursion."""
22

33
import sys
4-
sys.setrecursionlimit(100_000)
4+
sys.setrecursionlimit(int(1e5))
55

66
def dfs(current, visited, graph):
77
for neighbor in graph[current]:
@@ -17,7 +17,10 @@ def count_areas(graph):
1717
for vertex in graph:
1818
if vertex in visited:
1919
continue
20+
21+
visited.add(vertex)
2022
dfs(vertex, visited, graph)
23+
2124
count += 1
2225

2326
return count
@@ -35,5 +38,3 @@ def count_areas(graph):
3538
graph[y].add(x)
3639

3740
print(count_areas(graph), end=' ')
38-
39-

0 commit comments

Comments
 (0)