結果
| 問題 |
No.3237 Find the Treasure!
|
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2025-08-15 23:45:31 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 357 ms / 3,000 ms |
| コード長 | 2,335 bytes |
| コンパイル時間 | 3,585 ms |
| コンパイル使用メモリ | 291,580 KB |
| 実行使用メモリ | 25,972 KB |
| 平均クエリ数 | 14.70 |
| 最終ジャッジ日時 | 2025-08-15 23:45:44 |
| 合計ジャッジ時間 | 13,079 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
bool query(vector<int>&v) {
cout << "?" << " ";
for (auto e : v)cout << e + 1 << " ";
cout << endl;
string s; cin >> s;
return s == "Yes";
}
template <class T, class F>
T binarySearch(T ok, T ng, const F &f) {
while (abs(ok - ng) > 1) {
T mid = (ok + ng) / 2;
(f(mid) ? ok : ng) = mid;
}
return ok;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n; cin >> n;
vector to(n, vector<int>());
vector<P>e(n - 1);
rep(i, n - 1) {
int u, v; cin >> u >> v;
u--, v--;
to[u].push_back(v);
to[v].push_back(u);
e[i] = { u,v };
}
vector<int>col(n, 0);
auto dfs = [&](auto &&self, int v, int p = -1)->void {
for (auto nv : to[v]) {
if (p == nv)continue;
col[nv] = 1 - col[v];
self(self, nv, v);
}
};
dfs(dfs, 0);
vector<int>v(n - 1);
rep(i, n - 1) {
if (col[e[i].first] == 0)v[i] = e[i].first;
else v[i] = e[i].second;
}
auto q0 = query(v);
if (!q0) {
rep(i, n)col[i] = 1 - col[i];
}// 0にあるのは確定した
vector<P>e2(n - 1);
{
set<int>st;//used0
rep(i, n - 1) {
int x = e[i].first, y = e[i].second;// 01
if (col[e[i].first] == 1)swap(x, y);
if (st.count(x)) x = y;
else st.insert(x);
e2[i] = { x,y };
}
e.swap(e2);
}
auto f = [&](const long long x)->bool {
vector<int>v(n - 1);
rep(i, n - 1) {
if (i <= x) v[i] = e[i].first;
else v[i] = e[i].second;
}
return query(v);
};
auto index = binarySearch(n - 1, -1, f);
int ans = e[index].first;
cout << "! " << ans + 1 << endl;
return 0;
}
kwm_t