QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643399#6107. One PathxlwangWA 1ms3996kbC++142.5kb2024-10-15 21:01:022024-10-15 21:01:04

Judging History

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

  • [2024-10-15 21:01:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3996kb
  • [2024-10-15 21:01:02]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define int long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
#define pii pair<int,int>
#define mk make_pair
using namespace std;
inline int read(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
inline void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
//	int t=read();
//	while(t--) work();
//}
const int Maxn=2e3+10;
struct node{int nxt,to,d;}e[Maxn<<1];
int cnt,head[Maxn];
inline void add(int u,int v,int w){++cnt;e[cnt]=(node){head[u],v,w};head[u]=cnt;}
inline void chkmin(int &x,int y){if(x>y) x=y;}
inline void chkmax(int &x,int y){if(x<y) x=y;}
int f[Maxn][Maxn],g[Maxn][Maxn],h[Maxn][Maxn];
int siz[Maxn];
inline void dfs(int x,int fa){
    siz[x]=1;
    for(register int I=head[x];I;I=e[I].nxt) if(e[I].to!=fa){
        int y;y=e[I].to;dfs(y,x);
        rf(i,siz[x],1) rf(j,siz[y],1){
            chkmax(h[x][i+j],h[x][i]+h[y][j]+e[I].d);
            chkmax(h[x][i+j-1],h[x][i]+f[y][j]);
            chkmax(h[x][i+j-1],f[x][i]+h[y][j]);
            chkmax(h[x][i+j-1],g[x][i]+g[y][j]+e[I].d);
        }
        rf(i,siz[x],1) rf(j,siz[y],1){
            chkmax(g[x][i+j],g[x][i]+g[y][j]+e[I].d);
            chkmax(g[x][i+j-1],g[x][i]+f[y][j]);
            chkmax(g[x][i+j-1],f[x][i]+g[y][j]+e[I].d);
        }
        rf(i,siz[x],1) rf(j,siz[y],1){
            chkmax(f[x][i+j],f[x][i]+h[y][j]+e[I].d);
            chkmax(f[x][i+j-1],f[x][i]+f[y][j]);
        }siz[x]+=siz[y];
    }
}
int n,k;
inline void init(){
    n=read();k=read();
    fr(i,1,n-1){
        int x,y,z;
        x=read();y=read();z=read();
        add(x,y,z);add(y,x,z);
    }
}
inline void work(){
    dfs(1,0);
    fr(i,1,k+1) writepl(h[1][min(i,n)]);puts("");
}
signed main(){
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
    init();work();
    // printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3712kb

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: 3536kb

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: 3996kb

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 1875378184 1878130698 1878589451 1878933516 1879019534 1879041040 1879046418 1879047315 1879047988 1879048101 1879048158 1879048159 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 187...

result:

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