From 431d677073e739362b9183c966795ffe65adb356 Mon Sep 17 00:00:00 2001 From: InSange Date: Fri, 3 May 2024 13:34:04 +0900 Subject: [PATCH 1/2] =?UTF-8?q?2024-05-03=20=EC=88=AB=EC=9E=90=20=EA=B3=A0?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InSange/DFS/2668.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ InSange/README.md | 3 ++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 InSange/DFS/2668.cpp diff --git a/InSange/DFS/2668.cpp b/InSange/DFS/2668.cpp new file mode 100644 index 0000000..e6ea5a5 --- /dev/null +++ b/InSange/DFS/2668.cpp @@ -0,0 +1,60 @@ +#include +#include +#include + +using namespace std; + +int N, num; +vector visited; +vector v; +vector answer; + +void DFS(int cur, int start) +{ + if (visited[cur] == true) + { + if (start == cur) answer.push_back(start); + return; + } + + visited[cur] = true; + DFS(v[cur], start); + visited[cur] = false; +} + +void Solve() +{ + cin >> N; + + N += 1; + visited.assign(N, false); + v.assign(N, 0); + + for (int i = 1; i < N; i++) + { + cin >> v[i]; + } + + for (int i = 1; i < N; i++) + { + DFS(i, i); + } + + int asize = answer.size(); + cout << asize << "\n"; + + for (int i = 0; i < asize; i++) + { + cout << answer[i] << "\n"; + } +} + +int main() +{ + cin.tie(nullptr); + ios::sync_with_stdio(false); + + Solve(); + + return 0; +} \ No newline at end of file diff --git a/InSange/README.md b/InSange/README.md index 1542bc2..854679e 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -11,6 +11,7 @@ | 7차시 | 2024.04.04 | 스택 | [문자열 폭발](https://www.acmicpc.net/problem/9935) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] | 8차시 | 2024.04.09 | 투 포인터 | [두 용액](https://www.acmicpc.net/problem/2470) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/32)] | 9차시 | 2024.04.12 | 힙 | [Top K Frequent Words](https://leetcode.com/submissions/detail/1180988760/) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] -| 10차시 | 2024.05.02 | 스택 | [Top K Frequent Words](https://leetcode.com/submissions/detail/1180988760/) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] +| 10차시 | 2024.05.02 | 스택 | [오아시스 재결합](https://www.acmicpc.net/problem/3015) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/40)] +| 11차시 | 2024.05.02 | DFS | [숫자고르기](https://www.acmicpc.net/problem/2668) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] ======= --- From e3ff94d6c52daefaad8f00a0144c5bc526aa2b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=A0=EC=9A=B0?= <51250442+InSange@users.noreply.github.com> Date: Fri, 3 May 2024 14:01:28 +0900 Subject: [PATCH 2/2] 11-InSange --- InSange/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InSange/README.md b/InSange/README.md index 854679e..0828da4 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -12,6 +12,6 @@ | 8차시 | 2024.04.09 | 투 포인터 | [두 용액](https://www.acmicpc.net/problem/2470) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/32)] | 9차시 | 2024.04.12 | 힙 | [Top K Frequent Words](https://leetcode.com/submissions/detail/1180988760/) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] | 10차시 | 2024.05.02 | 스택 | [오아시스 재결합](https://www.acmicpc.net/problem/3015) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/40)] -| 11차시 | 2024.05.02 | DFS | [숫자고르기](https://www.acmicpc.net/problem/2668) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] +| 11차시 | 2024.05.02 | DFS | [숫자고르기](https://www.acmicpc.net/problem/2668) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/41)] ======= ---