def main0(n,s,e,a): a.append(s) a.append(e) g=[[] for _ in range(n+2)] for i in range(n+1): for j in range(i+1,n+2): x=a[i]^a[j] cnt=bin(x).count('1') if cnt<=1: g[i].append(j) g[j].append(i) from collections import deque todo=deque([n]) seen=[-1]*(n+2) seen[n]=0 while todo: v=todo.popleft() for nv in g[v]: if seen[nv]==-1: seen[nv]=seen[v]+1 todo.append(nv) if seen[n+1]==-1: return -1 else: return seen[n+1]-1 def main1(n,s,e,a): # a[i]<=10^9~2^30 # 各iについてハミルトン距離が1のものを列挙→連想配列{数字:idx}の中から当てはまるものを探す a.append(s) a.append(e) g=[set() for _ in range(n+2)] d={} for i,x in enumerate(a): if x in d: d[x].append(i) else: d[x]=[i] for i,x in enumerate(a): for j in range(30): if x^(1<