import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines def scc(g): n=len(g) cmp=[0]*n ord=[-1]*n fin=[False]*n low=[0]*n visited=[] num=0 k=0 for x in range(n): if ord[x]!=-1: continue st=[~x, x] while st: v=st.pop() if v>=0: if ord[v]!=-1: continue ord[v]=num low[v]=num num+=1 visited.append(v) for w in g[v]: if ord[w]==-1: st.append(~w) st.append(w) else: v=~v if fin[v]: continue fin[v]=True for w in g[v]: if ord[w]