1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 #include #include #include #include #include using namespace std; set> sym_opcji(int A, int B, int C, int a, int b, int c) { set> res; // dodanie do A if (a + b > A) { res.emplace(A, a+b - A, c); } else { res.emplace(a + b, 0, c); } // dokad + skad > dokad if ( a + c > A){ res.emplace(A, b, a + c - A); } else { res.emplace(a + c, b, 0); } if (b + a > B) { res.emplace(a + b - B, B, c); } else { res.emplace(0, a + b, c); } if ( b + c > B){ res.emplace(a, B, b + c - B); } else { res.emplace(a, b + c, 0); } if (c + a > C) { res.emplace(a + c - C, b, C); } else { res.emplace(0, b, c + a); } if ( c + b > C){ res.emplace(a, b + c - C, C); } else { res.emplace(a, 0, b + c); } return res; } void bfs(vector& result, int A, int B, int C, int a, int b, int c) { queue> done; done.push({a,b,c}); set> seen; queue q; int how_many_act_layer = 1; int how_many_next_layer = 0; seen.insert(done.front()); int step = 0; int how_many_do_we_have = 0; tuple act_val; while (!done.empty() && how_many_do_we_have <= C) { auto [l,m,n] = done.front(); // cout << l << " " << m << " " << n << " " << step <<'\n'; done.pop(); seen.insert({l,m,n}); if (result[l] == -1) { how_many_do_we_have++; result[l] = step; } if (result[m] == -1) { how_many_do_we_have++; result[m] = step; } if (result[n] == -1) { how_many_do_we_have++; result[n] = step; } how_many_act_layer--; int temp = 0; auto options = sym_opcji(A,B,C,l,m,n); for (auto possibility: options) { if (seen.find(possibility) == seen.end()) { temp++; done.push(possibility); } } if (how_many_act_layer == 0) { step++; how_many_act_layer = how_many_next_layer + temp; how_many_next_layer = 0; } else { how_many_next_layer += temp; } } // cout << "how" << how_many_do_we_have; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int A, B, C, a, b, c; cin >> A >> B >> C >> a >> b >> c; // auto o = sym_opcji(A, B, C, 2, 5, 3); // for (auto [l,k,m]: o) { // cout << l << " " << k << " " << m << '\n'; // } vector res(C + 1, -1); bfs(res, A,B,C,a,b,c); for (int i =0; i < C + 1; ++i) { cout << res[i] << " "; } }