Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. int main()
  2. {
  3. int n, k, tmp;
  4. fin >> n;
  5. int** adjacency_list = new int*[n];
  6. int *col = new int[n];
  7.  
  8. for (auto i = 0; i < n; i++) {
  9. fin >> k;
  10. col[i] = -1;
  11. adjacency_list[i] = new int[k + 1];
  12. adjacency_list[i][0] = k;
  13. for (auto j = 1; j <= k; j++)
  14. {
  15. fin >> tmp;
  16. adjacency_list[i][j] = tmp;
  17. }
  18. }
  19. print(adjacency_list, n);
  20. col[0] = 1;
  21. for (auto i = 0; i < n; ++i) {
  22. if (col[i] != -1) {
  23. for (auto j = 1; j <= adjacency_list[i][0]; ++j)
  24. {
  25. if (col[adjacency_list[i][j] - 1] == -1) {
  26. switch (col[i]) {
  27. case 0:
  28. col[adjacency_list[i][j] - 1] = 1;
  29. break;
  30. case 1:
  31. col[adjacency_list[i][j] - 1] = 0;
  32. break;
  33. default:
  34. break;
  35. }
  36. }
  37. }
  38. }
  39. else {
  40. for (auto j = 1; j <= adjacency_list[i][0]; ++j)
  41. {
  42. if (col[adjacency_list[i][j] - 1] == 1)
  43. {
  44. col[i] = 0;
  45. }
  46. else if (col[adjacency_list[i][j] - 1] == 0)
  47. {
  48. col[i] = 1;
  49. }
  50. }
  51. }
  52. }
  53.  
  54. for (auto i = 0; i < n; ++i) {
  55. cout << col[i] << " ";
  56. }
  57. fout << min(count(col, col + n, 0), count(col, col + n, 1));
  58. cout << endl << min(count(col, col + n, 0), count(col, col + n, 1));
  59. fin.close();
  60. fout.close();
  61. delete[] col;
  62. for (auto i = 0; i < n; i++) {
  63. delete[] adjacency_list[i];
  64. }
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement