Pagini recente » Cod sursa (job #2278842) | Cod sursa (job #2321358) | Cod sursa (job #122982) | Cod sursa (job #1073833) | Cod sursa (job #2835921)
#include<bits/stdc++.h>
using namespace std;
FILE *f=fopen("sortaret.in","r");
FILE *g=fopen("sortaret.out","w");
const int NMAX = 50004;
vector<int> G[NMAX];
bitset<NMAX>viz;
int N,M;
stack<int> stiva;
void DFS(int nodCurent)
{
viz[nodCurent]=true;
for(auto nodVecin:G[nodCurent])
if(!viz[nodVecin])DFS(nodVecin);
stiva.push(nodCurent);
}
void Read()
{
fscanf(f,"%d%d",&N,&M);
for(int i=1;i<=M;i++)
{
int x,y;fscanf(f,"%d%d",&x,&y);
G[x].push_back(y);
}
fclose(f);
}
int main()
{
Read();
for(int i=1;i<=N;i++)
if(!viz[i])DFS(i);
while(!stiva.empty())
{
fprintf(g,"%d ",stiva.top());
stiva.pop();
}
fclose(g);
return 0;
}