Skip to content

Commit

Permalink
11-InSange
Browse files Browse the repository at this point in the history
11-InSange
  • Loading branch information
InSange authored May 20, 2024
2 parents 11b5d76 + a7badff commit 81387c2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
60 changes: 60 additions & 0 deletions InSange/DFS/2668.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, num;
vector<bool> visited;
vector<int> v;
vector<int> 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;
}
1 change: 1 addition & 0 deletions InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
| 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/41)]
---

0 comments on commit 81387c2

Please sign in to comment.