Advertisement
Dennnhhhickk

Untitled

Jan 5th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 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. };
  12.  
  13. int main()
  14. {
  15. puperfunctionmycreateion temp, temp1;
  16. int n, m, free = -1, v, u, h;
  17. vector <int> a, head, ans, next, dest;
  18. queue <puperfunctionmycreateion> q;
  19. cin >> n >> m;
  20. head.reserve(100000);
  21. a.reserve(100000);
  22. ans.reserve(100000);
  23. dest.reserve(100000);
  24. next.reserve(100000);
  25. head.resize(n);
  26. ans.resize(n);
  27. a.resize(n);
  28. for (int i = 1; i <= n; i++){
  29. next[i] = 0;
  30. ans[i] = INT_MAX - 20;
  31. cin >> a[i];
  32. if (a[i] != 0){
  33. temp.data = i;
  34. temp.st = i;
  35. temp.ans = 0;
  36. temp.prev = 0;
  37. q.push(temp);
  38. }
  39. }
  40. for (int i = 1; i <= m; i++){
  41. cin >> v >> u;
  42. free++;
  43. dest.resize(free + 1);
  44. next.resize(free + 1);
  45. dest[free] = u;
  46. next[free] = head[v];
  47. head[v] = free;
  48. free++;
  49. dest[free] = v;
  50. next[free] = head[u];
  51. head[u] = free;
  52. }
  53. h = head[3];
  54. while (h){
  55. cout << " " << dest[h] << endl;
  56. h = next[h];
  57. }
  58. cin >> h;
  59. while (!q.empty()){
  60. temp = q.front();
  61. h = head[temp.data];
  62. while (h){
  63. if (dest[h] != temp.prev)
  64. if (a[dest[h]] == 0){
  65. temp1.data = dest[h];
  66. temp1.st = temp.st;
  67. temp1.ans = temp.ans + 1;
  68. temp1.prev = temp.data;
  69. q.push(temp1);
  70. }
  71. else
  72. if (a[dest[h]] != a[temp.st]){
  73. //cout << q.size() << endl;
  74. ans[dest[h]] = min(ans[dest[h]], temp.ans + 1);
  75. }
  76. h = next[h];
  77. cout << " " << q.size() << endl;
  78. }
  79. cout << q.size() << endl;
  80. q.pop();
  81. }
  82. int min2;
  83. min2 = ans[1];
  84. for (int i = 2; i <= n; i++)
  85. min2 = min(min2, ans[i]);
  86. cout << min2 << "\n";
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement