#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "lib/debug.h"
#else
#define debug(...) 228
#endif
typedef long long ll;
typedef long double ld;
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
vector<int> read_vec(int n) {
vector<int> v(n);
for (int& t : v) cin >> t;
return v;
}
template<typename T>
inline void upd_max(T& a, T b) {
if (a < b) {
a = b;
}
}
template<typename T>
inline void upd_min(T& a, T b) {
if (a > b) {
a = b;
}
}
const int maxN = 2005;
vector<pair<int,int>> g[maxN];
const int INF = 1e9;
int d[maxN];
bool was[maxN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
string who;
cin >> who;
int n, m;
cin >> n >> m;
int prv = 0;
FOR(i, 1, m + 1) {
int u, v, c;
cin >> u >> v >> c;
g[u].pb(make_pair(v, c));
g[v].pb(make_pair(u, c));
}
set<pair<int,int>> s;
FOR(i, 1, n + 1) d[i] = INF;
d[1] = 0;
FOR(i, 1, n + 1) {
s.emplace(d[i], i);
}
FOR(i, 1, n + 1) {
auto [w, x] = *s.begin();
assert(!was[x]);
assert(w >= prv);
int H = w - prv;
H = min(H, 511);
int otherH = 0;
if (who == "Algosia") {
FOR(res, 0, 9) {
cout << "+ " << ((H >> res) & 1) << endl;
}
FOR(res, 0, 9) {
cout << "? " << endl;
int resp;
cin >> resp;
otherH |= (resp << res);
}
}
else {
FOR(res, 0, 9) {
cout << "? " << endl;
int resp;
cin >> resp;
otherH |= (resp << res);
}
FOR(res, 0, 9) {
cout << "+ " << ((H >> res) & 1) << endl;
}
}
if (H < otherH || (H == otherH && who == "Algosia")) {
//we move
FOR(res, 0, 11) {
cout << "+ " << ((x >> res) & 1) << endl;
}
}
else {
//he moves
x = 0;
FOR(res, 0, 11) {
cout << "? " << endl;
int resp;
cin >> resp;
x |= (resp << res);
}
}
prv += min(H, otherH);
assert(prv <= w);
s.erase({d[x], x});
d[x] = prv;
assert(!was[x]);
was[x] = 1;
for (auto& [to, add] : g[x]) {
if (d[to] > d[x] + add) {
assert(!was[to]);
s.erase({d[to], to});
d[to] = d[x] + add;
s.insert({d[to], to});
}
}
}
if (who == "Algosia") {
cout << "! ";
FOR(i, 1, n + 1) cout << d[i] << " ";
cout << endl;
}
return 0;
}
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 | #ifdef DEBUG #define _GLIBCXX_DEBUG #endif //#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #ifdef DEBUG #include "lib/debug.h" #else #define debug(...) 228 #endif typedef long long ll; typedef long double ld; #define pb push_back #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) vector<int> read_vec(int n) { vector<int> v(n); for (int& t : v) cin >> t; return v; } template<typename T> inline void upd_max(T& a, T b) { if (a < b) { a = b; } } template<typename T> inline void upd_min(T& a, T b) { if (a > b) { a = b; } } const int maxN = 2005; vector<pair<int,int>> g[maxN]; const int INF = 1e9; int d[maxN]; bool was[maxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef DEBUG freopen("input.txt", "r", stdin); #endif string who; cin >> who; int n, m; cin >> n >> m; int prv = 0; FOR(i, 1, m + 1) { int u, v, c; cin >> u >> v >> c; g[u].pb(make_pair(v, c)); g[v].pb(make_pair(u, c)); } set<pair<int,int>> s; FOR(i, 1, n + 1) d[i] = INF; d[1] = 0; FOR(i, 1, n + 1) { s.emplace(d[i], i); } FOR(i, 1, n + 1) { auto [w, x] = *s.begin(); assert(!was[x]); assert(w >= prv); int H = w - prv; H = min(H, 511); int otherH = 0; if (who == "Algosia") { FOR(res, 0, 9) { cout << "+ " << ((H >> res) & 1) << endl; } FOR(res, 0, 9) { cout << "? " << endl; int resp; cin >> resp; otherH |= (resp << res); } } else { FOR(res, 0, 9) { cout << "? " << endl; int resp; cin >> resp; otherH |= (resp << res); } FOR(res, 0, 9) { cout << "+ " << ((H >> res) & 1) << endl; } } if (H < otherH || (H == otherH && who == "Algosia")) { //we move FOR(res, 0, 11) { cout << "+ " << ((x >> res) & 1) << endl; } } else { //he moves x = 0; FOR(res, 0, 11) { cout << "? " << endl; int resp; cin >> resp; x |= (resp << res); } } prv += min(H, otherH); assert(prv <= w); s.erase({d[x], x}); d[x] = prv; assert(!was[x]); was[x] = 1; for (auto& [to, add] : g[x]) { if (d[to] > d[x] + add) { assert(!was[to]); s.erase({d[to], to}); d[to] = d[x] + add; s.insert({d[to], to}); } } } if (who == "Algosia") { cout << "! "; FOR(i, 1, n + 1) cout << d[i] << " "; cout << endl; } return 0; } |
English