QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#72176#4926. Where Is the Root?MoQz0 11ms3464kbC++854b2023-01-14 19:22:332023-01-14 19:22:35

Judging History

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

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

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
int n;
int d[511],px[511];
bool cmp(int x,int y){
	return (d[x]<d[y]);
}
int main(){
	cin>>n;
	fo(i,1,n-1){
		int x,y;
		cin>>x>>y;
		++d[x],++d[y];
	}
	fo(i,1,n)px[i]=i;
	sort(px+1,px+n+1,cmp);
	int w=1;
	while(w<n&&d[px[w+1]]==1)++w;
	int l=1,r=n;
	char s[10];
	while(l<r&&r>2){
		int mid=(l+r)/2;
		cout<<"? "<<mid<<" ";
		fo(i,1,mid)cout<<px[i]<<" ";
		cout<<endl;
		cout.flush();
		cin>>s;
		if(s[0]=='N')l=mid+1;
		else r=mid;
	}
	cout<<l<<" "<<r<<endl;
	if(r==2){
		cout<<"? "<<n-1<<" ";
		fo(i,2,n)cout<<px[i]<<" ";
		cout<<endl;
		cout.flush();
		cin>>s;
		if(s[0]=='Y')l=2;
	}
	cout.flush();
	cout<<"! "<<px[l];
	cout.flush();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 3264kb

input:

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

output:

? 4 2 5 6 7 
? 6 2 5 6 7 1 3 
7 7
! 4

result:

wrong output format Unexpected end of file - int32 expected

Subtask #2:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 1ms
memory: 3464kb

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
YES
YES
NO
YES
YES

output:

? 15 2 28 25 24 23 21 20 19 17 16 14 12 11 10 9 
? 8 2 28 25 24 23 21 20 19 
? 4 2 28 25 24 
? 6 2 28 25 24 23 21 
? 5 2 28 25 24 23 
5 5
! 23

result:

wrong output format Unexpected end of file - int32 expected

Subtask #3:

score: 0
Wrong Answer

Test #54:

score: 0
Wrong Answer
time: 11ms
memory: 3204kb

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:

? 250 283 299 298 296 294 292 290 289 287 285 284 300 282 281 280 279 277 276 273 270 268 318 332 331 330 328 327 326 324 323 322 320 264 317 316 313 312 310 307 305 304 303 192 210 209 208 205 204 201 199 198 197 196 211 191 189 181 177 174 173 171 169 168 235 260 257 256 254 252 250 246 245 242 33...

result:

wrong output format Unexpected end of file - int32 expected