Why does this interactive code hang?

This code for yesterday’s “Where is the Root” always hangs. I used similar way to deal with interactive problems but never met this issue on Codeforces before.
Can anyone suggest why? (I know it is incorrect answer). Did I miss any setting?

#include <bits/stdc++.h>
using namespace std;
#define REP(i, e) for (int i = 0; i < (e); ++i) 
int __FAST_IO__ = []() {
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	return 0;
}();

int main() {
    srand(time(NULL));
    int N;
    cin >> N;
    REP(i, N - 1) {
        int u, v;
        cin >> u >> v;
        --u, --v;
    }
    
    vi v(N);
    REP(i, N) v[i] = i;
    while (!v.empty()) {
        int d = rand() % v.size();
        cout << "? " << N - 1;
        REP(i, N) if (i != v[d]) cout << " " << i + 1;
        cout << endl;
        cout.flush();
        string ans;
        cin >> ans;
        if (ans == "NO") {
            cout << "! " << v[d] + 1 << endl;
            cout.flush();
            return 0;
        }
        v.erase(v.begin() + d);
    }
    
    return 0;
}