intmain(){ cin >> n; set<int> s; for (int i = 1; i <= n - 1; i++) s.insert(i); for (int i = 2; i <= n; i++) { int tot = 0; for (int j = i; j <= n; j += i) { if (a[j]) continue; if (tot == 0) { tot = *s.begin(); s.erase(s.begin()); } a[j] = tot; } } for (int i = 2; i <= n; i++) printf("%d ", a[i]); return0; }
intmain(){ cin >> n >> x; set<int> st, used; for (int i = 1; i < (1 << n); i++) st.insert(i); int len = 0; while (!st.empty()) { int tot = *st.begin(); st.erase(st.begin()); while (used.count(tot ^ x) || tot == x) { if (st.empty()) break; tot = *st.begin(); st.erase(st.begin()); } if (used.count(tot ^ x) || tot == x) continue; a[++len] = tot; used.insert(tot); } printf("%d\n", len); for (int i = len; i >= 2; i--) a[i] ^= a[i - 1]; for (int i = 1; i <= len; i++) { printf("%d ", a[i]); } return0; }
int mpdis[maxn], mpson[maxn]; intqd(int u){ if (mpdis[u] != -1) return mpdis[u]; cout << "d " << u << endl; int ans; cin >> ans; return mpdis[u] = ans; } intqs(int u){ if (mpson[u] != -1) return mpson[u]; cout << "s " << u << endl; int ans; cin >> ans; return mpson[u] = ans; } voidanswer(int u){ cout << "! " << u << endl; }
int n; vector<int> edge[maxn];
int dep[maxn], fa[maxn], siz[maxn], son[maxn], top[maxn]; vector<int> path[maxn]; voiddfs(int u, int f){ dep[u] = dep[f] + 1; fa[u] = f; siz[u] = 1; for (int& v: edge[u]) { if (v == f) continue; dfs(v, u); siz[u] += siz[v]; if (siz[v] > siz[son[u]]) son[u] = v; } } voiddfs(int u, int f, int tp){ top[u] = tp; path[tp].push_back(u); if (!son[u]) return ; dfs(son[u], u, tp); for (int& v: edge[u]) { if (v == f || v == son[u]) continue; dfs(v, u, v); } } voidinit(){ dfs(1, 0); dfs(1, 0, 1); } intqlca(int u, int v){ while (top[u] != top[v]) { if (dep[top[u]] < dep[top[v]]) swap(u, v); u = fa[top[u]]; } return dep[u] < dep[v] ? u : v; } intqdis(int u, int v){ return dep[u] + dep[v] - 2 * dep[qlca(u, v)]; }
int totd; intsolve(int u){ int d = path[u].back(); int d1 = dep[d] - dep[u]; // int d2 = qd(u); int d2 = totd; int d3 = qd(d); int dy = (d1 + d2 - d3) / 2; if (d2 == dy) return path[u][dy]; int y = path[u][dy]; totd -= dy + 1; returnsolve(qs(y)); }
intmain(){ ms(mpdis, -1); ms(mpson, -1); scanf("%d", &n); for (int i = 2, u, v; i <= n; i++) { scanf("%d%d", &u, &v); edge[u].push_back(v); edge[v].push_back(u); } init(); totd = qd(1); int r = solve(1); answer(r); return0; }