Pagini recente » Cod sursa (job #1983573) | Cod sursa (job #2169868) | Cod sursa (job #904939) | Cod sursa (job #841475) | Cod sursa (job #2059324)
#include <iostream>
#include <fstream>
#include <vector>
#define pb push_back
#define ll long long
using namespace std;
const int N = 1e5 + 10;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n, m;
vector < int > v[N];
vector < int > a;
int apa[N];
void dfs(int cnod)
{
fout << cnod << " ";
for(int i = 0; i < v[cnod].size(); ++i)
{
int nnod = v[cnod][i];
dfs(nnod);
}
}
int main()
{
ios::sync_with_stdio(false);
fin >> n >> m;
int x, y;
for(int i = 0; i < m; ++i)
{
fin >> x >> y;
v[x].pb(y);
apa[y] = x;
}
for(int i = 1; i <= n; ++i)
{
if(!apa[i])
a.pb(i);
}
for(int i = 0; i < a.size(); ++i)
{
int s = a[i];
dfs(s);
}
fout << "\n";
return 0;
}