Pagini recente » Cod sursa (job #2781610) | Cod sursa (job #2808221) | Cod sursa (job #807257) | Cod sursa (job #163443) | Cod sursa (job #2113811)
#include <fstream>
#include <vector>
#define nmax 50005
using namespace std;
fstream f1("sortaret.in", ios::in);
fstream f2("sortaret.out", ios::out);
int n, m, viz[nmax], nrl, l[nmax];
vector <int> v[nmax];
void citire()
{
int i, x, y;
f1>>n>>m;
for(i=1; i<=m; i++)
{
f1>>x>>y;
v[x].push_back(y);
}
}
void dfs(int i)
{
viz[i]=1;
for(auto it= v[i].begin(); it!=v[i].end(); ++it)
if(!viz[*it])
dfs(*it);
nrl++;
l[nrl]=i;
}
void solutie()
{
int i;
for(i=1; i<=n; i++)
if(!viz[i])
dfs(i);
}
void afis()
{
int i;
for(i=nrl; i>=1; i--)
f2<<l[i]<<' ';
}
int main()
{
citire();
solutie();
afis();
return 0;
}