Skip to content

Commit

Permalink
24-yuyu0830
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyu0830 authored Sep 2, 2024
2 parents 617e119 + ed7d392 commit dbbb3c4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) | - |
---
48 changes: 48 additions & 0 deletions yuyu0830/μœ„μƒμ •λ ¬/2252.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <iostream>
#include <vector>
#include <queue>

#define NUM 32001

using namespace std;

int n, m;
int enter[NUM] = {0, };

vector<int> 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<int> empty;
vector<int> 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);
}

0 comments on commit dbbb3c4

Please sign in to comment.