Skip to content

Commit

Permalink
Merge pull request #78 from AlgoLeadMe/21-seongwon030
Browse files Browse the repository at this point in the history
21-seongwon030
  • Loading branch information
seongwon030 authored Aug 4, 2024
2 parents a59bee6 + 5c078f2 commit cadb852
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions seongwon030/dfs/트리.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys
input = sys.stdin.readline

n = int(input())
k = list(map(int,input().split()))
del_node = int(input())

def dfs(node):
k[node] = -2
for i in range(n):
if node == k[i]:
dfs(i)

dfs(del_node)

cnt = 0
for j in range(n):
if k[j] != -2 and j not in k:
cnt+=1

print(cnt)

0 comments on commit cadb852

Please sign in to comment.