Skip to content

Commit

Permalink
Merge pull request #46 from AlgoLeadMe/13-kangrae-jo
Browse files Browse the repository at this point in the history
13-kangrae-jo
  • Loading branch information
kangrae-jo authored Jan 9, 2025
2 parents 328bed6 + 134010c commit b56da47
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions kangrae-jo/Graph/13-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
#include <list>
#include <vector>

using namespace std;

int N, M;
vector<bool> visited;
vector<list<int>> graph;

void dfs(int v, list<int>& r) {
visited[v] = true;
for (int x : graph[v]) {
if (visited[x] == false) dfs(x, r);
}
r.push_front(v);
}

list<int> topologicalSort() {
list<int> r;
for (int v = 1; v <= N; v++) {
if (visited[v] == false) dfs(v, r);
}

return r;
}

int main() {
cin >> N >> M;

visited = vector<bool>(N + 1, false);
graph = vector<list<int>>(N + 1);

while (M--) {
int a, b;
cin >> a >> b;

graph[a].push_back(b);
}

list<int> r = topologicalSort();
for (int i : r) {
cout << i << " ";
}

return 0;
}
1 change: 1 addition & 0 deletions kangrae-jo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
| 10์ฐจ์‹œ | 2024.11.30 | ๋ˆ„์ ํ•ฉ | [๊ตฌ๊ฐ„ ํ•ฉ ๊ตฌํ•˜๊ธฐ 4](https://www.acmicpc.net/problem/11659)|[#37](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/37)|
| 11์ฐจ์‹œ | 2024.12.21 | Greedy | [ATM](https://www.acmicpc.net/problem/11399)|[#41](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/41)|
| 12์ฐจ์‹œ | 2024.12.24 | HEAP | [ํฌ๋ฆฌ์Šค๋งˆ์Šค ์„ ๋ฌผ](https://www.acmicpc.net/problem/14235)|[#44](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/44)|
| 13์ฐจ์‹œ | 2024.12.28 | Graph | [์ค„ ์„ธ์šฐ๊ธฐ](https://www.acmicpc.net/problem/2252)|[#46](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/46)|

---

0 comments on commit b56da47

Please sign in to comment.