QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#541621 | #8938. Crawling on a Tree | ucup-team3510# | WA | 1ms | 8064kb | C++20 | 1.4kb | 2024-08-31 20:13:36 | 2024-08-31 20:13:36 |
Judging History
answer
#include <bits/stdc++.h>
#define N 10011
#define ll long long
#define sht short
using namespace std;
sht f[N][N];ll g[N][N];
int n,M,c[N];
struct edge{int v,w,k;};
vector<edge> G[N];
sht nf[N],tf[N];ll ng[N],tg[N];
void dfs(int u,int F)
{
for(auto [v,w,k]:G[u])if(v^F)dfs(v,u);
f[u][0]=g[u][0]=0;
for(auto [v,w,k]:G[u])if(v^F)
{
for(int i=0;i<=M;++i)
{
for(int j=0;i+j<=M;++j)
{
nf[i+j]=min((int)nf[i+j],f[u][i]+f[v][j]);
ng[i+j]=min(ng[i+j],g[u][i]+g[v][j]+1ll*(j+2*f[v][j])*w);
}
}
for(int i=0;i<=M;++i)f[u][i]=nf[i],g[u][i]=ng[i],nf[i]=M+1,ng[i]=1e18;
}
for(int i=1;i<=M;++i)f[u][i]=min(f[u][i],f[u][i-1]);
for(int i=1;i<=M;++i)g[u][i]=min(g[u][i],g[u][i-1]);
for(int i=0;i<=M;++i)f[u][i]=max((int)f[u][i],c[u]-i);
// printf("f[%d]:",u);for(int i=0;i<=M;++i)printf("%d ",(int)f[u][i]);putchar(10);
// printf("g[%d]:",u);for(int i=0;i<=M;++i)printf("%lld ",g[u][i]);putchar(10);
}
int main()
{
scanf("%d%d",&n,&M);
for(int i=1;i<n;++i)
{
int u,v,w,k;scanf("%d%d%d%d",&u,&v,&w,&k);G[u].push_back({v,w,k});G[v].push_back({u,w,k});
}
c[1]=0;for(int i=2;i<=n;++i)scanf("%d",c+i);
for(int i=1;i<=n;++i)for(int j=0;j<=M;++j)f[i][j]=M+1,g[i][j]=1e18;
for(int i=0;i<=M;++i)nf[i]=M+1,ng[i]=1e18;
dfs(1,0);
for(int i=1;i<=M;++i)
{
ll ans=1e18;
for(int j=0;j<=M;++j)if(j+f[1][j]<=i)ans=min(ans,g[1][j]);
if(ans<1e18)printf("%lld\n",ans);
else printf("-1\n");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7916kb
input:
4 2 1 2 3 2 2 3 2 1 2 4 5 1 1 1 1
output:
-1 13
result:
ok 2 number(s): "-1 13"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7864kb
input:
4 2 1 2 3 2 2 3 2 1 2 4 5 1 2 2 2
output:
-1 -1
result:
ok 2 number(s): "-1 -1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 8064kb
input:
2 1 2 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 7984kb
input:
2 50 2 1 1 1 50
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 50
result:
wrong answer 50th numbers differ - expected: '-1', found: '50'