QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115637#4926. Where Is the Root?myrcella0 0ms0kbC++142.7kb2023-06-26 14:11:092023-06-26 14:11:10

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-26 14:11:10]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-06-26 14:11:09]
  • 提交

answer

// by szh
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

#define F first
#define S second
#define pii pair<LL, LL>
#define pb push_back
#define debug(x) cerr << #x << "=" << x << endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a; i < (b); i++)
#define MP make_pair
#define SZ(x) (static_cast<int>(x.size()))
#define MOD 1000000007
#define ALL(x) x.begin(), x.end()
void inc(int &a, int b) {a = (a+b)%MOD;}
void dec(int &a, int b) {a = (a-b+MOD)%MOD;}
int prod(int a,int b) {return LL(a)*LL(b)%MOD;}
int lowbit(int x) {return x&(-x);}

const int maxn = 555;

int n;
int deg[maxn];
vector <int> edge[maxn];

vector <int> leaf, candidate;

int main() {
  // freopen("input.txt","r",stdin);
  cin >> n;
  rep(i, 1, n) {
	int u, v;
	cin >> u >> v;
	edge[u].pb(v);
	edge[v].pb(u);
	deg[u]++;
	deg[v]++;
  }
  /*
  rep(i, 1, n + 1) {
	if (deg[i] == 1) continue;
	cout << "? " << n - 1;
    rep(j, 1, n + 1) if (i != j) cout << " " << j;
    cout << endl;
    cout.flush();
    string s;
    cin >> s;
    if (s == "NO") {
	  cout << "! " << i << endl;
	  cout.flush();
	  return 0;
	}
  }
  // root is a leaf
  rep(i, 1, n + 1) {
	if (deg[i] == 1) leaf.pb(i);
	else candidate.pb(i);
  }
  if (SZ(leaf) == 1) {
	cout << "! " << leaf[0] << endl;
  }
  for (auto it : leaf) {
	cout << "? " << SZ(leaf) - 1;
	for (auto itt : leaf) {
	  if (it == itt) continue;
	  cout << " " << itt;
	}
	cout << endl;
	string s;
	cin >> s;
	if (s == "NO") {
	  cout << "! " << it << endl;
	  return 0;
    }
  }
  */
  //idea: check leaves first, then go through non-leaf node
  
  cout << "? " << SZ(leaf);
  for (auto it : leaf) cout << " " << it;
  cout << endl;
  string s;
  cin >> s;
  if (s == "YES") {
	while (SZ(leaf) > 1) {
	  int mid = SZ(leaf) / 2;
	  cout << "? " << mid;
	  rep(i, 0, mid) cout << " " << leaf[i];
	  cout << endl;
	  string ss; cin >> ss;
	  if (ss == "YES") {
		while (SZ(leaf) > mid) leaf.pop_back();
	  }
	  else {
		vector <int> tmp;
		rep(i, mid, SZ(leaf)) tmp.pb(leaf[i]);
		leaf = tmp;
	  }
	}
	cout << "! " << leaf[0] << endl;
  } else {
	while (SZ(candidate) > 1) {
	  int mid = SZ(candidate)/2;
      cout << "? " << mid + SZ(leaf);
      for (auto it : leaf) cout << " " << it;
      rep(i, 0, mid) cout << " " << candidate[i];
      cout << endl;
      string ss; cin >> ss;
      if (ss == "YES") {
	    while (SZ(candidate) > mid) candidate.pop_back();
      }
      else {
	    vector <int> tmp;
	    rep(i, mid, SZ(candidate)) tmp.pb(candidate[i]);
	    candidate = tmp;
	  }
    }
    cout << "! " << candidate[0] << endl;
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

7
4 1
1 2
4 3
3 5
3 6
4 7

output:

? 0

result:


Subtask #2:

score: 0
Runtime Error

Test #24:

score: 0
Runtime Error

input:

30
1 15
29 30
1 4
7 28
29 17
1 26
26 7
12 5
27 13
3 7
27 1
21 15
9 22
22 5
24 27
19 1
25 30
22 27
6 15
16 13
18 2
27 10
27 30
20 26
8 15
18 8
14 1
27 23
11 3

output:

? 0

result:


Subtask #3:

score: 0
Runtime Error

Test #54:

score: 0
Runtime Error

input:

500
419 133
44 225
391 269
419 461
293 347
108 31
110 363
423 257
321 155
498 87
180 492
251 5
357 30
341 172
275 109
372 446
286 336
208 339
162 320
138 103
129 219
62 141
359 286
130 238
470 460
418 48
210 358
429 13
323 143
382 415
406 394
309 175
325 170
128 108
6 113
363 17
470 457
7 224
288 48...

output:

? 0

result: