Topological Sorting by kt3k

import sys
b=set()
a=[set(map(int,l[3:].split()))for l in sys.stdin]
while 1:l=min(i+1for i,k in enumerate(a)if not(k-b or i+1in b));b.add(l);print l

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page