You are viewing a single comment's thread. Return to all comments →
def storyOfATree(n, edges, k, guesses): cnn=[[] for _ in range(n+1)] for p,q in edges: cnn[p].append(q) cnn[q].append(p) win1=0 vist=[0]*(n+1) cur=[1] while cur: st=cur[0] del cur[0] if not vist[st]: vist[st]=1 for ed in cnn[st]: if not vist[ed]: win1+=[st,ed] in guesses cur.append(ed) vist=[-1]*(n+1); vist[0]=0 cur=[(1,win1)] while cur: st,win=cur[0] del cur[0] if vist[st]==-1: vist[st]=win for ed in cnn[st]: if vist[ed]==-1: cur.append((ed,win+([ed,st] in guesses)-([st,ed] in guesses))) wincount=sum([1 for x in vist if x>=k]) return '{}/{}'.format(wincount//(math.gcd(wincount,n)),n//(math.gcd(wincount,n)))
Seems like cookies are disabled on this browser, please enable them to open this website
The Story of a Tree
You are viewing a single comment's thread. Return to all comments →
Python 3: dono what's wrong with my code orz~~