Pagini recente » Cod sursa (job #293402) | Cod sursa (job #2269540) | Cod sursa (job #617781) | Cod sursa (job #2556961) | Cod sursa (job #2863604)
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#define NMax 50005
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
int N;
bool VIZ[NMax];
vector <int> muchie[NMax];
stack <int> Stiva;
void DFS(int nod)
{
VIZ[nod] = true;
for(unsigned int i = 0; i < muchie[nod].size(); ++ i)
if(VIZ[muchie[nod][i]] == false)
DFS(muchie[nod][i]);
Stiva.push(nod);
}
int main()
{
int M, x, y;
fin >> N >> M;
for(int i = 1; i <= M; ++ i)
{
fin >> x >> y;
muchie[x].push_back(y);
}
for(int i = 1; i <= N; ++ i)
if(VIZ[i] == false)
DFS(i);
while( !Stiva.empty() )
{
fout << Stiva.top() << ' ';
Stiva.pop();
}
return 0;
}