fork download
  1. #include<bits/stdc++.h>
  2. //#include<boost/multiprecision/cpp_int.hpp>
  3. #define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  4. using namespace std;
  5. //using boost::multiprecision::cpp_int;
  6. typedef long long LL;
  7. typedef long double LD;
  8. const int inf=0x3f3f3f3f;
  9. const int infi=1e9+7;
  10. int t,n,m,c,d;
  11. int main()
  12. {
  13. fast;
  14. cin>>t;
  15. if(t>=1&&t<=3000)
  16. {
  17. while(t--)
  18. {
  19. vector<int> *ptr;
  20. ptr=new vector<int> [100001]();
  21. cin>>n>>m;
  22. /*if(n==2)
  23.   {
  24.   cout<<1<<endl;
  25.   cout<<1<<" "<<1<<endl;
  26.   }*/
  27. if(!(m&1))
  28. {
  29. cout<<1<<endl;
  30. for(int i=0;i<n;++i)
  31. cout<<1<<" ";
  32. cout<<endl;
  33. for(int i=0;i<m;++i)
  34. {
  35. int a,b;
  36. cin>>a>>b;
  37. }
  38. }
  39. else
  40. {
  41. for(int i=0;i<m;++i)
  42. {
  43. int a,b;
  44. cin>>a>>b;
  45. ptr[a].push_back(b);
  46. ptr[b].push_back(a);
  47. c=a;
  48. d=b;
  49. }
  50. for(int i=1;i<=n;++i)
  51. {
  52. if((ptr[i].size()&1))
  53. {
  54. cout<<2<<endl;
  55. for(int j=1;j<=n;++j)
  56. {
  57. if(j!=i)
  58. cout<<1<<" ";
  59. else
  60. cout<<2<<" ";
  61. }
  62. cout<<endl;
  63. break;
  64. }
  65. if(i==n-1)
  66. {
  67. cout<<3<<endl;
  68. for(int k=1;k<=n;++k)
  69. {
  70. if(k==c)
  71. cout<<2<<" ";
  72. else if(k==d)
  73. cout<<3<<" ";
  74. else
  75. cout<<1<<" ";
  76. }
  77. cout<<endl;
  78. }
  79. }
  80. }
  81.  
  82. }
  83. }
  84. }
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
Standard output is empty