-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: main
Are you sure you want to change the base?
[22주차] 배수빈 #303
Conversation
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를 다 돌았으면 끝났음 표시 |
There was a problem hiding this comment.
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
이런 테스트 케이스에서는 스택 오버플로우가 발생할 것 같습니다!
질문 게시판에 반례 보고 댓글 남깁니다!
반례는 통과하지만, 행, 열 크기가 더 큰 경우에는 안될 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헉!!! 그렇군요!!
순환그래프는 dfs방법으로만 생각하고 시간복잡도도 괜찮아서 된다고 생각했었는데, 재귀일땐 스택 오버플로우도 잘 고려하는 습관을 길러야겠어요! N<=10^4 정도만 안전하다는 점... 잊지않도록 하겠습니당!! 알려주셔서 감사합니다!!😊
No description provided.