Farjana_akter

Untitled

Jun 29th, 2019
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int graph[105][105]= {0},i,j,n,k,mx;
  4. vector<int>store,res;
  5. bool color[105];
  6.  
  7. bool isblack(int node)
  8. {
  9. for(i=1; i<=node; i++)
  10. {
  11. if(graph[node][i]==1 && color[i]==true)
  12. {
  13. return false;
  14. }
  15. }
  16. return true;
  17. }
  18. void graphclr(int nodenum)
  19. {
  20. if(nodenum>n)
  21. {
  22. if(mx<store.size())
  23. {
  24. mx=store.size();
  25. res=store;
  26. }
  27. return;
  28. }
  29. if(isblack(nodenum)==true)
  30. {
  31. color[nodenum]=true;
  32. store.push_back(nodenum);
  33. graphclr(nodenum+1);
  34. store.pop_back();
  35. color[nodenum]=false;
  36. }
  37. graphclr(nodenum+1);
  38. }
  39. int main()
  40. {
  41. int t,x,y;
  42. cin>>t;
  43. while(t--)
  44. {
  45. memset(graph,0,sizeof(graph));
  46. memset(color,0,sizeof(color));
  47. store.clear();
  48. res.clear();
  49. cin>>n>>k;
  50. for(i=0; i<k; i++)
  51. {
  52. cin>>x>>y;
  53. graph[x][y]=1;
  54. graph[y][x]=1;
  55. }
  56. mx=0;
  57. graphclr(1);
  58. cout<<mx<<endl;
  59. for(i=0; i<mx; i++)
  60. {
  61. if(i>0)
  62. cout<<" ";
  63. cout<<res[i];
  64. }
  65. cout<<endl;
  66. }
  67. return 0;
  68. }
Add Comment
Please, Sign In to add comment