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
#include <iostream>
#include <set>
#include <queue>

using namespace std;

int main() {
    int A,B,C,a,b,c;
    cin>>A>>B>>C>>a>>b>>c;
    int tab[100001];
    for(int i=0; i<C+1; ++i) tab[i] = -1;
    set< pair< pair<int,int>, pair<int,int> > > S;
    queue< pair< pair<int,int>, pair<int,int> > > Q;
    Q.push(make_pair(make_pair(a,b),make_pair(c,0)));
    S.insert(Q.front());
    while(!Q.empty()) {
        pair< pair<int,int>, pair<int,int> > P;
        P = Q.front();
        int d,e,f,z;
        d = P.first.first;
        e = P.first.second;
        f = P.second.first;
        z = P.second.second;
        //cout<<d<<" "<<e<<" "<<f<<" "<<z<<endl;
        if(tab[d] == -1) tab[d] = z;
        if(tab[e] == -1) tab[e] = z;
        if(tab[f] == -1) tab[f] = z;
        pair< pair<int,int>, pair<int,int> > R[6];
        if(d+e <= B) {
            R[0] = make_pair(make_pair(0,d+e),make_pair(f,0));
        }
        else {
            R[0] = make_pair(make_pair(d+e-B,B),make_pair(f,0));
        }
        if(d+e <= A) {
            R[1] = make_pair(make_pair(d+e,0),make_pair(f,0));
        }
        else {
            R[1] = make_pair(make_pair(A,d+e-A),make_pair(f,0));
        }
        if(d+f <= C) {
            R[2] = make_pair(make_pair(0,e),make_pair(d+f,0));
        }
        else {
            R[2] = make_pair(make_pair(d+f-C,e),make_pair(C,0));
        }
        if(d+f <= A) {
            R[3] = make_pair(make_pair(d+f,e),make_pair(0,0));
        }
        else {
            R[3] = make_pair(make_pair(A,e),make_pair(d+f-A,0));
        }
        if(e+f <= C) {
            R[4] = make_pair(make_pair(d,0),make_pair(e+f,0));
        }
        else {
            R[4] = make_pair(make_pair(d,e+f-C),make_pair(C,0));
        }
        if(e+f <= B) {
            R[5] = make_pair(make_pair(d,e+f),make_pair(0,0));
        }
        else {
            R[5] = make_pair(make_pair(d,B),make_pair(e+f-B,0));
        }
        for(int k=0; k<6; ++k)
        if(S.count(R[k]) == 0) {
            S.insert(R[k]);
            //cout<<R[k].first.first<<" "<<R[k].first.second<<" "<<R[k].second.first<<" "<<R[k].second.second<<endl;
            R[k].second.second = z+1;
            Q.push(R[k]);
        }
        Q.pop();
    }
    for(int i=0; i<C+1; ++i) cout<<tab[i]<<" ";
    cout<<endl;
    
    return 0;
}