QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102524 | #5252. Deforestation | zswzswzsw# | WA | 38ms | 18764kb | C++14 | 767b | 2023-05-03 14:21:53 | 2023-05-03 14:21:57 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=501000;
int n,W,tA=0;
vector<int>G[N];
int val[N],tot;
int build(void)
{
int u=++tA,siz;
cin>>val[u]>>siz;tot+=val[u];
for(int i=1;i<=siz;i++)G[u].push_back(build());
return u;
}
int res=0;
bool cmp(int x,int y){
return val[x]<val[y];
}
void DFS(int u)
{
int sum=0;
for(int i=0,v;i<G[u].size();i++)
{
v=G[u][i];
DFS(v);sum+=val[v];
}
sort(G[u].begin(),G[u].end());
int siz=G[u].size()-1;
while(sum>W)++res,sum-=val[G[u][siz]],--siz;
val[u]+=sum;
res+=val[u]/W;val[u]%=W;
return;
}
signed main()
{
cin>>W;
build();
if(W>=tot)return cout<<0,0;
DFS(1);
if(val[1])++res;
cout<<res;
return 0;
}
/*
2
1 1
2 1
1 1
2 0
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 38ms
memory: 18764kb
input:
999900000 7339 3 14947 2 12850 3 8986 10 11599 9 8889 10 10711 4 8015 1 11626 0 9492 1 7017 0 8863 0 8632 0 5321 5 9906 0 11687 0 9845 0 10469 0 11708 0 14950 5 11934 0 11922 0 13101 0 12000 0 9082 0 9273 5 12296 0 6119 0 9201 0 12652 0 12957 0 7454 5 12515 0 12976 0 10358 0 13997 0 8371 0 10181 5 8...
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'