//vsp #include #define cat(x) cerr << #x << " = " << x << "\n"; #define rep(i, a, b) for (int i = (a); i < (b); i++) #define per(i, a, b) for (int i = (b) - 1; (a) <= i; i--) #define FOR(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) #define pb push_back using ll = long long; using namespace std; const int N = 404; int n, d, deg[N], rep[N], where[N]; vector e[N]; vector groups[N]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> d; FOR(i, n - 1) { int a, b; cin >> a >> b; e[a].pb(b); e[b].pb(a); deg[a]++; deg[b]++; } queue q; rep(i, 0, n) if (deg[i] == 1) q.push(i); while (!q.empty()) { int u = q.front(); q.pop(); for (auto v : e[u]) { if (rep[u] == 0 && rep[v] == 0) { rep[u] = v; rep[v] = v; } else if (rep[u] == 0 && rep[v] > 0) { rep[u] = v; } else if (rep[u] == u && rep[v] == 0) { rep[v] = u; } deg[v]--; if (deg[v] == 1) q.push(v); } } rep(i, 0, n) { if (rep[i] == i) groups[rep[i]].pb(i); } rep(i, 0, n) { if (rep[i] != i) groups[rep[i]].pb(i); } int cnt = 0; rep(i, 0, n) { if (rep[i] == i) { assert(sz(groups[i]) > 1); if (sz(groups[i]) == 2) cnt++; else cnt += 2; } } if (d >= cnt) { cout << "DEFEND" << endl; int nr = 0; rep(i, 0, n) { if (rep[i] == i) { where[nr] = i; nr++; if (sz(groups[i]) > 1) { int u = groups[i][1]; where[nr] = u; nr++; } } } rep(i, 0, n) { rep(oh, 2, sz(groups[i])) { if (nr < d) { where[nr] = groups[i][oh]; nr++; } } } FOR(i, d) cout << where[i] << ' '; cout << endl; FOR(r, 365) { int id; cin >> id; if (id == -1) break; bool ok = 0; rep(i, 0, d) if (where[i] == id) ok = 1; vector> go; if (!ok) { rep(i, 0, d) if (where[i] == rep[id]) { go.emplace_back(where[i], id); where[i] = id; break; } rep(i, 0, d) if (where[i] != id && rep[where[i]] == rep[id]) { go.emplace_back(where[i], rep[id]); where[i] = rep[id]; break; } } cout << sz(go) << ' '; for (auto [a, b] : go) cout << a << ' ' << b << ' '; cout << endl; } } else { cout << "ATTACK" << endl; srand(time(0)); rep(i, 0, d) cin >> where[i]; FOR(r, 365) { auto good = [&](int u) { rep(i, 0, d) if (where[i] == u) return 0; for (auto v : e[u]) rep(i, 0, d) if (where[i] == v) return 0; return 1; }; rep(i, 0, n) { if (good(i)) { cout << i << endl; return 0; } } int ID = -1; rep(i, 0, n) { if (rep[i] == i) { int cnt = 0; rep(j, 0, d) cnt += rep[where[j]] == i; if (cnt < sz(groups[i])) { ID = i; if (rand() % 2) break; } } } assert(ID >= 0); int siz = groups[ID].size(); int best = -1; for (auto u : groups[ID]) { bool ok = 1; rep(i, 0, d) if (where[i] == u) ok = 0; if (ok == 0) continue; if (best == -1 || sz(e[best]) >= sz(e[u])) best = u; } assert(best != -1); cout << best << endl; int roz; cin >> roz; while (roz--) { int _1, _2; cin >> _1 >> _2; rep(i, 0, d) if (where[i] == _1) { where[i] = _2; break; } } } } return 0; }