結果

問題 No.3237 Find the Treasure!
ユーザー cho435
提出日時 2025-08-15 23:10:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 343 ms / 3,000 ms
コード長 1,527 bytes
コンパイル時間 1,968 ms
コンパイル使用メモリ 205,436 KB
実行使用メモリ 26,228 KB
平均クエリ数 14.83
最終ジャッジ日時 2025-08-15 23:11:17
合計ジャッジ時間 10,666 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)

template <class T> bool chmin(T& x, T y) {
	return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
	return x < y ? (x = y, true) : false;
}

struct io_setup {
	io_setup() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} io_setup;

void solve() {
	int n;
	cin >> n;
	vector<int> u(n - 1), v(n - 1);
	rep(i, 0, n - 1) cin >> u[i] >> v[i], u[i]--, v[i]--;
	vector<vector<int>> g(n);
	rep(i, 0, n) {
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	vector<int> dist(n, 0);
	{
		auto dfs = [&](auto self, int nw, int pr) -> void {
			for (int nx : g[nw]) {
				if (nx == pr) continue;
				dist[nx] = dist[nw] + 1;
				self(self, nx, nw);
			}
		};
		dfs(dfs, 0, -1);
	}
	rep(i, 0, n - 1) {
		if (dist[u[i]] & 1) swap(u[i], v[i]);
	}
	{
		cout << "?";
		rep(i, 0, n - 1) cout << " " << v[i] + 1;
		cout << endl;
		string s;
		cin >> s;
		assert(s != "Invalid");
		if (s == "Yes") swap(u, v);
	}
	int up = n;
	int dw = 0;
	while (up - dw > 1) {
		int md = (up + dw) / 2;
		cout << "?";
		rep(i, 0, n - 1) {
			cout << " ";
			if (u[i] < md) cout << u[i] + 1;
			else cout << v[i] + 1;
		}
		cout << endl;
		string s;
		cin >> s;
		assert(s != "Invalid");
		if (s == "Yes") up = md;
		else dw = md;
	}
	cout << "! " << up << endl;
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) solve();
}
0