Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ∧_∧
- ( ・ω・。)つ━☆・*。
- ⊂ ノ ・゜
- しーJ Accepted
- */
- // #pragma GCC optimize("O3")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define all(x) begin(x), end(x)
- #define x first
- #define y second
- // #define int long long
- using namespace std;
- using namespace __gnu_pbds;
- typedef long double ld;
- template<typename T>
- using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout << fixed << setprecision(14);
- #ifdef _offline
- // freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stderr);
- #endif
- }
- const int MAXN = 1e6 + 10;
- const int MAXM = 600;
- const int INF = 1e9 + 7;
- const int BASE = 47;
- const int MOD = 1e9 + 7;
- const int MAXLOG = 51;
- const ld EPS = 1e-6;
- vector<vector<int>> g;
- vector<int> op, lul;
- vector<int> used;
- int cur = 0, last;
- void dfs(int u, int p) {
- // euler.push_back(cur);
- last++;
- op[cur] = u;
- lul[u] = cur;
- cur++;
- for(auto v : g[u]) {
- if(v != p) {
- dfs(v, u);
- }
- }
- // euler.push_back(cur);
- }
- signed main() {
- seriy();
- int n;
- cin >> n;
- g.resize(n);
- used.resize(n);
- lul.resize(n);
- op.resize(n);
- for(int i = 0; i < n - 1; i++) {
- int u, v;
- cin >> u >> v;
- u--;
- v--;
- g[u].push_back(v);
- g[v].push_back(u);
- }
- // for(auto i : op) {
- // cout << i << " ";
- // }
- while(1) {
- char c;
- cin >> c;
- if(c == 'E') {
- break;
- }
- for(int i = 0; i < n; i++) {
- sort(all(g[i]), [&](int a, int b) {
- return used[a] > used[b] || used[a] == used[b] && a < b;
- });
- }
- last = 0;
- cur = 0;
- int first = 0;
- for(int i = 0; i < n; i++) {
- lul[i] = i;
- }
- for(int i = 0; i < n; i++) {
- sort(all(g[i]), [&](int a, int b) {
- return lul[a] < lul[b];
- });
- }
- dfs(0, -1);
- fill(all(used), 0);
- set<int> res;
- int CNT = 10;
- last = n;
- int lol = -1;
- while(CNT--) {
- // cerr << last << " " << lol << '\n' << '\n';
- // for(auto i : op) {
- // cerr << i << " " << used[i] << '\n';
- // }
- // cerr << '\n';
- // cerr << CNT << '\n';
- int cnt = 0;
- int pos_f = -1;
- for(int i = 0; i < n; i++) {
- if(op[i] == first) {
- pos_f = i;
- }
- }
- int l = -1, r = n;
- while(r - l > 1) {
- int mid = (r + l) >> 1;
- set<int> kek;
- for(int j = 0; j <= mid; j++) {
- kek.insert(op[j]);
- }
- // for(auto j : res) {
- // kek.insert(j);
- // }
- cout << "? " << kek.size() << " ";
- cnt++;
- for(auto i : kek) {
- // assert(i != -1);
- cout << i + 1 << " ";
- }
- cout << endl;
- int ans;
- cin >> ans;
- assert(ans != -1);
- if(!ans) {
- l = mid;
- }
- else {
- r = mid;
- }
- }
- // cerr << r << '\n';
- if(r < n) res.insert(op[r]);
- cur = 0;
- // g[op[r]].clear();
- if(lol > 0) {
- // cerr << lol << '\n';
- used[lol] = 1;
- // g[lol].clear();
- }
- else {
- first = lol;
- }
- for(int i = 0; i < n; i++) {
- sort(all(g[i]), [&](int a, int b) {
- return lul[a] < lul[b];
- });
- }
- lol = op[r];
- last = 0;
- fill(all(op), -1);
- if(used[lol]) {
- break;
- }
- dfs(lol, -1);
- // last =
- // used[{par[op[r]], op[r]}] = 1;
- }
- cout << "! " << res.size() << " ";
- for(auto i : res) {
- cout << i + 1 << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement