結果
問題 |
No.3237 Find the Treasure!
|
ユーザー |
![]() |
提出日時 | 2025-08-15 22:26:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 332 ms / 3,000 ms |
コード長 | 2,644 bytes |
コンパイル時間 | 4,254 ms |
コンパイル使用メモリ | 257,708 KB |
実行使用メモリ | 26,212 KB |
平均クエリ数 | 13.83 |
最終ジャッジ日時 | 2025-08-15 22:26:43 |
合計ジャッジ時間 | 12,679 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using isize = size_t; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = long double; using p2 = pair<i64, i64>; using el = tuple<i64, i64, i64>; using mint = atcoder::modint998244353; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } i64 pow(i64 x, i64 n) { i64 res = 1; i64 t = x; while (n > 0) { if (n & 1) { res = res * t; } t = t * t; n >>= 1; } return res; } i64 pow(i64 x, i64 n, i64 m) { i64 res = 1; i64 t = x % m; while (n > 0) { if (n & 1) { res = res * t % m; } t = t * t % m; n >>= 1; } return res; } vector<p2> g[10000]; p2 edge[10000]; i64 dep[10000]; void dfs(i64 v, i64 par) { for (auto [nv, i] : g[v]) { if (nv == par) continue; dep[nv] = dep[v] + 1; if (dep[v] % 2 == 0) edge[i] = {v, nv}; else edge[i] = {nv, v}; dfs(nv, v); } } void _main() { i64 n; cin >> n; for (i64 i = 0; i < n - 1; i++) { i64 u, v; cin >> u >> v; u--, v--; g[u].push_back({v, i}); g[v].push_back({u, i}); } dep[0] = 0; dfs(0, -1); vector<bool> ng(n, false); { cout << "? "; for (i64 i = 0; i < n - 1; i++) { auto [u, v] = edge[i]; cout << u + 1 << " "; } cout << "\n"; cout.flush(); string s; cin >> s; if (s == "Yes") { for (i64 i = 0; i < n; i++) { if (dep[i] % 2 == 1) ng[i] = true; } } else { for (i64 i = 0; i < n; i++) { if (dep[i] % 2 == 0) ng[i] = true; } } } while (true) { vector<i64> v; for (i64 i = 0; i < n; i++) { if (!ng[i]) v.push_back(i); } if (v.size() == 1) break; i64 m = v.size() / 2; vector<i64> p(n, 0); for (i64 i = m; i < v.size(); i++) { p[v[i]] = 1; } cout << "? "; for (i64 i = 0; i < n - 1; i++) { auto [u, v] = edge[i]; assert(p[u] != 1 || p[v] != 1); if (p[u] == 1) { cout << v + 1 << " "; } else if (p[v] == 1) { cout << u + 1 << " "; } else if (!ng[u]) { cout << u + 1 << " "; } else { cout << v + 1 << " "; } } cout << "\n"; cout.flush(); string s; cin >> s; if (s == "Yes") { for (i64 i = m; i < v.size(); i++) ng[v[i]] = true; } else { for (i64 i = 0; i < m; i++) ng[v[i]] = true; } } for (i64 i = 0; i < n; i++) { if (!ng[i]) { cout << "! " << i + 1 << "\n"; cout.flush(); } } }