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
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define JOIN_(X, Y) X##Y
#define JOIN(X, Y) JOIN_(X, Y)
#define TMP JOIN(tmp, __LINE__)
#define PB push_back
#define SZ(x) int((x).size())
#define REP(i, n) for (int i = 0, TMP = (n); i < TMP; ++i)
#define FOR(i, a, b) for (int i = (a), TMP = (b); i <= TMP; ++i)
#define FORD(i, a, b) for (int i = (a), TMP = (b); i >= TMP; --i)

#ifdef DEBUG
#define DEB(x) (cerr << x)
#else
#define DEB(x)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef unsigned int uint;

const int MAX_N = 2000;
const int MAX_WEIGHT = 501;
const int MAX_DIST = MAX_N * MAX_WEIGHT + 1;

struct Elem {
  int target, dist;
  bool operator<(const Elem &other) const {
    if (dist == other.dist) {
      return target > other.target;
    }
    return dist > other.dist;
  }

  friend std::ostream &operator<<(std::ostream &os, const Elem &e) {
    os << "Elem{ target: " << e.target << ", dist: " << e.dist << " }";
    return os;
  }
};

void transmit(int value, int bits) {
  REP(i, bits) {
    int bit = (value >> i) & 1;
    cout << "+ " << bit << "\n";
    cout.flush();
  }
}

int receive(int bits) {
  int value = 0;
  REP(i, bits) {
    cout << "?\n";
    cout.flush();
    int bit;
    cin >> bit;
    value |= (bit << i);
  }
  return value;
}

struct Case {
  int dist[MAX_N + 1] = {};
  vector<pii> adj[MAX_N + 1];
  void solve() {
    string person;
    cin >> person;
    int n, m;
    cin >> n >> m;
    FOR(i, 1, n) { dist[i] = MAX_DIST; }
    int start = 1;
    dist[start] = 0;
    REP(i, m) {
      int a, b, weight;
      cin >> a >> b >> weight;
      adj[a].PB({b, weight});
      adj[b].PB({a, weight});
    }
    priority_queue<Elem> q;
    q.push({start, 0});
    REP(i, n) {
      Elem local;
      if (q.empty()) {
        local = Elem({0, MAX_DIST});
      } else {
        local = q.top();
      }
      if (local.target != 0 and local.dist > dist[local.target]) {
        q.pop();
        continue;
      }
      DEB(person << " i=" << i << " local=" << local << "\n");

      transmit(local.target, 11);
      transmit(local.dist, 20);
      int remote_target = receive(11);
      int remote_dist = receive(20);
      Elem remote = Elem({remote_target, remote_dist});
      DEB(person << " i=" << i << " remote=" << local << "\n");

      Elem current;
      if (local < remote) {
        current = remote;
      } else {
        current = local;
        if (current.target != 0) {
          q.pop();
        }
      }
      DEB(person << " i=" << i << " current=" << local << "\n");

      int x = current.target;
      for (auto &edge : adj[x]) {
        int y = edge.first;
        int weight = edge.second;
        int new_dist = current.dist + weight;
        if (new_dist < dist[y]) {
          dist[y] = new_dist;
          q.push({y, new_dist});
        }
      }
    }
    if (person[0] == 'A') {
      cout << "! ";
      DEB("wynik:\n");
      FOR(i, 1, n) {
        cout << dist[i] << " ";
        DEB(dist[i] << " ");
      }
      DEB("\n");
      cout << "\n";
      cout.flush();
    }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int z = 1;
  // cin >> z;
  while (z--) {
    Case().solve();
  }
}