1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| #include <iostream> #include <cstring> #include <algorithm>
using namespace std; const int maxn = 1e5; int n,m,tot,ans,len; int head[150],all[150],point[150]; struct node { int v,next; } edge[maxn];
void add(int u,int v) { edge[tot].v = v; edge[tot].next = head[u]; head[u] = tot++; }
void dfs(int cur,int num) { if (cur > n) { if (num > ans) { ans = num; len = 0; for (int i=1; i<=n; ++i) if (all[i]) { point[len++] = i; } } return ; } bool flag = 1; for (int i=head[cur]; i!=-1; i=edge[i].next) { if (all[edge[i].v]) { flag = 0; break; } } if (flag) { all[cur] = 1; dfs(cur+1,num+1); all[cur] = 0; } if (num+(n-cur) > ans) { dfs(cur+1,num); } }
void init() { ans = tot = 0; memset(head,-1,sizeof head); }
int main() { freopen("1.in","r",stdin); int times; cin >> times; while (times--) { init(); scanf("%d%d",&n,&m); for (int i=1; i<=m; ++i) { int x,y; scanf("%d%d",&x,&y); add(x,y); add(y,x); } dfs(1,0); printf("%d\n",ans); for (int i=0; i<len; ++i) printf("%d ",point[i]); printf("\n"); } return 0; }
|