Pagini recente » Rating Gavrilescu Dina (dinag) | Cod sursa (job #27313) | Cod sursa (job #956755) | Cod sursa (job #974094) | Cod sursa (job #2711352)
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <bitset>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
const int NMAX = 50005;
const int MMAX = 100005;
vector<int> v[NMAX];
stack<int> st;
bitset<NMAX> viz;
void DFS(int x)
{
viz[x] = 1;
for(int nod : v[x])
{
if(!viz[nod])
{
DFS(nod);
}
}
st.push(x);
}
int main()
{
int n, m, x, y, i, j;
fin>>n>>m;
for(i=1; i<=m; i++)
{
fin>>x>>y;
v[x].push_back(y);
}
for(i=1; i<=n; i++)
{
if(!viz[i])
DFS(i);
}
while(!st.empty())
{
fout<<st.top()<<' ';
st.pop();
}
fin.close();
fout.close();
return 0;
}