fork download
  1. #include<stdio.h>
  2. int d[300005];
  3. int col[300005];
  4. int main()
  5. {
  6. int n, m, i, a, b, c, t;
  7. scanf("%d %d", &n, &m);
  8. while(m>0)
  9. {
  10. scanf("%d %d %d", &a, &b, &c);
  11. if(d[b])
  12. {
  13. t=a;
  14. a=b;
  15. b=t;
  16. }
  17. if(d[c])
  18. {
  19. t=a;
  20. a=c;
  21. c=t;
  22. }
  23. col[b]=(col[a]+1)%3;
  24. col[c]=(col[a]+2)%3;
  25. d[a]=d[b]=d[c]=1;
  26. m--;
  27. }
  28. for(i=1; i<=n; i++)
  29. printf("%d ",col[i]+1);
  30. return 0;
  31. }
Success #stdin #stdout 0s 4524KB
stdin
Standard input is empty
stdout
Standard output is empty