This is my output if my topological sort only prints out the last vertex visited. $ g++ speed_test.cpp $ time ./a.out 22442211222411441234484848884444444444444884448844444444444884444444888444444844 30303019251923191919191677191930191911772525231111777777723237723725257257257725252525262626267726777257262323723232377267777257726262577772525252677725262377 6060575760606363172863444444176261717173361613333333333332821332121213321618888828288332828616112212121336133333333333333333333331212121212286161121212128282888828618888888833333333333333333333288282828616133888888 9696969696969696969654549696965454545454547171717171757575751181181182525257575757513131313131313135454545454252525252525255484848484848484848413131313131313131313545454545454545454545454545454545454545454545454848484848454545454545454548484845454545454545454545454965454545454545454 255255255255255255255255252252252252252254254254252254254254201201201201201201201252252252165165454545454545454516516516512712724513313313313313313332323232321921921921921921921921921921921923120120120120328118118118118118118118111111111111105105111111111111111111111111111111111111333333395951651651651651271271273331811811811812828282828283333339595959532282828282828282828282828281811811811811813232 511511511511511511511511511511511511377329329329329329396396507507507507507507507507507507507507507507507507507507507507507507450450450450450450450450450450450450450450450450450450450450450450450450450199199199199199199199267267360360360423289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289289333333333333333333333333333333333333333143143143338338338338338338338338240240240240240240240240240240240240240240240240 383838102210221022102210221022102210221022102210221022102210221022102210221022102210221022605605605605605605605605605605605605605605605605957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957957102210221022102210221022102210221022102210221022814814814814987102210221022102210221022102210221022102210221022102210221022102210221022292559559559559559559559559559559559559559559559559559559559957559559559814814814559782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782782957957957957 2047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204720472047204714811481148114811481148114811481148114811481148114811481148114811481148114811481148114811481148114811481 400740074007400740074007400740074007400740074007400740074007400740074007400740072596259625962596259625962596259624124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124118671867186718671867186718671867186718671867186718671867186718671867186718671867186718671867186718671867186713381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381338133813381853185318531853185318531853185318531853185318531853185318531853185318531853465 7.629u 0.012s 0:07.64 99.8% 0+0k 0+0io 0pf+0w