Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- bool graph[110][110];
- bool color[110],ans[110];
- int node,edge,curr;
- bool yes(int n)
- {
- for(int i=1; i<=node; i++)
- {
- if(graph[n][i] && color[i])
- {
- return false;
- }
- }
- return true;
- }
- void dfs(int n,int mx)
- {
- if(n==node+1)
- {
- if(curr<mx)
- {
- curr = mx;
- memcpy(ans,color,sizeof(color));
- }
- return;
- }
- if(yes(n))
- {
- color[n] = true;
- dfs(n+1,mx+1);
- color[n] = false;
- }
- dfs(n+1,mx);
- }
- int main()
- {
- int test,i,u,v;
- scanf("%d",&test);
- while(test--)
- {
- scanf("%d%d",&node,&edge);
- for(i=1; i<=edge; i++)
- {
- scanf("%d%d",&u,&v);
- graph[u][v] = graph[v][u] = true;
- }
- curr = 0;
- dfs(1,0);
- printf("%d\n",curr);
- for(i=1;i<=node;i++)
- {
- if(ans[i])
- {
- printf("%d",i);
- break;
- }
- }
- for(i=i+1;i<=node;i++)
- {
- if(ans[i])
- {
- printf(" %d",i);
- }
- }
- puts("");
- memset(color,false,sizeof(color));
- memset(graph,false,sizeof(graph));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement