QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#624149#6107. One PathcjxWA 1ms6960kbC++202.6kb2024-10-09 15:06:002024-10-09 15:06:02

Judging History

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

  • [2024-10-09 15:06:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6960kb
  • [2024-10-09 15:06:00]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
long long read(){
	long long x=0,f=1;char ch=getchar();
	while(!isdigit(ch))
	{if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
void write(long long x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
const int N=2010;
int n,k,sz[N];
int head[N],ver[N<<1],nxt[N<<1],tot;
ll edge[N<<1],f[N][N][3];
void add(int x,int y,ll z){
	ver[++tot]=y,edge[tot]=z,nxt[tot]=head[x],head[x]=tot;
}
void dfs1(int x,int fa){
    sz[x]=1;
    f[x][0][0]=f[x][0][1]=-1e12;
    ll g[N][3];
    for(int i=head[x];i;i=nxt[i]){
        int y=ver[i];
        if(y==fa)continue;
        dfs1(y,x);
        memset(g,0,sizeof(g));
        for(int p=sz[x];p>=0;p--){
            for(int q=0;q<=sz[y];q++){
                g[p+q][0]=max(g[p+q][0],f[x][p][0]+f[y][q][2]);
                g[p+q][0]=max(g[p+q][0],f[x][p][2]+f[y][q][0]+edge[i]);
                g[p+q+1][0]=max(g[p+q+1][0],f[x][p][2]+f[y][q][2]+edge[i]);
                g[p+q][1]=max(g[p+q][1],f[x][p][1]+f[y][q][2]);
                g[p+q][1]=max(g[p+q][1],f[x][p][2]+f[y][q][1]);
                g[p+q][1]=max(g[p+q][1],f[x][p][2]+f[y][q][0]+edge[i]);
                g[p+q][1]=max(g[p+q][1],f[x][p][0]+f[y][q+1][0]+edge[i]);
                g[p+q][1]=max(g[p+q][1],f[x][p][0]+f[y][q][2]+edge[i]);
                g[p+q][2]=max(g[p+q][2],f[x][p][2]+f[y][q][2]);
                g[p+q][2]=max(g[p+q][2],f[x][p][2]+f[y][q][1]+edge[i]);
                //for(int t=1;t<3;t++)
                 //   f[x][p+q][t]=max(f[x][p+q][t],f[x][p+q][t-1]);
            }
            //g[p][1]=max(f[x][p][1],f[x][p][0]+f[y][1][0]+edge[i]);
        }
        sz[x]+=sz[y];
        for(int p=1;p<=sz[x];p++){
            for(int j=0;j<3;j++){
                f[x][p][j]=max(f[x][p][j],max(g[p][j],f[x][p-1][j]));
                if(j)f[x][p][j]=max(f[x][p][j],f[x][p][j-1]);
            }
        }
    }
    /*for(int i=1;i<=sz[x];i++)
        for(int j=0;j<3;j++){
            f[x][i][j]=max(f[x][i][j],f[x][i-1][j]);
            if(j)f[x][i][j]=max(f[x][i][j],f[x][i][j-1]);
            printf("f[%d][%d][%d]=%lld\n",x,i,j,f[x][i][j]);
        }*/
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();k=read();
	for(int i=1;i<n;i++){
        int x=read(),y=read(),z=read();
        add(x,y,z);add(y,x,z);
    }
    dfs1(1,0);
    for(int i=0;i<=k;i++){
        printf("%lld ",f[1][min(i+1,n)][1]);
    }
    puts("");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4124kb

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: 0ms
memory: 4196kb

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: 1ms
memory: 6960kb

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 1877213192 1878589449 1878933514 1879019532 1879041038 1879046416 1879047761 1879048098 1879048155 1879048157 1879048158 1879048159 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 187...

result:

wrong answer 5th numbers differ - expected: '1877213193', found: '1877213192'