/*
Copyright 2011 Marek "p2004a" Rusinowski
Kahn algorithm
*/
#include <cstdio>
#include <vector>
#include <queue>
#define MAXN 1000000
std:: vector < int > edges[ MAXN] ;
int indeg[ MAXN] ;
int main( ) {
int a, b, n, m;
scanf ( "%d %d" , & n, & m) ;
for ( int i = 0 ; i < m; ++ i) {
scanf ( "%d %d" , & a, & b) ;
edges[ -- a] .push_back ( -- b) ;
++ indeg[ b] ;
}
std:: queue < int > q;
for ( int i = 0 ; i < n; ++ i) {
if ( ! indeg[ i] ) {
q.push ( i) ;
}
}
while ( ! q.empty ( ) ) {
int v = q.front ( ) ;
printf ( "%d " , v + 1 ) ;
q.pop ( ) ;
for ( unsigned i = 0 ; i < edges[ v] .size ( ) ; ++ i) {
-- indeg[ edges[ v] [ i] ] ;
if ( ! indeg[ edges[ v] [ i] ] ) {
q.push ( edges[ v] [ i] ) ;
}
}
}
printf ( "\n " ) ;
return 0 ;
}
LyoKICBDb3B5cmlnaHQgMjAxMSBNYXJlayAicDIwMDRhIiBSdXNpbm93c2tpCiAgS2FobiBhbGdvcml0aG0KKi8KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHF1ZXVlPgoKI2RlZmluZSBNQVhOIDEwMDAwMDAKCnN0ZDo6dmVjdG9yPGludD4gZWRnZXNbTUFYTl07CmludCBpbmRlZ1tNQVhOXTsKCmludCBtYWluKCkgewogIGludCBhLCBiLCBuLCBtOwogIHNjYW5mKCIlZCAlZCIsICZuLCAmbSk7CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyArK2kpIHsKICAgIHNjYW5mKCIlZCAlZCIsICZhLCAmYik7CiAgICBlZGdlc1stLWFdLnB1c2hfYmFjaygtLWIpOwogICAgKytpbmRlZ1tiXTsKICB9CiAgc3RkOjpxdWV1ZTxpbnQ+IHE7CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgIGlmICghaW5kZWdbaV0pIHsKICAgICAgcS5wdXNoKGkpOwogICAgfQogIH0KICB3aGlsZSAoIXEuZW1wdHkoKSkgewogICAgaW50IHYgPSBxLmZyb250KCk7CiAgICBwcmludGYoIiVkICIsIHYgKyAxKTsKICAgIHEucG9wKCk7CiAgICBmb3IgKHVuc2lnbmVkIGkgPSAwOyBpIDwgZWRnZXNbdl0uc2l6ZSgpOyArK2kpIHsKICAgICAgLS1pbmRlZ1tlZGdlc1t2XVtpXV07CiAgICAgIGlmICghaW5kZWdbZWRnZXNbdl1baV1dKSB7CiAgICAgICAgcS5wdXNoKGVkZ2VzW3ZdW2ldKTsKICAgICAgfQogICAgfQogIH0KICBwcmludGYoIlxuIik7CiAgcmV0dXJuIDA7Cn0K
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout