QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#654102 | #8938. Crawling on a Tree | 11d10xy | RE | 1ms | 4256kb | C++14 | 1.8kb | 2024-10-18 21:05:34 | 2024-10-18 21:06:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
int n,m,c[10010];
struct N_{
int L,R;
vector<i64>a;
void reserve(int l1,int r1){
int l=max(l1,L),r=min(r1,R);
if(l>r)a={};
else{
a.erase(begin(a),begin(a)+l-L);
a.erase(end(a)-(R-r),end(a));
L=l,R=r;
}
}
void extend(int r){
r=max(r,R);
a.insert(end(a),r-R,1e9),R=r;
}
};
N_ mul(N_ x,N_ y){
if(x.a.empty()||y.a.empty())return{};
vector<i64>d;
for(int i=1;i<x.a.size();i++)d.push_back(x.a[i]-x.a[i-1]);
int N=d.size();
for(int i=1;i<y.a.size();i++)d.push_back(y.a[i]-y.a[i-1]);
inplace_merge(begin(d),begin(d)+N,end(d));
d.insert(begin(d),x.a[0]+y.a[0]);
for(int i=1;i<d.size();i++)d[i]+=d[i-1];
return{x.L+y.L,x.R+y.R,d};
}
struct E_{int k,l,v;};
vector<E_>G[10010];
N_ dfs(int u,int fa,int k,int l){
N_ prod{0,0,{0}};
for(E_ e:G[u])if(e.v!=fa){
prod=mul(prod,dfs(e.v,u,e.k,e.l));
prod.reserve(0,m);
c[u]=max(c[u],c[e.v]);
}
prod.extend(m);
for(int i=prod.L+1;i<=prod.R;i++)prod.a[i]=min(prod.a[i],prod.a[i-1]);
if(u>1){
prod.reserve(c[u]*2-k,k);
if(!prod.a.empty()){
for(int i=prod.L;i<=prod.R;i++){
prod.a[i-prod.L]+=(max(c[u],i)*2-i)*1ll*l;
}
}
}else prod.reserve(c[u],m);
return prod;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1,u,v,k,l;i<n;i++){
scanf("%d%d%d%d",&u,&v,&l,&k);
G[u].push_back({k,l,v});
G[v].push_back({k,l,u});
}
for(int i=2;i<=n;i++){
scanf("%d",&c[i]);
}
N_ res=dfs(1,0,0,0);
vector<i64>ans(m+1,-1);
if(!res.a.empty()){
for(int i=res.L;i<=res.R;i++)ans[i]=res.a[i-res.L];
}
for(int i=1;i<=m;i++)printf("%lld\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3988kb
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: 0ms
memory: 3984kb
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: 0ms
memory: 4044kb
input:
2 1 2 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3908kb
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 -1
result:
ok 50 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 4244kb
input:
2 50 2 1 1 50 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:
ok 50 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
2 50 1 2 1 100000 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:
ok 50 numbers
Test #7:
score: 0
Accepted
time: 0ms
memory: 4256kb
input:
50 1 1 2 85524 58896 2 3 9137 9819 3 4 3036 88987 4 5 78909 15766 5 6 76067 34996 6 7 64247 63701 7 8 14 9384 8 9 37698 35418 9 10 51427 91691 10 11 39818 89351 11 12 47887 64083 12 13 43836 44135 13 14 22561 83803 14 15 52617 97413 15 16 41869 83810 16 17 35783 18642 17 18 5514 34601 18 19 50448 49...
output:
3202064
result:
ok 1 number(s): "3202064"
Test #8:
score: -100
Runtime Error
input:
50 5 1 2 48897 1 2 3 59967 3 3 4 61806 2 4 5 48519 4 5 6 77213 5 6 7 32384 1 7 8 59009 2 8 9 98263 1 9 10 42945 6 10 11 5549 6 11 12 51097 6 12 13 88536 4 13 14 44215 2 14 15 56896 2 15 16 19263 5 16 17 30787 5 17 18 20135 3 18 19 75922 4 19 20 35387 5 20 21 84081 4 21 22 54235 5 22 23 44411 3 23 24...