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
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define p_b push_back
#define m_p make_pair
#define fi first
#define se second
 
const int maxn = 1000001;
ll mod = 1000000007;

void bfs(int pa, int pb, int pc, int a, int b, int c, vector<int> &resy){
    queue<vector<int>> que;
    map<vector<int>, bool> vis;
    map<vector<int>, int> dis;
    que.push({a, b, c});
    vis[{a, b, c}] = true;
    dis[{a, b, c}] = 0;
    while((int)que.size()){
        vector<int> t = que.front();
        que.pop();
        int da = dis[t];
        resy[t[0]] = min(resy[t[0]], da);
        resy[t[1]] = min(resy[t[1]], da);
        resy[t[2]] = min(resy[t[2]], da);
        int a = t[0], b = t[1], c = t[2];
        vector<int> ab = {a-min(a, pb-b), b+min(a, pb-b), c}, ac = {a-min(a, pc-c), b, c+min(a, pc-c)};
        vector<int> ba = {a+min(b, pa-a), b-min(b, pa-a), c}, bc = {a, b-min(b, pc-c), c+min(b, pc-c)};
        vector<int> ca = {a+min(c, pa-a), b, c-min(c, pa-a)}, cb = {a, b+min(c, pb-b), c-min(c, pb-b)};
        if(!vis[ab]){
            dis[ab] = da+1;
            vis[ab] = true;
            que.push(ab);
        }
        if(!vis[ac]){
            dis[ac] = da+1;
            vis[ac] = true;
            que.push(ac);
        }
        if(!vis[ba]){
            dis[ba] = da+1;
            vis[ba] = true;
            que.push(ba);
        }
        if(!vis[bc]){
            dis[bc] = da+1;
            vis[bc] = true;
            que.push(bc);
        }
        if(!vis[ca]){
            dis[ca] = da+1;
            vis[ca] = true;
            que.push(ca);
        }
        if(!vis[cb]){
            dis[cb] = da+1;
            vis[cb] = true;
            que.push(cb);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int pa, pb, pc, a, b, c; cin>>pa>>pb>>pc>>a>>b>>c;
    vector<int> resy(pc+1);
    for(int i = 0; i<=pc; i++)
        resy[i] = mod;

    bfs(pa, pb, pc, a, b, c, resy);
    for(auto i: resy){
        if(i==mod) cout<<-1<<" ";
        else cout<<i<<" ";
    }

}