We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9ff5f55 commit b628836Copy full SHA for b628836
5주차/gyubhin/줄세우기.cpp
@@ -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