Pagini recente » Cod sursa (job #2963043) | Cod sursa (job #1047568) | Cod sursa (job #2085853) | Cod sursa (job #829640) | Cod sursa (job #1726589)
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <fstream>
#include<vector>
#include <stack>
#define maxn 50003
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
vector <int> L[maxn];
stack <int> s;
int n, m, v[maxn];
void read()
{
int i, x, y;
fin >> n >> m;
for (i = 1; i <= m; i++)
{
fin >> x >> y;
L[x].push_back(y);
}
}
void DFS(int x)
{
v[x] = 1;
int i;
for (i = 0; i < L[x].size(); i++)
if (v[L[x][i]] == 0)
DFS(L[x][i]);
s.push(x);
}
void solve()
{
int i;
for (i = 1; i <= n; i++)
if (v[i] == 0)
{
DFS(i);
}
}
void afis()
{
while (!s.empty())
{
fout << s.top() << " ";
s.top();
}
}
int main()
{
read();
solve();
afis();
fin.close();
fout.close();
return 0;
}