Pagini recente » Cod sursa (job #1388260) | Cod sursa (job #900346) | Cod sursa (job #826596) | Cod sursa (job #1264594) | Cod sursa (job #2089779)
#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];
bool b[N];
bool start[N];
void dfs(int cnod)
{
b[cnod] = true;
for(int i = 0; i < v[cnod].size(); ++i)
{
int nnod = v[cnod][i];
fout << nnod << " ";
if(!b[nnod])
dfs(nnod);
}
}
int main()
{
fin >> n >> m;
int x, y;
for(int i = 0; i < m; ++i)
{
fin >> x >> y;
v[x].pb(y);
start[y] = true;
}
// cout << 1;
int s = 1;
while(start[s])
++s;
while(s <= n)
{
if(!b[s])
{
fout << s << " ";
dfs(s);
}
++s;
}
fout << "\n";
return 0;
}