Pagini recente » Cod sursa (job #1631849) | Cod sursa (job #2479530) | Cod sursa (job #1197541) | Cod sursa (job #2560258) | Cod sursa (job #2905983)
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
stack<int>stiva;
bool viz[50001];
vector <int> a[50001];
void dfs(int x)
{
viz[x]=true;
for (auto y:a[x])
{
if (!viz[y])
dfs(y);
}
stiva.push(x);
}
int main()
{
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n, m;
fin >> n >> m;
for (int i = 0; i < m; i ++)
{
int x, y;
fin >> x >> y;
a[x].push_back(y);
}
for (int i=1;i<=n;i++)
if (!viz[i])
dfs(i);
while (!stiva.empty())
{
fout<<stiva.top()<<" ";
stiva.pop();
}
fin.close();
fout.close();
return 0;
}