import sys sys.setrecursionlimit(10**7) def main1(n,m,a): # 自明な例を除外 for i in range(n-2): if a[i]!=a[i+1]!=a[i+2]!=a[i]: continue return [] g=[[] for _ in range(m)] v0ls=set(range(m)) for i in range(0,n,2): if 0<=i-1: u,v=a[i],a[i-1] u,v=u-1,v-1 g[u].append(v) v0ls.discard(v) if i+mvに辺がある<=>u