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
#include <bits/stdc++.h>

using namespace std;

int n, m;
bool algosia = false;
vector<pair<int, int>> graph[2001];
int distances[2001];

void sendV(int v, int len)
{
    for (int i = 0; i < len; ++i)
    {
        cout << "+ " << (v & 1) << endl;
        v /= 2;
    }
}

int readV(int len)
{
    int v = 0;
    for (int i = 0; i < len; ++i)
    {
        cout << "?" << endl;
        int b;
        cin >> b;

        if (b) v |= (1 << i);
    }
    return v;
}

void printAnswer()
{
    cout << "! ";

    for (int i = 1; i <= n; ++i) cout << distances[i] << ' ';
    cout << endl;
}

void Dijkstra()
{
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> current;
    current.emplace(0, 1);
    int lastD = 0;

    for (int i = 0; i < n; ++i)
    {
        while (!current.empty() && distances[current.top().second] != -1) current.pop();
        int d = 0, node = -1;

        if (current.empty()) d = (1 << 10) - 1;
        else d = current.top().first - lastD;

        sendV(d, 9);
        int otherD = readV(9);

        if ((algosia && d <= otherD) || d < otherD)
        {
            sendV(current.top().second, 11);
            node = current.top().second;
            current.pop();
        }
        else
        {
            node = readV(11);
            d = otherD;
        }

        distances[node] = d + lastD;
        lastD = distances[node];

        for (auto [child, c] : graph[node])
        {
            if (distances[child] == -1)
                current.emplace(distances[node] + c, child);
        }
    }
}

void Algosia()
{
    algosia = true;
    cin >> n >> m;

    for (int i = 0; i < m; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;

        graph[a].emplace_back(b, c);
        graph[b].emplace_back(a, c);
    }

    for (int i = 1; i <= n; ++i) distances[i] = -1;

    Dijkstra();

    printAnswer();
}

void Bajtek()
{
    algosia = false;
    cin >> n >> m;

    for (int i = 0; i < m; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;

        graph[a].emplace_back(b, c);
        graph[b].emplace_back(a, c);
    }

    for (int i = 1; i <= n; ++i) distances[i] = -1;

    Dijkstra();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    string role;
    cin >> role;

    if (role == "Algosia")
        Algosia();
    else if (role == "Bajtek")
        Bajtek();
    else
        return 1;
}