QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201645#5157. High-quality TreeDreamOn#WA 114ms26680kbC++23958b2023-10-05 15:48:092023-10-05 15:48:09

Judging History

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

  • [2023-10-05 15:48:09]
  • 评测
  • 测评结果:WA
  • 用时:114ms
  • 内存:26680kb
  • [2023-10-05 15:48:09]
  • 提交

answer

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),i##z=(b);i<=i##z;i++)
using namespace std;
const int N=int(2e5)+10;

vector<int> c[N]; vector<int> lst[N]; int dis[N],n;

void addE(int u,int v){ c[u].push_back(v),c[v].push_back(u); }

void dfs(int p,int fa=0){
	dis[p]=dis[fa]+1,lst[dis[p]].push_back(p);
	for(int v:c[p]) if(!dis[v]) dfs(v,p);
}
int gsize(int p){ return c[p].size()+(p==1)-1; }
int dfs2(int p,int rest){
	if(rest<0) return 0;
	int cnt=1;
	for(int v:c[p]) if(dis[v]>dis[p]) cnt+=dfs2(v,rest-1);
	return cnt;
}

int main(){
	cin>>n; for(int i=1,u,v;i<n;i++) cin>>u>>v,addE(u,v); dfs(1);
	int lp=0,ans=0,cnt[3]; memset(cnt,0,sizeof(cnt));
	FOR(i,1,n) if(lst[i].size() == (1<<(i-1))) lp=max(lp,i);
	ans=(1<<lp)-1;
	for(int p:lst[lp]) cnt[gsize(p)]++;
	if(cnt[0])
		for(int p:lst[lp])
			ans+=dfs2(p,min(1,gsize(p)))-1;
	else
		for(int p:lst[lp])
			ans+=dfs2(p,gsize(p))-1;
	cout<<n-ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 13100kb

input:

6
1 2
1 3
3 4
3 5
5 6

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 3ms
memory: 13040kb

input:

12
1 2
2 3
3 4
3 5
1 6
6 7
7 8
7 9
9 10
6 11
11 12

output:

3

result:

ok single line: '3'

Test #3:

score: -100
Wrong Answer
time: 114ms
memory: 26680kb

input:

200000
167246 158246
40931 40296
178588 27974
35171 899
4204 163250
101422 9230
55420 93371
16012 140142
28866 154497
33519 180725
50361 52348
46923 175364
126599 169575
15138 34958
164256 64770
63123 130169
154172 168301
127476 54744
199964 81879
173765 69220
178225 73653
59861 46415
138112 17507
8...

output:

100000

result:

wrong answer 1st lines differ - expected: '199998', found: '100000'