#include <bits/stdc++.h>
using namespace std;
int A, B, C;
int a, b, c, S;
int a1, b1, c1;
int t;
set<pair<int, int>> visited;
vector<int> res;
queue<pair<pair<int, int>, int>> q;
void add()
{
if (visited.find({a1, b1}) == visited.end())
{
// cout << a1 << ' ' << b1 << '\n';
q.push({{a1, b1}, t + 1});
visited.insert({a1, b1});
res[a1] = min(res[a1], t + 1);
res[b1] = min(res[b1], t + 1);
res[c1] = min(res[c1], t + 1);
}
}
void BFS(pair<int, int> r)
{
q.push({r, 0});
visited.insert(r);
res[a] = min(res[a1], 0);
res[b] = min(res[b1], 0);
res[c] = min(res[c1], 0);
while (!q.empty())
{
// cout << "xd";
t = q.front().second;
a = q.front().first.first;
b = q.front().first.second;
c = S - a - b;
q.pop();
// a -> b
a1 = max(0, a + b - B);
b1 = min(a + b, B);
c1 = S - a1 - b1;
add();
// b -> a
b1 = max(0, b + a - A);
a1 = min(b + a, A);
c1 = S - a1 - b1;
add();
// b -> c
b1 = max(0, b + c - C);
c1 = min(b + c, C);
a1 = S - b1 - c1;
add();
// c -> b
c1 = max(0, c + b - B);
b1 = min(c + b, B);
a1 = S - b1 - c1;
add();
// c -> a
c1 = max(0, c + a - A);
a1 = min(c + a, A);
b1 = S - c1 - a1;
add();
// a -> c
a1 = max(0, a + c - C);
c1 = min(a + c, C);
b1 = S - c1 - a1;
add();
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> A >> B >> C;
cin >> a >> b >> c;
res.assign(C + 1, INT_MAX);
S = a + b + c;
BFS({a, b});
for (auto &x : res)
{
if (x == INT_MAX)
cout << "-1 ";
else
cout << x << ' ';
}
}
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 | #include <bits/stdc++.h> using namespace std; int A, B, C; int a, b, c, S; int a1, b1, c1; int t; set<pair<int, int>> visited; vector<int> res; queue<pair<pair<int, int>, int>> q; void add() { if (visited.find({a1, b1}) == visited.end()) { // cout << a1 << ' ' << b1 << '\n'; q.push({{a1, b1}, t + 1}); visited.insert({a1, b1}); res[a1] = min(res[a1], t + 1); res[b1] = min(res[b1], t + 1); res[c1] = min(res[c1], t + 1); } } void BFS(pair<int, int> r) { q.push({r, 0}); visited.insert(r); res[a] = min(res[a1], 0); res[b] = min(res[b1], 0); res[c] = min(res[c1], 0); while (!q.empty()) { // cout << "xd"; t = q.front().second; a = q.front().first.first; b = q.front().first.second; c = S - a - b; q.pop(); // a -> b a1 = max(0, a + b - B); b1 = min(a + b, B); c1 = S - a1 - b1; add(); // b -> a b1 = max(0, b + a - A); a1 = min(b + a, A); c1 = S - a1 - b1; add(); // b -> c b1 = max(0, b + c - C); c1 = min(b + c, C); a1 = S - b1 - c1; add(); // c -> b c1 = max(0, c + b - B); b1 = min(c + b, B); a1 = S - b1 - c1; add(); // c -> a c1 = max(0, c + a - A); a1 = min(c + a, A); b1 = S - c1 - a1; add(); // a -> c a1 = max(0, a + c - C); c1 = min(a + c, C); b1 = S - c1 - a1; add(); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> A >> B >> C; cin >> a >> b >> c; res.assign(C + 1, INT_MAX); S = a + b + c; BFS({a, b}); for (auto &x : res) { if (x == INT_MAX) cout << "-1 "; else cout << x << ' '; } } |
English