Saleh127

UVA 193

Oct 13th, 2020 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll n,k;
  6. ll g[105][105];
  7. ll color[105];
  8. ll ans[105];
  9. ll maxx=0;
  10.  
  11. ll check(ll ind)
  12. {
  13. for(ll j=0; j<n; j++)
  14. {
  15. if(color[j]==1 && g[ind][j]==1)
  16. {
  17. return 0;
  18. }
  19. }
  20. return 1;
  21. }
  22.  
  23. void dfs(ll indx)
  24. {
  25.  
  26. if(indx>maxx)
  27. {
  28. maxx=indx;
  29. for(ll j=0; j<n; j++)
  30. {
  31. ans[j]=color[j];
  32. }
  33. }
  34. if(indx==n) return;
  35.  
  36. for(ll j=0; j<n; j++)
  37. {
  38. if(check(j)==1 && color[j]==0)
  39. {
  40. color[j]=1;
  41. dfs(indx+1);
  42. color[j]=0;
  43. }
  44. }
  45. return;
  46. }
  47.  
  48.  
  49. int main()
  50. {
  51. ios_base::sync_with_stdio(0);
  52. cin.tie(0);
  53. cout.tie(0);
  54.  
  55. test
  56. {
  57. cin>>n>>k;
  58. ll x,y;
  59. memset(g,0,sizeof(g));
  60. for(ll i=0; i<k; i++)
  61. {
  62. cin>>x>>y;
  63. x--,y--;
  64. g[x][y]=1;
  65. g[y][x]=1;
  66. }
  67. memset(color,0,sizeof(color));
  68. maxx=0;
  69.  
  70. dfs(0);
  71. cout<<maxx<<endl;
  72.  
  73. ll d=0;
  74. for(ll i=0; i<n; i++)
  75. {
  76. if(ans[i]==1)
  77. {
  78. if(d) cout<<" ";
  79. cout<<i+1;
  80. d=1;
  81. }
  82. }
  83. cout<<endl;
  84. }
  85.  
  86.  
  87. return 0;
  88. }
  89.  
Add Comment
Please, Sign In to add comment