codeforce 906 SOL (C)
我们发现N很小,那么我们可以爆搜每个人取或不取,最后统计答案。
#include<bits/stdc++.h> #define eho(x) for(int i=head[x];i;i=net[i]) #define N 27 #define M 4007 using namespace std; int anw,ans[N],now,nows[N],siz,n,m; int f[N][N],fall[M],net[M],head[N],tot,a,b; #define sight(c) ('0'<=c&&c<='9') inline void read(int &x){ static char c; for (c=getchar();!sight(c);c=getchar()); for (x=0;sight(c);c=getchar())x=x*10+c-48; } void write(int x){if (x<10) {putchar('0'+x); return;} write(x/10); putchar('0'+x%10);} inline void writeln(int x){ if (x<0) putchar('-'),x*=-1; write(x); putchar('\n'); } inline void writel(int x){ if (x<0) putchar('-'),x*=-1; write(x); putchar(' '); } void dfs(int x){ if (now>=anw) return; if (n==x) { for (int i=0;i<n;i++) if (f[n][i]^siz) return; memcpy(ans,nows,sizeof nows); anw=now; return; } memcpy(f[x+1],f[x],sizeof f[x]); dfs(x+1); for (int i=0;i<n;i++) if(f[x][x]&(1<<(i))) f[x+1][i]|=f[x][x]; nows[++now]=x+1; dfs(x+1); now--; } int main () { freopen("c.in","r",stdin); read(n); read(m); for (int i=0;i<n;i++)ans[i]=i+1,f[0][i]|=1<<i;anw=n; siz=1<<n; siz--; while (m--) { read(a); read(b); f[0][a-1]|=1<<b-1;f[0][b-1]|=1<<a-1; } dfs(0); writeln(anw); for (int i=1;i<=anw;i++) writel(ans[i]);return 0; }