Advertisement
Dennnhhhickk

Untitled

Jan 7th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <cmath>
  5. #include <climits>
  6.  
  7. using namespace std;
  8.  
  9. struct puperfunctionmycreateion {
  10. int data, prev, st, ans;
  11. bool bol;
  12. };
  13. int find228(queue <puperfunctionmycreateion>, int);
  14. int find1337(queue <puperfunctionmycreateion>, int);
  15. int view(vector <int>);
  16. puperfunctionmycreateion check(queue <puperfunctionmycreateion>, int);
  17.  
  18. int main()
  19. {
  20. ios::sync_with_stdio(0);
  21. puperfunctionmycreateion temp, temp1, pituh2281337332;
  22. int n, m, free = 0, v, u, h, data1;
  23. vector <int> a, ans, mark, ans1;
  24. vector <vector <int> > dp;
  25. queue <puperfunctionmycreateion> q;
  26. cin >> n >> m;
  27. mark.reserve(n + 1);
  28. a.reserve(n + 1);
  29. ans.reserve(n + 1);
  30. ans.resize(n + 1);
  31. a.resize(n + 1);
  32. mark.resize(n + 1);
  33. dp.reserve(n + 1);
  34. dp.resize(n + 1);
  35. for (int i = 1; i <= n; i++){
  36. mark[i] = 0;
  37. ans[i] = INT_MAX - 20;
  38. cin >> a[i];
  39. if (a[i] != 0) {
  40. temp.data = i;
  41. temp.st = i;
  42. temp.ans = 0;
  43. temp.prev = 0;
  44. q.push(temp);
  45. mark[i] = 1;
  46. }
  47. }
  48. for (int i = 1; i <= m; i++) {
  49. cin >> v >> u;
  50. dp[v - 1].push_back(u);
  51. dp[u - 1].push_back(v);
  52. }
  53. while (!q.empty()) {
  54. temp = q.front();
  55. q.pop();
  56. for (int i = 0; i < dp[temp.data - 1].size(); i++){
  57. data1 = dp[temp.data - 1][i];
  58. if (data1 != temp.prev)
  59. if (!mark[data1]) {
  60. temp1.data = data1;
  61. temp1.st = temp.st;
  62. temp1.ans = temp.ans + 1;
  63. temp1.prev = temp.data;
  64. q.push(temp1);
  65. mark[data1] = 1;
  66. }
  67. else {
  68. pituh2281337332 = check(q, data1);
  69. if (pituh2281337332.bol)
  70. if (a[temp.st] != a[pituh2281337332.st]){
  71. ans[temp.st] = min(ans[temp.st], temp.ans + pituh2281337332.ans + 1);
  72. ans[pituh2281337332.st] = min(ans[pituh2281337332.st], ans[temp.st]);
  73. }
  74. }
  75. }
  76. }
  77. int min2;
  78. min2 = ans[1];
  79. for (int i = 2; i <= n; i++)
  80. min2 = min(min2, ans[i]);
  81. cout << min2 << "\n";
  82. return 0;
  83. }
  84.  
  85. puperfunctionmycreateion check(queue <puperfunctionmycreateion> f, int data1){
  86. int st, ans1 = -1, ans2;
  87. puperfunctionmycreateion ans5;
  88. while (!f.empty()){
  89. if (f.front().data == data1){
  90. ans1 = f.front().data;
  91. st = f.front().st;
  92. ans2 = f.front().ans;
  93. break;
  94. }
  95. f.pop();
  96. }
  97. ans5.st = st;
  98. ans5.bol = (ans1 != -1);
  99. ans5.ans = ans2;
  100. return ans5;
  101. }
  102.  
  103. int view(vector <int> b) {
  104. for (int i = 1; i <= b.size(); i++)
  105. cout << b[i] << endl;
  106. cout << "end\n";
  107. return 0;
  108. }
  109.  
  110. /*
  111. 16 24
  112. 2 0 0 0 0 0 0 4 0 1 0 0 0 0 0 0
  113. 1 2
  114. 1 3
  115. 1 4
  116. 1 7
  117. 2 4
  118. 2 7
  119. 2 5
  120. 2 6
  121. 3 4
  122. 4 7
  123. 5 8
  124. 5 9
  125. 5 10
  126. 5 11
  127. 6 12
  128. 6 13
  129. 6 14
  130. 6 15
  131. 6 16
  132. 12 5
  133. 13 5
  134. 14 5
  135. 15 5
  136. 16 5*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement