Skip to content

Commit b628836

Browse files
committed
BOJ 2252 / 골드3 / 줄 세우기 / 36ms
1 parent 9ff5f55 commit b628836

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

5주차/gyubhin/줄세우기.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
#define SIZE 100002
5+
6+
int n, m, ind[SIZE];
7+
vector<int> adj[SIZE];
8+
queue<int> q;
9+
10+
int main(void) {
11+
int u, v;
12+
scanf("%d %d", &n, &m);
13+
for (int i = 0; i < m; i++) {
14+
scanf("%d %d", &u, &v);
15+
adj[u].push_back(v);
16+
ind[v]++;
17+
}
18+
19+
for (int i = 1; i <= n; i++) {
20+
if (!ind[i]) q.push(i);
21+
}
22+
while (!q.empty()) {
23+
int cur = q.front();
24+
q.pop();
25+
printf("%d ", cur);
26+
for (auto nxt : adj[cur]) {
27+
ind[nxt]--;
28+
if (!ind[nxt]) q.push(nxt);
29+
}
30+
}
31+
return 0;
32+
}

0 commit comments

Comments
 (0)