結果
問題 |
No.3237 Find the Treasure!
|
ユーザー |
![]() |
提出日時 | 2025-08-15 22:56:58 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 358 ms / 3,000 ms |
コード長 | 3,994 bytes |
コンパイル時間 | 3,271 ms |
コンパイル使用メモリ | 290,848 KB |
実行使用メモリ | 25,972 KB |
平均クエリ数 | 16.00 |
最終ジャッジ日時 | 2025-08-15 22:57:10 |
合計ジャッジ時間 | 12,454 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 |
ソースコード
// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using ld = long double; template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>; template<class T> using VVV = V<VV<T>>; template<class T> using VVVV = VV<VV<T>>; #define rep(i,n) for(ll i=0ll;(i)<(n);(i)++) #define REP(i,a,n) for(ll i=(a);(i)<(n);(i)++) #define rrep(i,n) for(ll i=(n)-1;(i)>=(0ll);(i)--) #define RREP(i,a,n) for(ll i=(n)-1;(i)>=(a);(i)--) const long long INF = (1LL << 60); const long long mod99 = 998244353; const long long mod107 = 1000000007; const long long mod = mod99; #define eb emplace_back #define be(v) (v).begin(),(v).end() #define all(v) (v).begin(),(v).end() #define foa(i,v) for(auto& (i) : (v)) #define UQ(v) sort(be(v)), (v).erase(unique(be(v)), (v).end()) #define UQ2(v,cmp) sort(be(v)), (v).erase(unique(be(v),cmp), (v).end()) #define UQ3(v,cmp) sort(be(v),cmp), (v).erase(unique(be(v)), (v).end()) #define UQ4(v,cmp,cmp2) sort(be(v), cmp), (v).erase(unique(be(v),cmp2), (v).end()) #define LB(x,v) (lower_bound(be(v),(x))-(v).begin()) #define LB2(x,v,cmp) (lower_bound(be(v),(x),(cmp))-(v).begin()) #define UB(x,v) (upper_bound(be(v),(x))-(v).begin()) #define UB2(x,v,cmp) (upper_bound(be(v),(x),(cmp))-(v).begin()) #define dout() cout << fixed << setprecision(20) #define randinit() srand((unsigned)time(NULL)) template<class T, class U> bool chmin(T& t, const U& u) { if (t > u){ t = u; return 1;} return 0; } template<class T, class U> bool chmax(T& t, const U& u) { if (t < u){ t = u; return 1;} return 0; } ll Rnd(ll L=0, ll R=mod99){return rand()%(R-L)+L;} void solve(){ ll n; cin >> n; V<ll> u(n-1), v(n-1); VV<ll> G(n); rep(i, n-1){ cin >> u[i] >> v[i]; u[i]--; v[i]--; G[u[i]].eb(v[i]); G[v[i]].eb(u[i]); } V<ll> dist(n, INF); dist[0] = 0; queue<ll> que; que.push(0); while(!que.empty()){ ll nd = que.front(); que.pop(); for(auto nx:G[nd]) if(chmin(dist[nx], dist[nd]+1)) que.push(nx); } V<ll> x(n-1); V<ll> pos(n, 1); auto query = [&]() -> bool { cout << "?"; for(auto val:x) cout << " " << val+1; cout << endl; string s; cin >> s; if(s[0] == 'Y'){ V<ll> tmp(n, 0); for(auto val:x) tmp[val] = 1; rep(i, n) pos[i] &= tmp[i]; return 1; }else{ for(auto val:x) pos[val] = 0; } return s[0] == 'Y'; }; rep(i, n-1) if(dist[u[i]]%2) swap(u[i], v[i]); V<ll> ord(n-1); rep(i, n-1) ord[i] = i; auto shuf = [&]() -> void { rep(i, n-2) swap(ord[i], ord[Rnd(i, n-1)]); }; for(ll q=14; q >= 0; q--){ ll rest = 0; for(auto x:pos) rest += x; V<ll> see(n, 0); rep(i, n-1){ x[i] = u[i]; see[x[i]]++; } ll use = 0; rep(i, n) use += (see[i] > 0) and (pos[i] == 1); if(use > (rest+1)/2){ rep(i, n-1){ swap(u[i], v[i]); } see.assign(n, 0); rep(i, n-1){ x[i] = u[i]; see[x[i]]++; } use = 0; rep(i, n) use += (see[i] > 0) and (pos[i] == 1); } rep(i, n-1) if(use < (rest+1)/2){ if(see[x[i]] > 1 or pos[x[i]] == 0){ see[x[i]]--; x[i] = v[i]; see[x[i]] ++; if(see[x[i]] == 1 and pos[x[i]]) use++; } } // cout << rest << " " << use << endl; query(); } ll ans = 0; while(!pos[ans]) ans++; cout << "! " << ans+1 << endl; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t=1; // cin >> t; rep(i,t) solve(); }