ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#152117 | #9. 小h的树 | LightningUZ | 70 | 373ms | 110360kb | C++11 | 1.6kb | 2022-07-30 20:36:12 | 2022-07-30 20:36:18 |
answer
#include<bits/stdc++.h>
using namespace std;
#define N 3050
#define INF 0x3f3f3f3f
#define F(i,l,r) for(int i=(l);i<=(r);++i)
#define D(i,r,l) for(int i=(r);i>=(l);--i)
#define MEM(x,a) memset(x,a,sizeof(x))
int I() {char c=getchar(); int x=0; int f=1; while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar(); while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return ((f==1)?x:-x);}
int n,k;
struct Graph
{
int to[N<<1],nx[N<<1],w[N<<1],h[N],ec=-1; void cl(){MEM(h,-1);ec=-1;}
void ad(int u,int v,int ww){++ec;to[ec]=v;nx[ec]=h[u];w[ec]=ww;h[u]=ec;} void a2(int u,int v,int w){ad(u,v,w),ad(v,u,w);}
}G;
#define T(G,i,u)for(int i=G.h[u],v;~i;i=G.nx[i])
int sz[N]; int f[3][N][N];
int tmp[3][N];
inline void up(int&a,int b){a=(b<a)?b:a;}
void fuck(int u,int v,int w)
{
F(i,0,3)F(j,0,sz[u]+sz[v])tmp[i][j]=INF;
F(i,0,sz[u])F(j,0,sz[v])
{
up(tmp[2][i+j],f[2][u][i]+f[2][v][j]+2*w);
up(tmp[1][i+j],f[1][u][i]+f[2][v][j]+2*w); up(tmp[1][i+j],f[2][u][i]+f[1][v][j]+w);
up(tmp[0][i+j],f[1][u][i]+f[1][v][j]+w);
up(tmp[0][i+j],f[2][u][i]+f[0][v][j]+2*w); up(tmp[0][i+j],f[0][u][i]+f[2][v][j]+2*w);
}
F(i,0,2)F(j,0,sz[u]+sz[v])up(f[i][u][j],tmp[i][j]);
}
void d0(int u,int fa)
{
sz[u]=1;
F(i,0,2)f[i][u][0]=f[i][u][1]=0;
T(G,i,u)if((v=G.to[i])!=fa)
{
d0(v,u);
fuck(u,v,G.w[i]);
sz[u]+=sz[v];
}
}
void flandre()
{
n=I(),k=I(); G.cl();
F(i,1,n-1){int u=I(),v=I(),w=I(); G.a2(u,v,w);}
MEM(f,0x3f); d0(1,1);
printf("%d\n",f[0][1][k]);
}
int main()
{
int t=1;
while(t-->0){flandre();}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 4ms
memory: 110204kb
input:
10 7 1 2 35129 2 3 42976 3 4 24497 2 5 83165 1 6 4748 5 7 38311 4 8 70052 3 9 3561 8 10 80238
output:
184524
result:
ok 1 number(s): "184524"
Test #2:
score: 10
Accepted
time: 68ms
memory: 110288kb
input:
3000 3000 1 2 80232 1 3 31904 1 4 24318 1 5 70898 1 6 54285 1 7 99203 1 8 36858 1 9 52269 1 10 21554...
output:
293195939
result:
ok 1 number(s): "293195939"
Test #3:
score: 10
Accepted
time: 0ms
memory: 110204kb
input:
50 32 1 2 78088 1 3 59372 2 4 12219 3 5 17188 2 6 51314 3 7 72028 3 8 1593 4 9 65442 5 10 97450 6 11...
output:
1758096
result:
ok 1 number(s): "1758096"
Test #4:
score: 10
Accepted
time: 3ms
memory: 110204kb
input:
50 48 1 2 60240 2 3 71246 3 4 21134 2 5 75461 5 6 4274 6 7 87233 6 8 74521 4 9 81504 8 10 23918 5 11...
output:
3245532
result:
ok 1 number(s): "3245532"
Test #5:
score: 0
Wrong Answer
time: 3ms
memory: 110204kb
input:
200 36 1 2 95675 1 3 46068 3 4 92249 2 5 79443 4 6 11920 6 7 28895 4 8 25231 5 9 82622 8 10 34349 8 ...
output:
1411815
result:
wrong answer 1st numbers differ - expected: '1214282', found: '1411815'
Test #6:
score: 10
Accepted
time: 3ms
memory: 110204kb
input:
200 35 1 2 97551 2 3 27011 2 4 14709 1 5 27407 2 6 57345 5 7 63132 7 8 89143 4 9 30986 5 10 89545 7 ...
output:
1341305
result:
ok 1 number(s): "1341305"
Test #7:
score: 10
Accepted
time: 93ms
memory: 110288kb
input:
3000 666 1 2 65806 1 3 53490 1 4 43794 1 5 63048 1 6 10670 1 7 56872 1 8 71919 1 9 78642 1 10 9831 1...
output:
14876698
result:
ok 1 number(s): "14876698"
Test #8:
score: 0
Wrong Answer
time: 83ms
memory: 110360kb
input:
3000 1633 1 2 73534 2 3 97254 3 4 96323 4 5 88456 5 6 287 6 7 7380 7 8 63246 8 9 57273 9 10 23915 10...
output:
75738612
result:
wrong answer 1st numbers differ - expected: '74678010', found: '75738612'
Test #9:
score: 10
Accepted
time: 38ms
memory: 110292kb
input:
3000 2612 1 2 85560 1 3 99187 1 4 40779 1 5 70190 1 6 50395 1 7 9810 1 8 87504 1 9 600 1 10 78858 1 ...
output:
231082152
result:
ok 1 number(s): "231082152"
Test #10:
score: 0
Wrong Answer
time: 78ms
memory: 110332kb
input:
3000 858 1 2 51625 1 3 28801 1 4 85825 3 5 92506 5 6 76389 4 7 74801 3 8 49889 6 9 81981 9 10 73122 ...
output:
40176513
result:
wrong answer 1st numbers differ - expected: '38161665', found: '40176513'