diff --git a/yuyu0830/README.md b/yuyu0830/README.md index 09b8881..da52d1a 100644 --- a/yuyu0830/README.md +++ b/yuyu0830/README.md @@ -25,4 +25,5 @@ | 21차시 | 2024.07.23 | 수학 | [1의 개수 세기](https://www.acmicpc.net/problem/9527) | - | | 22차시 | 2024.08.05 | DP | [계단 수](https://www.acmicpc.net/problem/1562) | - | | 23차시 | 2024.08.05 | LCS | [LCS 2](https://www.acmicpc.net/problem/9252) | - | +| 24차시 | 2024.08.14 | 위상정렬 | [줄 세우기](https://www.acmicpc.net/problem/2252) | - | --- \ No newline at end of file diff --git "a/yuyu0830/\354\234\204\354\203\201\354\240\225\353\240\254/2252.cpp" "b/yuyu0830/\354\234\204\354\203\201\354\240\225\353\240\254/2252.cpp" new file mode 100644 index 0000000..05bb3b8 --- /dev/null +++ "b/yuyu0830/\354\234\204\354\203\201\354\240\225\353\240\254/2252.cpp" @@ -0,0 +1,48 @@ +#include +#include +#include + +#define NUM 32001 + +using namespace std; + +int n, m; +int enter[NUM] = {0, }; + +vector rule[NUM]; + +int main() { + cin >> n >> m; + + for (int i = 0; i < m; i++) { + int a, b; cin >> a >> b; + + rule[a].push_back(b); + enter[b]++; + } + + queue empty; + vector ans; + + for (int i = 1; i <= n; i++) { + if (!enter[i]) + empty.push(i); + } + + while (!empty.empty()) { + int cur = empty.front(); + empty.pop(); + + ans.push_back(cur); + + for (int i : rule[cur]) { + enter[i]--; + + if (!enter[i]) + empty.push(i); + } + } + + for (int i : ans) + printf("%d ", i); +} \ No newline at end of file