Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[22주차] 배수빈 #303

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

[22주차] 배수빈 #303

wants to merge 6 commits into from

Conversation

baexxbin
Copy link
Contributor

No description provided.

Comment on lines +21 to +34
visited[x][y] = true;

// 다음 좌표
int d = board[x][y];
int nx = x+dx[d];
int ny = y+dy[d];

if (visited[nx][ny] && !finished[nx][ny]) { // 사이클 찾은 경우
cycle++;
}

if (!visited[nx][ny]) dfs(nx, ny); // 방문안했을 경우 다음 좌표로 이동

finished[x][y] = true; // 현재 노드의 dfs를 다 돌았으면 끝났음 표시
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DFS로 깔끔하게 구현해주신 것 같은데요,,!!

행과 열이 1,000이면서

RRRR ..... D
ULLL ..... D
RRRR ..... D
...
RRRR ..... L

이런 테스트 케이스에서는 스택 오버플로우가 발생할 것 같습니다!

질문 게시판에 반례 보고 댓글 남깁니다!

반례는 통과하지만, 행, 열 크기가 더 큰 경우에는 안될 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헉!!! 그렇군요!!
순환그래프는 dfs방법으로만 생각하고 시간복잡도도 괜찮아서 된다고 생각했었는데, 재귀일땐 스택 오버플로우도 잘 고려하는 습관을 길러야겠어요! N<=10^4 정도만 안전하다는 점... 잊지않도록 하겠습니당!! 알려주셔서 감사합니다!!😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants