Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4.  
  5. using namespace std;
  6. //by GB Zakeski
  7. int abs (int n)
  8. {
  9. if (n > 0 ) return n;
  10. return -1*n;
  11. }
  12.  
  13. bool SameParty(int A, int B)
  14. {
  15. if (abs(A-B) != 1) return false;
  16. if (A%2)
  17. {
  18. return A+1 == B;
  19. }
  20. else return SameParty(B,A);
  21. }
  22.  
  23. int SecondPosel (int p)
  24. {
  25. if (SameParty(p,p+1)) return p+1;
  26. else return p-1;
  27. }
  28.  
  29. int getParty (int p)
  30. {
  31. return (p+1)/2;
  32. }
  33.  
  34. bool odp[8002];
  35.  
  36. bool CheckPosel (int toCheck, int &TS, vector <vector <int> > &NL)
  37. {
  38. int old = toCheck;
  39. vector <bool> visited(TS);
  40. visited.at(toCheck) = true;
  41. queue <int> Q;
  42. Q.push(toCheck);
  43. int toConsi,toAdd;
  44. while (Q.empty() == false)
  45. {
  46. toCheck = Q.front();
  47. visited.at(toCheck) = true;
  48. Q.pop();
  49. for (int i=0; i<NL[toCheck].size(); ++i)
  50. {
  51. toConsi = NL[toCheck][i];
  52. toAdd = SecondPosel(toConsi);
  53. if (visited.at(toAdd) == false)
  54. {
  55. visited.at(toAdd) = true;
  56. Q.push(toAdd);
  57. }
  58. }
  59. }
  60.  
  61. // cout << "For " << old << endl;
  62. // for (int i=1; i!=TS; ++i) cout << visited[i] << " ";
  63. // cout << endl;
  64. if (visited.at(old) && visited.at(SecondPosel(old))) return false;
  65. for (int i=1; i!=TS; ++i) if (visited.at(i)) odp[i] = true;
  66. return true;
  67.  
  68. }
  69.  
  70. int main()
  71. {
  72. ios_base::sync_with_stdio(0);
  73. cin.tie(0);
  74. cout.tie(0);
  75. for (int i=0; i!=8002; ++i) odp[i] = false;
  76. int n,m;
  77. int a,b;
  78. cin >> n >> m;
  79. int TS = 2*n + 1;
  80. vector <vector <int> > NotLike(TS);
  81. for (int i=0; i!=m; ++i)
  82. {
  83. cin >> a >> b;
  84. NotLike.at(a).push_back(b);
  85. NotLike.at(b).push_back(a);
  86. }
  87.  
  88. for (int i=1; i!=n+1; ++i)
  89. {
  90. if (odp[2*i-1] == false)
  91. {
  92. if (odp[2*i] == false)
  93. {
  94. if (CheckPosel(2*i-1,TS,NotLike) == false)
  95. {
  96. if (CheckPosel(2*i,TS,NotLike) == false)
  97. {
  98. cout << "NIE";
  99. return 0;
  100. }
  101. }
  102. }
  103. }
  104. }
  105.  
  106. for (int i=1; i!=TS; ++i) if (odp[i]) cout << i << "\n";
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement