結果
問題 |
No.3237 Find the Treasure!
|
ユーザー |
![]() |
提出日時 | 2025-08-15 22:25:21 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 326 ms / 3,000 ms |
コード長 | 2,319 bytes |
コンパイル時間 | 3,166 ms |
コンパイル使用メモリ | 292,856 KB |
実行使用メモリ | 25,972 KB |
平均クエリ数 | 14.78 |
最終ジャッジ日時 | 2025-08-15 22:26:30 |
合計ジャッジ時間 | 11,949 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; #define rep(i,n) for(ll i=0;i<n;++i) #define all(a) (a).begin(),(a).end() ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } template<class T> T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); } template<class T> T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); } template <typename T, typename U> inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template <typename T, typename U> inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; } void solve() { ll N; cin>>N; vector<vector<ll>> edge(N); vector<pair<ll,ll>> el; rep(i,N-1){ ll u,v; cin>>u>>v; u--; v--; edge[u].push_back(v); edge[v].push_back(u); el.push_back({u,v}); } vector<ll> color(N,-1); color[0]=0; stack<ll> st; st.push(0); while (st.size()>0){ ll cp=st.top();st.pop(); for (ll np:edge[cp]){ if (color[np]>=0)continue; color[np]=color[cp]^1; st.push(np); } } auto query=[](vector<ll> A){ cout<<"? "; for (auto a:A){ cout<<a+1<<' '; } cout<<endl; string S; cin>>S; assert (S!="Invalid"); return (S=="Yes"); }; vector<ll> C; for (auto &[a,b]:el){ if (color[a]==1){ swap(a,b); } C.push_back(a); } if (query(C)){ for (auto &[a,b]:el){ swap(a,b); } } ll l=0; ll r=N-1; while (r-l>1){ ll mid=(l+r)/2; vector<ll> C; rep(i,N-1){ if (l<=i and i<mid){ C.push_back(el[i].second); } else{ C.push_back(el[i].first); } } if (query(C)){ r=mid; } else{ l=mid; } } cout<<"! "<<el[l].second+1<<endl; return; } int main() { ll T=1; while (T--){ solve(); } return 0; }