Mercurial > hg > python
view req_dep.py @ 59:c22f83e049a9 simple
check0 works for nono10,
but is broken in that col 3 w/o the row 7 hit would find the row 3 hit
as satisfying the last (2nd) run, which isn't _necessarily_ correct
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Sat, 03 Jun 2023 22:11:12 +0100 |
parents | e07789816ca5 |
children |
line wrap: on
line source
#!/usr/bin/python2.7 import sys kids={} parents={} known=set(()) l=sys.stdin.readline() while l: ff=l.strip().split() if len(ff)!=0: d=ff[0] sys.stdin.readline() pp=sys.stdin.readline().strip().replace(',','').split()[2:] parents[d]=pp known.add(d) for p in pp: known.add(p) try: c=kids[p] c.add(d) except KeyError: c=set([d]) kids[p]=c l=sys.stdin.readline() roots={} still=set(()) for k in known: if k in parents: still.add(k) else: roots[k]=set([k]) #print len(parents),len(kids),len(roots),len(still),roots print roots.keys() while len(still)>0: #print len(still),len(roots) pend=still still=set([]) while len(pend)>0: x=pend.pop() #print x,len(pend) for p in parents[x]: try: r=roots[p] roots[x]=roots.get(x,set(())).union(r) except KeyError: if p in parents: still.add(x) for x,r in sorted(roots.items()): print x,r