Pagini recente » Cod sursa (job #1313645) | Cod sursa (job #737527) | Cod sursa (job #1877868) | Cod sursa (job #854776) | Cod sursa (job #2843873)
#include <fstream>
#include <vector>
#define pb push_back
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
const int nmax=50002;
const int mmax=100002;
vector <int> muc[nmax];
bool viz[nmax];
int stiva[nmax],hstk;
int n,m;
void topologic(int x)
{
viz[x]=1;
for(auto it:muc[x])
{
if(!viz[it])
topologic(it);
}
hstk++;
stiva[hstk]=x;
}
int main()
{
fin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y;
fin>>x>>y;
muc[x].pb(y);
}
for(int i=1;i<=n;i++)
if(viz[i]==0)
topologic(i);
for(int i=hstk;i>0;i--)
fout<<stiva[i]<<' ';
return 0;
}