Pagini recente » Cod sursa (job #1711327) | Cod sursa (job #1477781) | Cod sursa (job #1529998) | Cod sursa (job #2160115) | Cod sursa (job #2628443)
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __unix__
#define getchar getchar_unlcoked
#define putchar putchar_unlocked
#endif // __unix__
int read () {
int ch;
while (!isdigit(ch=getchar()));
int ans=0;
do
ans = (ans<<3) + (ans<<1) + ch - '0';
while (isdigit(ch=getchar()));
return ans;
}
void print (int a) {
if (a) {
print(a/10);
putchar(a%10 + '0');
}
}
struct nod {
int inf;
struct nod *urm;
} **G, *ans;
void add (nod **p, int x) {
struct nod *e = (struct nod*)malloc(sizeof(struct nod));
e->inf=x;
e->urm=*p;
*p=e;
}
unsigned long long *bits;
void set (int i) {
bits[i >> 6] |= (1ull << (i & 63));
}
int seen (int i) {
return (bits[i>>6] >> (i & 63)) & 1;
}
void dfs (int x) {
set(x);
for (struct nod *p=G[x]; p; p=p->urm)
if (!seen(p->inf))
dfs(p->inf);
add(&ans, x);
}
int main (void) {
freopen("sortaret.in", "r", stdin);
freopen("sortaret.out", "w", stdout);
int n, m;
n=read(), m=read();
bits = (unsigned long long*) calloc(n>>6 + 1, sizeof (unsigned long long));
G = (struct nod**) calloc(n+1, sizeof (struct nod*));
int i, j;
for (; m; m--) {
i=read();
j=read();
add(G+i, j);
}
for (i=1; i<=n; ++i)
if (!seen(i))
dfs(i);
for (; ans; ans=ans->urm) {
print(ans->inf);
putchar(' ');
}
fclose(stdin);
fclose(stdout);
return 0;
}