Pagini recente » Cod sursa (job #1960978) | Cod sursa (job #578181) | Cod sursa (job #2963902) | Cod sursa (job #1522272) | Cod sursa (job #2237908)
#include <cstdio>
#include <cstdlib>
using namespace std;
int n, m, *a[100005], checked[100005], time, ft[100005], c[100005], peak;
void dfs(int x)
{
checked[x] = 1;
++time;
for (int i = 1; i <= a[x][0]; ++i)
if (!checked[a[x][i]])
dfs(a[x][i]);
ft[x] = ++time;
c[++peak] = x;
}
int main()
{
FILE *in, *out;
in = freopen("sortaret.in", "r", stdin);
out = freopen("sortaret.out", "w", stdout);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
a[i] = (int *)realloc(a[i], sizeof(int));
a[i][0] = 0;
}
for (int i = 1; i <= m; ++i) {
int x, y;
scanf("%d%d", &x, &y);
++a[x][0];
a[x] = (int *)realloc(a[x], (a[x][0] + 1) * sizeof(int));
a[x][a[x][0]] = y;
++a[y][0];
a[y] = (int *)realloc(a[y], (a[y][0] + 1) * sizeof(int));
a[y][a[y][0]] = x;
}
for (int i = 1; i <= n; ++i)
if (!checked[i])
dfs(i);
for (int i = n; i; --i) printf("%d ", c[i]);
fclose(out);
return 0;
}