QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#79763#4815. Flower's LandhuzhaoyangWA 1ms4508kbC++141.5kb2023-02-20 21:15:262023-02-20 21:15:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-20 21:15:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4508kb
  • [2023-02-20 21:15:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=40005,M=3005;
int n,m,x,y,rt,a[N],vis[N],dfn[N],sz[N];
ll ans[N],fp[N][M],fs[N][M];
vector<int>e[N];
void get_sz(int k,int fa){
	sz[k]=1;
	for(int i:e[k])
		if ((!vis[i])&&(i!=fa))get_sz(i,k),sz[k]+=sz[i];
}
void get_rt(int k,int fa,int s){
	int mx=s-sz[k];
	for(int i:e[k])
		if ((!vis[i])&&(i!=fa))get_rt(i,k,s),mx=max(mx,sz[i]);
	if (mx<=(s>>1))rt=k;
}
void get_dfn(int k,int fa){
	dfn[++dfn[0]]=k,sz[k]=1;
	for(int i:e[k])
		if ((!vis[i])&&(i!=fa))get_dfn(i,k),sz[k]+=sz[i];
}
void dfs(int k){
	get_sz(k,0);
	if (sz[k]<m)return;
	get_rt(k,0,sz[k]),k=rt;
	dfn[0]=0,get_dfn(k,0);
	for(int i=1;i<=dfn[0]+1;i++){
		memset(fp[i],0,sizeof(fp[i]));
		memset(fs[i],0,sizeof(fs[i]));
	}
	for(int i=1;i<=dfn[0];i++){
		int I=dfn[i];
		for(int j=0;j<m;j++)fp[i+1][j+1]=max(fp[i+1][j+1],fp[i][j]+a[I]);
		for(int j=0;j<=m;j++)fp[i+sz[I]][j]=max(fp[i+sz[I]][j],fp[i][j]);
	}
	for(int i=dfn[0];i;i--){
		int I=dfn[i];
		for(int j=0;j<m;j++)fs[i][j]=max(fs[i][j],fs[i+1][j+1]+a[I]);
		for(int j=0;j<=m;j++)fs[i][j]=max(fs[i][j],fs[i+sz[I]][j]);
	}
	for(int i=1;i<=dfn[0];i++){
		int I=dfn[i];
		for(int j=0;j<m;j++)ans[I]=max(ans[I],fp[i][j]+fs[i+1][m-j-1]);
	}
	vis[k]=1;
	for(int i:e[k])
		if (!vis[i])dfs(i);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
}

详细

Test #1:

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

input:

5 3
6 10 4 3 4
3 4
4 2
2 5
5 1

output:


result:

wrong answer Answer contains longer sequence [length = 5], but output contains 0 elements