반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <iostream> #include <vector> #include <functional> #include <queue> using namespace std; int N, M,u,v,ind[32001]; vector <int> a[32001]; priority_queue <int,vector <int>,greater<int>> q; int main() { cin >> N >> M; for (int i = 1; i <= M; i++) { cin >> u >> v; a[u].push_back(v); ind[v]++; } for (int i = 1; i <= N; i++) { if (ind[i] == 0) q.push(i); } for (int j = 1; j <= N; j++) { int x = q.top(); q.pop(); cout << x << ' '; for (int i = 0; i < a[x].size(); i++) { int y = a[x][i]; ind[y]--; if (ind[y] == 0) { q.push(y); } } } } | cs |
'Algorithm' 카테고리의 다른 글
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 13700번:완전범죄 답 (0) | 2017.02.17 |
---|---|
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 9084번:동전 답 (0) | 2017.02.17 |
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 2294번:동전2 답 (0) | 2017.02.15 |
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 2293번:동전1 답 (0) | 2017.02.15 |
(C++) - 백준(BOJ) 11403 : 경로 찾기(BFS) 답 (2) | 2017.02.15 |