Pagini recente » Cod sursa (job #1223201) | Cod sursa (job #676986) | Cod sursa (job #314353) | Cod sursa (job #3229165) | Cod sursa (job #1802015)
#include<fstream>
#include<iostream>
#define mmax 100010
#define nmax 50005
#define buff_size 250010
using namespace std;
FILE*f=freopen("sortaret.in","r",stdin);
FILE*g=freopen("sortaret.out","w",stdout);
struct nod{int inf;nod *urm;} *L[nmax];
bool viz[nmax];int n,m;
char buff[buff_size],buffw[buff_size]="";int pos=0,posw=0;
inline void read(int &nr)
{
while(buff[pos] < '0' || buff[pos] > '9') if(++pos == buff_size) fread(buff,1, buff_size, stdin), pos = 0;
nr = 0;
while('0' <= buff[pos] && buff[pos] <= '9')
{
nr = nr * 10 + buff[pos] - '0';
if(++pos == buff_size) fread(buff,1, buff_size, stdin), pos = 0;
}
}
inline void add(int x,int y)
{nod *nou;
nou=new nod;
nou->inf=x;
nou->urm=L[y];
L[y]=nou;
}
inline void dfs(int x)
{nod *p;
viz[x]=1;
for(p=L[x];p;p=p->urm)
if(!viz[p->inf])
dfs(p->inf);
posw += sprintf(buffw + posw,"%d ", x);
}
int main()
{ int i,x,y;
fread(buff,1, buff_size, stdin);
read(n);read(m);
for(i=1;i<=m;i++) read(x),read(y),add(x,y);
for(i=1;i<=n;i++) if(!viz[i]) dfs(i);
fwrite(buffw, 1, posw, stdout);
}