QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#102503 | #5252. Deforestation | csw_ccc# | WA | 8ms | 10712kb | C++14 | 2.1kb | 2023-05-03 14:02:48 | 2023-05-03 14:02:53 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <map>
#include <cstdio>
#include <queue>
#include <algorithm>
#define ll long long
using namespace std;
struct node
{
int x;
int nxt;
};
const int maxn = 100000 + 5;
int Max_w;
node a[maxn << 1];
int len, h[maxn];
int w[maxn];
int chuan[maxn];
int tot;
int ans;
template<class T>
inline void read(T &x);
inline void add(int x, int y)
{
len++; a[len].x = y; a[len].nxt = h[x]; h[x] = len;
}
void input(int x, int fa)
{
add(x, fa); add(fa, x);
int n;
read(w[x]); read(n);
for (int i = 1; i <= n; i++)
input(++tot,x);
}
void init()
{
read(Max_w);
input(++tot,0);
}
priority_queue<int > q[maxn];
void dfs(int x, int fa)
{
// printf("x:%d fa:%d w:%d\n",x,fa,w[x]);
int tot_chuan = 0;
for (int p = h[x]; p; p = a[p].nxt)
{
int v = a[p].x;
if (v == fa) continue;
dfs(v,x);
if (chuan[v]) q[x].push(chuan[v]), tot_chuan += chuan[v];
}
if (w[x] >= Max_w)
{
ans += w[x] / Max_w;
if (x != 1) ans++;
w[x] %= Max_w;
while (tot_chuan > Max_w)
{
int t = q[x].top();
q[x].pop();
tot_chuan -= t;
ans++;
}
if (tot_chuan + w[x] > Max_w) chuan[x] = w[x] - Max_w + tot_chuan;
else chuan[x] = 0;
}
else
{
while (tot_chuan > Max_w)
{
int t = q[x].top();
q[x].pop();
tot_chuan -= t;
ans++;
}
if (tot_chuan + w[x] > Max_w)
{
chuan[x] = w[x] - Max_w + tot_chuan;
ans++;
}
else chuan[x] = tot_chuan + w[x];
}
}
void work()
{
dfs(1,0);
// for (int i = 1; i <= tot; i++) cout << chuan[i] << ' ';
// puts("");
}
void print()
{
cout << ans << endl;
}
int main()
{
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
init();
work();
print();
return 0;
}
template<class T>
inline void read(T &x)
{
x = 0; T s = 1;
char c = getchar();
while(c < '0' || c > '9') {if(c == '-') s = -1; c = getchar();}
while(c >= '0' && c <= '9') {x = x*10+c-'0'; c = getchar();}
x *= s;
}
详细
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 10712kb
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'