@lru_cache(None) def payoffs(S,E): stay=[i for i in range(1,13) if bit(S,i-1)] res=[0]*13 for i in range(1,13): if not bit(S,i-1): res[i]=outopt[i] if len(stay)==0: return tuple(res) win=stay[0] for i in stay[1:]: if v[i]>v[win]: win=i second=0 for i in stay: if i!=win and v[i]>second: second=v[i] adj=[[] for i in range(13)] for i in stay: if i<=3: adj[0].append(i) for b in range(11): u=edges[b][0] w=edges[b][1] if bit(E,b) and bit(S,u-1) and bit(S,w-1): adj[u].append(w) def reach(avoid): seen=[False]*13 stack=[0] seen[0]=True while len(stack)>0: x=stack.pop() for y in adj[x]: if y!=avoid and not seen[y]: seen[y]=True stack.append(y) return seen[win] res[win]=v[win]-second for i in stay: if i!=win: if not reach(i): res[i]=7 return tuple(res)