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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define LOCAL
#ifdef LOCAL
#include "../debug/debug.h"
#else
#define debug(...)
#define debugArr(...)
#endif

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = long double;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define x first
#define y second
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend() 
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define ft front()
#define bk back()
#define rsz resize
#define ins insert
#define each(a,x) for(auto&a:x)

template<class T> bool ckmin(T& a, T b) { return b<a?a=b,1:0; }
template<class T> bool ckmax(T& a, T b) { return b>a?a=b,1:0; }
template<class T> int lwb(vector<T>& a, const T& b) { return int(lower_bound(all(a),b)-bg(a)); }
template<class T> int upb(vector<T>& a, const T& b) { return int(upper_bound(all(a),b)-bg(a)); }
template<class T> void remdup(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)),end(v)); }

template<int MOD, int RT> struct mint {
    static const int mod = MOD;
    static constexpr mint rt() { return RT; }
    int v; explicit operator int() const { return v; }
    mint() : v(0) {}
    mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
        if (v < 0) v += MOD; }
    bool operator==(const mint& o) const {
        return v == o.v; }
    friend bool operator!=(const mint& a, const mint& b) { 
        return !(a == b); }
    friend bool operator<(const mint& a, const mint& b) { 
        return a.v < b.v; }

    mint& operator+=(const mint& o) { 
        if ((v += o.v) >= MOD) v -= MOD; 
        return *this; }
    mint& operator-=(const mint& o) { 
        if ((v -= o.v) < 0) v += MOD; 
        return *this; }
    mint& operator*=(const mint& o) { 
        v = int((ll)v*o.v%MOD); return *this; }
    mint& operator/=(const mint& o) { return (*this) *= inv(o); }
    friend mint pow(mint a, ll p) {
        mint ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans; }
    friend mint inv(const mint& a) { assert(a.v != 0); 
        return pow(a,MOD-2); }
        
    mint operator-() const { return mint(-v); }
    mint& operator++() { return *this += 1; }
    mint& operator--() { return *this -= 1; }
    friend mint operator+(mint a, const mint& b) { return a += b; }
    friend mint operator-(mint a, const mint& b) { return a -= b; }
    friend mint operator*(mint a, const mint& b) { return a *= b; }
    friend mint operator/(mint a, const mint& b) { return a /= b; }
    friend ostream& operator<<(ostream& o, const mint& a) { return o << a.v; }
    friend istream& operator>>(istream& i, mint& a) {
        ll x; i >> x; a = x;
        return i; }
};

const int MOD = 998244353;
using mi = mint<MOD,5>;
using vmi = vector<mi>;
using pmi = pair<mi,mi>;
using vpmi = vector<pmi>;

const pi MOVES[] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

#ifdef LOCAL
mt19937_64 rng(0xabadbeef);
#else
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

ll randr(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rng); }

const int N = 2048;
const int INF = 1e9;
int d[N];
bool done[N];
vpi g[N];
int n, m;
string me;

int recv(int k) {
    int x = 0;
    rep(i,0,k) {
        cout << "?" << endl;
        cout.flush();
        int dig;
        cin >> dig;
        x = x*2+dig;
    }
    return x;
}

void send(int x, int k) {
    per(i,0,k) {
        int dig = (x >> i) & 1;
        cout << "+ " << dig << endl;
        cout.flush();
    }
}

int recv_v() { return recv(11); }
int recv_c() { return recv(9); }

void send_v(int x) { send(x, 11); }
void send_c(int x) { send(x, 9); }

void run() {
    int prv_dist = 0;
    priority_queue<pi, vpi, greater<pi>> pq;
    d[0]=0;
    rep(i,1,n) pq.emplace(INF, i);
    pq.emplace(0, 0);
    while (!pq.empty()) {
        auto [dist, v] = pq.top();
        if (done[v]) {
            pq.pop();
            continue;
        }
        int delta = dist - prv_dist;
        ckmin(delta, 501);
        int other_delta;
        if (me == "Algosia") {
            send_c(delta);
            other_delta = recv_c();
        }
        else {
            other_delta = recv_c();
            send_c(delta);
        }
        if (delta < other_delta || (delta == other_delta && me == "Algosia")) {
            send_v(v);
        }
        else {
            delta = other_delta;
            v = recv_v();
        }

        assert(delta <= 500);

        done[v] = 1;
        d[v] = prv_dist + delta;
        prv_dist = d[v];

        for (auto [dd, u] : g[v]) {
            if (ckmin(d[u], d[v] + dd)) {
                pq.emplace(d[u], u);
            }
        }
    }
    if (me == "Algosia") {
        cout << "! ";
        rep(i,0,n) {
            cout << d[i] << ' ';
        }
        cout.flush();
    }
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> me >> n >> m;

    rep(i,0,m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].eb(c, b);
        g[b].eb(c, a);
    }

    rep(i,0,N) d[i]=INF;

    run();


    return 0;
}