Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int x0 = 1000;
- vector <int> flowww;
- set <int> was;
- vector <int> zeroes(x0, -1);
- int a[x0][x0];
- void bfs(int n) {
- vector <int> out;
- for (int i = flowww.size() - 1; i >= 0; ++i) {
- for (int j = 0; j < n; ++j) {
- if (a[flowww[i]][j] == 1 && was.find(j) == was.end()) {
- zeroes[j] = zeroes[flowww[i]] + 1;
- was.insert(j);
- out.emplace_back(j);
- }
- }
- }
- if (! out.empty()) {
- flowww = out;
- bfs(n);
- }
- }
- int main() {
- int x, y;
- cin >> x >> y;
- for (int i = 0; i < x; ++i) {
- for (int j = 0; j < x; ++j) {
- cin >> a[i][j];
- }
- }
- --y;
- flowww.push_back(y);
- for (auto z : flowww) {
- cout << z;
- }
- was.insert(y);
- zeroes[y] = 0;
- bfs(x);
- for (auto num : zeroes) {
- cout << num << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement