QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#106118#6107. One Path1kriWA 3ms3636kbC++141.5kb2023-05-16 17:44:092023-05-16 17:44:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-16 17:44:11]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3636kb
  • [2023-05-16 17:44:09]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
void updmax(ll &x,ll y){
	if (y>x)x=y;
	return;
}
int n,k,u[4005],v[4005],w[4005],first[2005],nxt[4005];
int sz[2005];
ll f[2005][2005][3];
ll _f[2005][3];
void dfs(int now,int fa){
	sz[now]=1;
	for (int i=first[now];i;i=nxt[i]){
		if (v[i]==fa)continue;
		dfs(v[i],now);
		memset(_f,0,sizeof(_f));
		for (int j=0;j<sz[now];j++)
			for (int k=0;k<sz[v[i]];k++){
				updmax(_f[j+k+1][0],f[now][j][0]+w[i]+f[v[i]][k][2]);
				updmax(_f[j+k+1][1],f[now][j][1]+w[i]+f[v[i]][k][2]);
				updmax(_f[j+k+1][2],f[now][j][2]+w[i]+f[v[i]][k][2]);
				updmax(_f[j+k][0],f[now][j][0]+f[v[i]][k][0]);
				updmax(_f[j+k][1],f[now][j][1]+f[v[i]][k][0]);
				updmax(_f[j+k][1],f[now][j][0]+w[i]+f[v[i]][k][1]);
				updmax(_f[j+k][2],f[now][j][2]+f[v[i]][k][0]);
				updmax(_f[j+k][2],f[now][j][1]+w[i]+f[v[i]][k][1]);
				updmax(_f[j+k][2],f[now][j][0]+f[v[i]][k][2]);
			}
		sz[now]+=sz[v[i]];
		for (int j=0;j<sz[now];j++){
			f[now][j][0]=_f[j][0];
			f[now][j][1]=_f[j][1];
			f[now][j][2]=_f[j][2];
			updmax(f[now][j][2],f[now][j][0]);
			updmax(f[now][j][2],f[now][j][1]);
			updmax(f[now][j][1],f[now][j][0]);
		}
	}
	return;
}
int main(){
	cin>>n>>k;
	for (int i=1;i<n;i++){
		cin>>u[i]>>v[i]>>w[i];
		nxt[i]=first[u[i]],first[u[i]]=i;
		u[i+n]=v[i],v[i+n]=u[i],w[i+n]=w[i];
		nxt[i+n]=first[u[i+n]],first[u[i+n]]=i+n;
	}
	dfs(1,0);
	for (int i=0;i<=k;i++)printf("%lld ",f[1][i][2]);
	printf("\n");
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3520kb

input:

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

output:

14 16 

result:

ok 2 number(s): "14 16"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3636kb

input:

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

output:

13 20 21 

result:

ok 3 number(s): "13 20 21"

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 3600kb

input:

50 2000
3 34 1
37 39 58720256
17 24 14680064
28 39 1
25 38 1
21 29 1
3 30 1
26 36 1
5 48 14336
4 22 1
26 41 1
41 44 1
5 14 1
23 25 28672
40 41 224
27 39 1
4 20 7340032
7 47 939524096
11 46 114688
30 49 3584
34 44 1
7 35 1
10 29 1
27 33 29360128
16 36 56
8 28 1
13 38 57344
34 45 896
15 35 469762048
1...

output:

1409286145 1761607683 1849688069 1871708167 1877213193 1878589451 1878933517 1879019535 1879041041 1879046419 1879047765 1879048103 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 187...

result:

wrong answer 51st numbers differ - expected: '1879048160', found: '0'