Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int x0 = 1000;
  6. vector <int> flowww;
  7. set <int> was;
  8. vector <int> zeroes(x0, -1);
  9. int a[x0][x0];
  10.  
  11. void bfs(int n) {
  12. vector <int> out;
  13. for (int i = flowww.size() - 1; i >= 0; ++i) {
  14. for (int j = 0; j < n; ++j) {
  15. if (a[flowww[i]][j] == 1 && was.find(j) == was.end()) {
  16. zeroes[j] = zeroes[flowww[i]] + 1;
  17. was.insert(j);
  18. out.emplace_back(j);
  19. }
  20. }
  21. }
  22. if (! out.empty()) {
  23. flowww = out;
  24. bfs(n);
  25. }
  26. }
  27.  
  28. int main() {
  29. int x, y;
  30. cin >> x >> y;
  31. for (int i = 0; i < x; ++i) {
  32. for (int j = 0; j < x; ++j) {
  33. cin >> a[i][j];
  34. }
  35. }
  36. --y;
  37. flowww.push_back(y);
  38. for (auto z : flowww) {
  39. cout << z;
  40. }
  41. was.insert(y);
  42. zeroes[y] = 0;
  43. bfs(x);
  44. for (auto num : zeroes) {
  45. cout << num << ' ';
  46. }
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement