Pagini recente » Cod sursa (job #2356249) | Cod sursa (job #2080533) | Cod sursa (job #852156) | Cod sursa (job #908448) | Cod sursa (job #3282442)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
const int N = 50000;
vector <int> s[N+1];
int nrp[N+1];
int main(){
ifstream in("sortaret.in");
ofstream out("sortaret.out");
int n, m;
in >> n >> m;
for (int i = 1; i <= m; i++){
int x, y;
in >> x >> y;
s[x].push_back(y);
nrp[y]++;
}
queue <int> q;
for (int i = 1; i <= n; i++){
if (nrp[i] == 0){
q.push(i);
}
}
while (!q.empty()){
int x = q.front();
q.pop();
out << x << " ";
for (auto y:s[x]){
nrp[y]--;
if (nrp[y] == 0){
q.push(y);
}
}
}
in.close();
out.close();
return 0;
}