結果
問題 |
No.3237 Find the Treasure!
|
ユーザー |
|
提出日時 | 2025-08-18 23:36:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 344 ms / 3,000 ms |
コード長 | 2,150 bytes |
コンパイル時間 | 2,304 ms |
コンパイル使用メモリ | 216,316 KB |
実行使用メモリ | 26,228 KB |
平均クエリ数 | 13.83 |
最終ジャッジ日時 | 2025-08-18 23:36:44 |
合計ジャッジ時間 | 11,615 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/fenwicktree.hpp> #include <atcoder/segtree.hpp> #include <atcoder/modint.hpp> #include <atcoder/dsu.hpp> #include <atcoder/lazysegtree.hpp> using namespace atcoder; using namespace std; using ll = long long; using ull = unsigned long long; template <class T> using max_heap = priority_queue<T>; template <class T> using min_heap = priority_queue<T, vector<T>, greater<>>; ll ll_min = numeric_limits<ll>::min(); ll ll_max = numeric_limits<ll>::max(); ll ALPHABET_N = 26; using mint = modint998244353; #define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++) #define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++) #define all(a) a.begin(), a.end() int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<pair<ll, ll>> uv(n - 1); vector<vector<ll>> g(n); rep(i, n - 1) { ll u, v; cin >> u >> v; u--, v--; uv[i] = {u, v}; g[u].push_back(v); g[v].push_back(u); } vector<ll> colors(n, -1); auto dfs = [&](auto &f, ll v, ll color) -> void { colors[v] = color; for (ll u : g[v]) { if (colors[u] == -1) { f(f, u, 1 - color); } } }; dfs(dfs, 0, 0); // 0だけで絞る cout << "?"; rep(i, n - 1) { auto [u, v] = uv[i]; if (colors[u] == 0) cout << " " << u + 1; else cout << " " << v + 1; } cout << endl; string s; cin >> s; ll tgt_c = (s == "Yes" ? 0 : 1); vector<ll> tgts; rep(i, n) { if (colors[i] == tgt_c) tgts.push_back(i); } sort(all(tgts)); tgts.erase(unique(all(tgts)), tgts.end()); ll l = 0, r = tgts.size(); while (r - l > 1) { ll m = (l + r) / 2; set<ll> st; for (ll i = l; i < m; i++) { st.insert(tgts[i]); } // Check if the current set of targets is valid cout << "?"; for (ll i = 0; i < n - 1; i++) { auto [u, v] = uv[i]; ll tgt_v = (colors[u] == tgt_c ? u : v); ll no_tgt_v = (colors[u] == tgt_c ? v : u); if (st.count(tgt_v)) { cout << " " << tgt_v + 1; } else { cout << " " << no_tgt_v + 1; } } cout << endl; cin >> s; if (s == "Yes") { r = m; } else { l = m; } } cout << "! " << tgts[l] + 1 << endl; return 0; }