Pagini recente » Cod sursa (job #3339120) | Cod sursa (job #3339523) | Cod sursa (job #3262719) | Cod sursa (job #3262717) | Cod sursa (job #3357865)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream cin("sortaret.in");
ofstream cout("sortaret.out");
vector<vector<int>> gr(50100);
vector<int> top(50100);
queue<int> Q;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int nodes, edges;
cin >> nodes >> edges;
for (int i = 0; i < edges; i++) {
int a, b;
cin >> a >> b;
gr[a].push_back(b);
top[b]++;
}
for (int i = 1; i <= nodes; i++) {
if (top[i] == 0) {
Q.push(i);
}
}
while (!Q.empty()) {
int now = Q.front();
Q.pop();
cout << now << " ";
for (auto &x : gr[now]) {
top[x]--;
if (top[x] == 0) {
Q.push(x);
}
}
}
return 0;
}