QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#763376#1652. One PieceshuopihuaWA 2ms10696kbC++141.1kb2024-11-19 19:54:262024-11-19 19:54:28

Judging History

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

  • [2024-11-19 19:54:28]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10696kb
  • [2024-11-19 19:54:26]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int n,m;
int p[250005];
int h[250005];
vector <int> ans[3];
vector <int> g[250005];

inline void in(int &n){
	n=0;
	char c=getchar();
	while(c<'0' || c>'9') c=getchar();
	while(c>='0'&&c<='9') n=n*10+c-'0',c=getchar();
	return ;
}

inline void dfs(int u,int fa,int d){
	if(d<0) p[u]=-1e9;
	else if(d==0) h[++m]=u,p[u]++;
	for(int v:g[u]) if(v^fa) dfs(v,u,d-1);
	return ;
}

int main(){
	in(n);
	for(int i=1;i<n;i++){
		int u,v;
		in(u),in(v);
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	for(int i=1;i<=n;i++){
		int x;
		in(x);
		m=0;
		dfs(i,0,x);
		if(m==1) p[h[1]]=1e9;
	}
	for(int i=1;i<=n;i++)
		if(p[i]>n) ans[0].emplace_back(i);
		else if(p[i]>=0) ans[1].emplace_back(i);
		else ans[2].emplace_back(i);

	sort(ans[0].begin(),ans[0].end());
	sort(ans[1].begin(),ans[1].end(),[](int x,int y){return p[x]<p[y];});
	sort(ans[2].begin(),ans[2].end());
	for(int v:ans[0]) printf("%d ",v);
	for(int v:ans[1]) printf("%d ",v);
	for(int v:ans[2]) printf("%d ",v);

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 10696kb

input:

5
1 2
1 3
2 4
2 5
2 2 3 3 3

output:

3 1 2 4 5 

result:

wrong answer 1st lines differ - expected: '3 4 5 1 2', found: '3 1 2 4 5 '