Pagini recente » Cod sursa (job #510334) | Cod sursa (job #1929577) | Cod sursa (job #1728057) | Cod sursa (job #3174033) | Cod sursa (job #3224860)
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
ifstream f("sortaret.in");
ofstream g("sortaret.out");
const int nmax = 50005;
int n, m, fr[nmax];
vector<int> a[nmax];
stack<int> St;
void Dfs(int nod)
{
fr[nod] = 1;
for(int i = 0; i < a[nod].size(); i ++)
{
int k = a[nod][i];
if(fr[k] == 0)
Dfs(k);
}
St.push(nod);
}
int main()
{
f >> n >> m;
for(int i = 1; i <= m; i ++)
{
int x, y;
f >> x >> y;
a[x].push_back(y);
}
for(int i = 1; i <= n; i ++)
if(!fr[i])
Dfs(i);
while(!St.empty())
{
g << St.top() << " ";
St.pop();
}
return 0;
}