UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196851#2663. 旅游wosile10020ms9428kbC++11547b2023-11-02 09:27:482023-11-02 12:03:43

answer

#include<bits/stdc++.h>
using namespace std;
int dep[300005];
vector<int>T[300005];
void dfs(int x,int fa){
	dep[x]=dep[fa]+1;
	for(int i=0;i<T[x].size();i++)if(T[x][i]!=fa)dfs(T[x][i],x);
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		T[u].push_back(v);
		T[v].push_back(u);
	}
	dep[0]=-1;
	dfs(1,0);
	int mx=0;
	for(int i=1;i<=n;i++)mx=max(mx,dep[i]);
	if(m>=2*n-2-mx)printf("%d",n);
	else if(m<=mx)printf("%d",m+1);
	else printf("%d",(m+mx)/2+1);
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 0ms
memory: 9424kb

input:

273 176
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

158

result:

ok single line: '158'

Test #2:

score: 5
Accepted
time: 0ms
memory: 9424kb

input:

280 245
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

194

result:

ok single line: '194'

Test #3:

score: 5
Accepted
time: 3ms
memory: 9424kb

input:

287 307
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

227

result:

ok single line: '227'

Test #4:

score: 5
Accepted
time: 3ms
memory: 9428kb

input:

294 322
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

236

result:

ok single line: '236'

Test #5:

score: 5
Accepted
time: 0ms
memory: 9424kb

input:

271 83
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1...

output:

84

result:

ok single line: '84'

Test #6:

score: 5
Accepted
time: 0ms
memory: 9424kb

input:

278 124
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

125

result:

ok single line: '125'

Test #7:

score: 5
Accepted
time: 0ms
memory: 9424kb

input:

285 350
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

248

result:

ok single line: '248'

Test #8:

score: 5
Accepted
time: 4ms
memory: 9424kb

input:

292 544
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

292

result:

ok single line: '292'

Test #9:

score: 5
Accepted
time: 0ms
memory: 9428kb

input:

299 437
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

295

result:

ok single line: '295'

Test #10:

score: 5
Accepted
time: 0ms
memory: 9428kb

input:

276 531
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

276

result:

ok single line: '276'

Test #11:

score: 5
Accepted
time: 3ms
memory: 9424kb

input:

283 18
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1...

output:

19

result:

ok single line: '19'

Test #12:

score: 5
Accepted
time: 0ms
memory: 9428kb

input:

290 363
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

256

result:

ok single line: '256'

Test #13:

score: 5
Accepted
time: 0ms
memory: 9424kb

input:

297 127
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

128

result:

ok single line: '128'

Test #14:

score: 5
Accepted
time: 0ms
memory: 9424kb

input:

274 49
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1...

output:

50

result:

ok single line: '50'

Test #15:

score: 5
Accepted
time: 3ms
memory: 9428kb

input:

281 397
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

271

result:

ok single line: '271'

Test #16:

score: 5
Accepted
time: 0ms
memory: 9424kb

input:

288 15
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1...

output:

16

result:

ok single line: '16'

Test #17:

score: 5
Accepted
time: 4ms
memory: 9424kb

input:

295 350
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

251

result:

ok single line: '251'

Test #18:

score: 5
Accepted
time: 0ms
memory: 9424kb

input:

272 218
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

179

result:

ok single line: '179'

Test #19:

score: 5
Accepted
time: 0ms
memory: 9424kb

input:

279 541
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

279

result:

ok single line: '279'

Test #20:

score: 5
Accepted
time: 0ms
memory: 9428kb

input:

286 149
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
...

output:

148

result:

ok single line: '148'