QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#667938 | #8938. Crawling on a Tree | Yansuan_HCl | RE | 1ms | 7528kb | C++20 | 2.4kb | 2024-10-23 09:57:03 | 2024-10-23 09:57:03 |
Judging History
answer
#include <bits/stdc++.h>
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline)) static
#define U(i,l,r) for(int i(l),END##i(r);i<=END##i;++i)
#define D(i,r,l) for(int i(r),END##i(l);i>=END##i;--i)
using namespace std;
using ll = long long;
#define IC isdigit(c)
#define GC c=getchar()
void rd(auto &x) { x = 0; char GC; bool f = 0;
for (; !IC; GC) f |= c == '-';
for (; IC; GC) x = x * 10 + c - 48;
if (f) x = -x;
}
void rd(auto &x, auto &...y) { rd(x); rd(y...); }
#define meow(...) fprintf(stderr, __VA_ARGS__)
#define Assert(e, v) if (!(e)) { meow("AF@%d\n", __LINE__ ); exit(v); }
#define vc vector
#define eb emplace_back
#define pb push_back
const int N = 10004;
int n, m, c[N], cx[N];
using info = array<ll, N>;
void mkv(info &f, info &g, info &h) {
U (i, 1, m - 1) {
assert(f[i] - f[i - 1] <= f[i + 1] - f[i]);
assert(g[i] - g[i - 1] <= g[i + 1] - g[i]);
}
h[0] = f[0] + g[0];
int i = 1, j = 1, k = 1;
for (; k <= m; ++k) {
assert(i <= m);
assert(j <= m);
if (f[i] - f[i - 1] <= g[j] - g[j - 1]) {
h[k] = h[k - 1] + f[i] - f[i - 1];
++i;
} else {
h[k] = h[k - 1] + g[j] - g[j - 1];
++j;
}
}
}
using edge = array<int, 3>;
vc<edge> g[N];
int siz[N], hson[N];
void dfs0(int u, int f) {
siz[u] = 1; cx[u] = c[u];
for (auto [v, w, k] : g[u]) if (v != f) {
dfs0(v, u);
siz[u] += siz[v];
cx[u] = max(cx[u], cx[v]);
if (siz[v] > siz[hson[u]])
hson[u] = v;
}
}
void dp(int u, int fa, int fw, int fk, info &f) {
for (auto [v, w, k] : g[u]) if (v == hson[u]) {
dp(hson[u], u, w, k, f);
}
for (auto [v, w, k] : g[u]) if (v != fa && v != hson[u]) {
info x {}, y {};
dp(v, u, w, k, x);
mkv(f, x, y);
f = y;
}
U (y, 1, m) f[y] = min(f[y], f[y - 1]); // 留在 u
U (y, 0, m) {
int x = max(cx[u], y);
if (2 * x - y > fk)
f[y] = (m - y + 1) * 1e14;
}
U (y, 0, m) {
int x = max(cx[u], y);
f[y] += (2 * x - y) * fw;
}
}
int main() {
// freopen("ava.in", "r", stdin);
rd(n, m);
U (i, 2, n) {
int u, v, w, k; rd(u, v, w, k);
g[u].pb({v, w, k});
g[v].pb({u, w, k});
}
U (i, 2, n)
rd(c[i]);
dfs0(1, 0);
info f {};
dp(1, 0, 0, 2e9, f);
info h; h.fill(1e18);
U (y, 0, m) {
int x = max(cx[1], y);
h[x] = min(h[x], f[y]);
}
U (x, 1, m) {
h[x] = min(h[x - 1], h[x]);
if (x < cx[1] || h[x] >= 1e14)
puts("-1");
else
printf("%lld\n", h[x]);
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4368kb
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: 4248kb
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: 4352kb
input:
2 1 2 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 4088kb
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: 1ms
memory: 4296kb
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: 4240kb
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: 7528kb
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...