-
Notifications
You must be signed in to change notification settings - Fork 0
/
음악프로그램.cc
57 lines (50 loc) · 1.24 KB
/
음악프로그램.cc
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> map(n+1, vector<int>());
vector<int> degree(n+1, 0);
int size;
for (int i = 0; i < m; i++) {
cin >> size;
vector<int> tmp(size, 0);
for (int j = 0; j < size; j++) {
cin >> tmp[j];
}
for (int j = 0; j < size; j++) {
for (int k = j+1; k < size; k++) {
map[tmp[j]].push_back(tmp[k]);
degree[tmp[k]]++;
}
}
}
queue<int> q;
for (int i = 1; i <= n; i++) {
if (degree[i] == 0) q.push(i);
}
vector<int> ans;
while(!q.empty()) {
int x = q.front();
q.pop();
ans.push_back(x);
for (int i = 0; i < map[x].size(); i++) {
int nx = map[x][i];
degree[nx]--;
if (degree[nx] == 0) q.push(nx);
}
}
if (ans.size() != n) {
cout << "0";
} else {
for (int i = 0; i < n; i++) {
cout << ans[i] << '\n';
}
}
return 0;
}