Pagini recente » Cod sursa (job #51823) | Statistici Cocis Gabriel Alin (Gaby_Cocis) | Istoria paginii preoni-2007/runda-finala/poze/wii-play | Cod sursa (job #2384027) | Cod sursa (job #3214476)
#include <bits/stdc++.h>
using namespace std;
const int max_size = 5e4 + 20, INF = 1e9 + 20;
vector <int> mc[max_size], topsort;
int viz[max_size];
void dfs (int nod)
{
viz[nod] = 1;
for (auto f : mc[nod])
{
if (viz[f] == 1)
{
continue;
}
dfs(f);
}
topsort.push_back(nod);
}
void solve ()
{
int n, m;
cin >> n >> m;
while (m--)
{
int x, y;
cin >> x >> y;
mc[x].push_back(y);
}
for (int i = 1; i <= n; i++)
{
if (viz[i] == 0)
{
dfs(i);
}
}
reverse(topsort.begin(), topsort.end());
for (auto f : topsort)
{
cout << f << " ";
}
cout << '\n';
}
signed main ()
{
#ifdef LOCAL
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#else
freopen("sortaret.in", "r", stdin);
freopen("sortaret.out", "w", stdout);
#endif // LOCAL
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long tt;
//cin >> tt;
tt = 1;
while (tt--)
{
solve();
}
return 0;
}