#include using namespace std; typedef long long LL; typedef long double LD; typedef unsigned long long ULL; typedef vector VI; typedef vector VLL; typedef set SI; typedef pair PII; typedef pair PLL; typedef vector VPII; typedef vector VPLL; const int INF = 1000000001; const LD EPS = 1e-9; const int MOD = 1000000007; const LL LLINF = 1000000000000000001; #define FOR(i, b, e) for(int i = b; i <= e; i++) #define FORD(i, b, e) for(int i = b; i >= e; i--) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define DPRINT(x) cout << #x << ": " << x << endl #define BOOST ios_base::sync_with_stdio(false); cin.tie(0) #define MP make_pair #define PB push_back #define ST first #define ND second //////////////////////////////////////////////////////////////// const int maxn = 142; VI gr[maxn]; int deg[maxn]; int N, D; int extraleaf; int board[maxn]; VPII defendMoves; bool dfsdefend(int a, int goal, int o) { if (a == goal) return true; for (auto i : gr[a]) if (i != o) { if(dfsdefend(i, goal, a)) { defendMoves.PB({a, i}); return true; } } return false; } void handlemove() { int x; cin >> x; while(x--) { int a, b; cin >> a >> b; a++; b++; board[a]--; board[b]++; } } void checkwin() { FOR(i, 1, N) { if (!board[i]) { bool good = true; for (auto j : gr[i]) if (board[j]) good = false; if (good) { cout << i-1 << endl; exit(0); } } } } void defend() { cout << "DEFEND" << endl; int printed = 0; FOR(i, 1, N) { if(SIZE(gr[i]) > 1) { board[i] = true; printed++; cout << i-1 << ' '; } } FOR(i, 1, N) { if(printed < D && !board[i]) { board[i] = true; extraleaf = i; printed++; cout << i-1 << ' '; } } cout << endl; while(true) { int attacked; cin >> attacked; attacked++; if (attacked == -1) exit(0); defendMoves.clear(); if (!board[attacked]) { dfsdefend(extraleaf, attacked, -1); board[attacked] = true; board[extraleaf] = false; extraleaf = attacked; } cout << SIZE(defendMoves) << ' '; for (auto p: defendMoves) { cout << p.first - 1 << ' ' << p.second - 1 << ' '; } cout << endl; } } int pickroot() { FOR(i, 1, N) { if(SIZE(gr[i]) > 1 && !board[i]) return i; } return -1; } int o[maxn]; int notleafc[maxn]; void dfsprepare(int a, int lo) { o[a] = lo; if (SIZE(gr[a]) > 1) notleafc[a]++; for(auto i : gr[a]) if (i != o[a]) { dfsprepare(i, a); notleafc[a] += notleafc[i]; } } int toattack; int boardcount[maxn]; int newroot; bool dfsattack(int a) { boardcount[a] = board[a]; for (auto i : gr[a]) if (i != o[a]) { if (dfsattack(i)) return true; boardcount[a] += boardcount[i]; } if(!board[a] && boardcount[a] <= notleafc[a]) { newroot = a; int toattack = a; while(SIZE(gr[toattack]) > 1) { if(gr[toattack][0] == o[toattack]) toattack = gr[toattack][1]; else toattack = gr[toattack][0]; } return true; } return false; } void attack() { cout << "ATTACK" << endl; FOR(i, 1, D) { int d; cin >> d; d++; board[d] = true; } checkwin(); int root = pickroot(); if (root == -1) { FOR(i, 1, N) { if (!board[i]) { cout << i-1 << endl; break; } } handlemove(); root = pickroot(); } dfsprepare(root, -1); while(true) { checkwin(); dfsattack(root); cout << toattack-1 << endl; root = newroot; handlemove(); } } int main() { BOOST; cin >> N >> D; FOR(i, 1, N-1) { int a, b; cin >> a >> b; a++; b++; gr[a].PB(b); gr[b].PB(a); } int deg3 = 0; FOR(i, 1, N) if (SIZE(gr[i]) > 1) deg3++; if (D >= deg3 + 1) defend(); else attack(); }