Replies: 1 comment 1 reply
-
|
ㅋㅋㅋㅋ 트리의 부모도 찾아주시는 착한 분이시군요. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
유명한 자료구조중에 하나인 트리구조이다. 근데 이건 사실 트리구조의 큰 개념만 이해하고 있으면 풀 수 있는 dfs 문제이다.
일단 tree의 인덱스값에 정점들의 값을 넣어준다. dfs로 p[I] == 0 은 방문한적이 없단 뜻이므로 해당 조건을 만족하면 p[I]에 s를 대입해서 방문 처리를 한다. 그럼 p[I]번째 값이 가지고 있는 s는 i번째 노드의 부모노드 값이 되는 것이다. 출력해주면 끝..!
아직은 난해한 tree.. 파이썬에서 트리구조 만들기 넘 귀찮..ㅠㅠ
Beta Was this translation helpful? Give feedback.
All reactions