QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#541946 | #8938. Crawling on a Tree | ucup-team180# | WA | 1ms | 3784kb | C++20 | 1.4kb | 2024-08-31 21:39:38 | 2024-08-31 21:39:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll piar<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define ov3(a,b,c,name,...)name
#define rep0(n) for(ll aaaaa = 0; aaaaa < n;++aaaaa)
#define rep1(i,n) for(ll i = 0;i < (n); i++)
#define rep2(i,a,b) for(ll i = (a); i <(b); i ++)
#define rep(...) ov3(__VA_ARGS__, rep2,rep1,rep0)(__VA_ARGS__)
#define fore(e,v) for(auto &&e:v)
#define all(a) begin(a),end(a)
#define si(a) (int)(size(a))
bool chmin(auto &a, auto b){return a>b?a = b,1:0;}
bool chmax(auto &a, auto b){return a<b?a = b,1:0;}
#define pb push_back
#define eb emplace_back
#define i128 __int128_t
const ll inf = LLONG_MAX / 3;
int main(){
cin.tie(0) -> sync_with_stdio(0);
ll n,m;
cin>>n>>m;
vector<vector<pair<ll,ll> > > g(n);
vl k(n - 1),l(n - 1);
rep(i,n - 1){
ll u,v;
cin>>u>>v;
u--,v--;
cin>>l[i]>>k[i];
g[u].eb(v,i);
g[v].eb(u,i);
}
vl c(n);
c[0] = 0;
for(ll i =1;i < n;i++)cin>>c[i];
vl e(n);
ll ans = 0;
bool ok = 1;
function<void(ll,ll,ll,ll)> dfs = [&](ll x,ll frm,ll kj,ll lj){
e[x] = c[x];
ll sum = 0;
for(auto &&[y,j] : g[x])if(y != frm){
dfs(y,x,k[j],l[j]);
sum+=e[y];
}
chmax(e[x],sum);
if(e[x] > kj)ok = 0;
else ans += e[x] * lj;
};
dfs(0,-1,2e9,0);
for(ll i = 1;i <= m;i++){
if(ok && e[0] <= i){
cout<<ans<<"\n";
}
else{
cout<<-1<<"\n";
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3752kb
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: 3544kb
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: 3784kb
input:
2 1 2 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3612kb
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: 3556kb
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: 1ms
memory: 3616kb
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: -100
Wrong Answer
time: 0ms
memory: 3624kb
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:
-1
result:
wrong answer 1st numbers differ - expected: '3202064', found: '-1'