Pagini recente » Cod sursa (job #2913136) | Cod sursa (job #561726) | Cod sursa (job #1160739) | Cod sursa (job #1204697) | Cod sursa (job #2446537)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
stack < int > st;
vector < int > G[50005];
bool v[50005];
int n, m, x, y;
void Citire()
{
int i;
fin >> n >> m;
for(i = 1; i <= m; i++)
{
fin >> x >> y;
G[x].push_back(y);
}
}
void DFS(int nod)
{
v[nod] = 1;
for(auto w : G[nod])
if(v[w] == 0)
DFS(w);
st.push(nod);
}
void Rezolvare()
{
int i;
for(i = 1; i <= n; i++)
if(v[i] == 0)
DFS(i);
while(!st.empty())
{
fout << st.top() << " ";
st.pop();
}
fout << "\n";
fout.close();
}
int main()
{
Citire();
Rezolvare();
return 0;
}