Pagini recente » Cod sursa (job #3367170) | Cod sursa (job #3364703) | Cod sursa (job #3364704) | Cod sursa (job #3365128) | Cod sursa (job #3364639)
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1000000;
vector<int> L[NMAX + 1];
int grad[NMAX + 1];
int main(){
ifstream cin("sortaret.in");
ofstream cout("sortaret.out");
int n, m, x, y;
cin >> n >> m;
for(int i=1; i<=m; i++){
cin >> x >> y;
L[x].push_back(y);
grad[y]++;
}
queue<int>q;
for(int i=1; i<=n; i++){
if(grad[i]==0){
q.push(i);
}
}
while (q.empty()==false){
int nod = q.front();
q.pop();
cout << nod <<" ";
for(int i=0;i<L[nod].size(); i++){
int vec=L[nod][i];
grad[vec]--;
if(grad[vec]==0){
q.push(vec);
}
}
}
return 0;
}