QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#270617 | #2002. Race | cciafrino | 0 | 220ms | 39656kb | C++20 | 1.9kb | 2023-12-01 10:29:42 | 2023-12-01 10:29:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int V = 3e5;
int H[V][2];
int L[V];
int best_path(int N, int K, int H[][2], int L[]) {
const int INF = 1e9;
int ans = INF;
vector<vector<pair<int, int>>> adj(N);
for (int i = 0; i+1 < N; ++i) {
// cout << H[i][0] << ' ' << H[i][1] << endl;
adj[H[i][0]].push_back({H[i][1], L[i]});
adj[H[i][1]].push_back({H[i][0], L[i]});
}
vector<bool> deleted(N);
vector<pair<int, int>> max_sub(N);
auto dfs = [&](auto&& self, int cur, int prv) -> int {
int sz = 1;
max_sub[cur] = {0, -1};
for (auto [nxt, weight] : adj[cur]) {
if (nxt == prv || deleted[nxt]) continue;
int cur_sz = self(self, nxt, cur);
sz += cur_sz;
max_sub[cur] = max(max_sub[cur], {cur_sz, nxt});
}
return sz;
};
auto get_dist = [&](auto& self, int cur, int prv, int64_t depth, int level, auto& path) -> void {
path.push_back({depth, level});
for (auto [nxt, weight] : adj[cur]) {
if (nxt == prv || deleted[nxt]) continue;
self(self, nxt, cur, depth + weight, level + 1, path);
}
};
auto rec = [&](auto&& self, int cur) -> void {
int total_sz = dfs(dfs, cur, -1);
while (max_sub[cur].first * 2 > total_sz) cur = max_sub[cur].second;
deleted[cur] = true;
vector<int> vals(K + 1, INF);
for (auto [nxt, weight] : adj[cur]) {
if (deleted[nxt]) continue;
vector<pair<int64_t, int>> path; path.reserve(total_sz);
get_dist(get_dist, nxt, -1, weight, 1, path);
for (auto [dist, level] : path) {
if (dist > K) continue;
ans = min(ans, vals[K - dist] + level);
}
for (auto [dist, level] : path) {
if (dist > K) continue;
vals[dist] = min(vals[dist], level);
}
}
for (auto [nxt, weight] : adj[cur]) {
if (deleted[nxt]) continue;
self(self, nxt);
}
};
rec(rec, 0);
return (ans == INF ? -1 : ans);
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 9
Accepted
time: 1ms
memory: 7700kb
input:
100 50 0 1 1 1 2 2 2 3 2 3 4 1 4 5 2 5 6 1 6 7 1 7 8 1 8 9 1 9 10 2 10 11 2 11 12 2 12 13 1 13 14 1 14 15 1 15 16 2 16 17 1 17 18 2 18 19 1 19 20 1 20 21 1 21 22 2 22 23 2 23 24 2 24 25 2 25 26 1 26 27 2 27 28 2 28 29 2 29 30 2 30 31 2 31 32 1 32 33 1 33 34 2 34 35 2 35 36 1 36 37 1 37 38 1 38 39 1 ...
output:
Correct.
Test #2:
score: 0
Accepted
time: 1ms
memory: 7704kb
input:
100 100 0 1 39 1 2 26 2 3 27 3 4 43 4 5 18 5 6 25 6 7 29 7 8 32 8 9 32 9 10 9 10 11 10 11 12 1 12 13 38 13 14 26 14 15 12 15 16 11 16 17 19 17 18 34 18 19 19 19 20 8 20 21 42 21 22 15 22 23 21 23 24 13 24 25 24 25 26 18 26 27 45 27 28 5 28 29 12 29 30 11 30 31 2 31 32 31 32 33 31 33 34 50 34 35 7 35...
output:
Correct.
Test #3:
score: 0
Accepted
time: 1ms
memory: 7736kb
input:
100 100 0 1 48 1 2 1 2 3 42 3 4 37 4 5 29 5 6 35 6 7 49 7 8 26 8 9 11 9 10 4 10 11 3 11 12 46 12 13 42 13 14 35 14 15 42 15 16 16 16 17 9 17 18 49 18 19 4 19 20 15 20 21 40 21 22 0 22 23 21 23 24 40 24 25 49 25 26 6 26 27 2 27 28 19 28 29 35 29 30 39 30 31 15 31 32 16 32 33 40 33 34 44 34 35 36 35 3...
output:
Correct.
Test #4:
score: 0
Accepted
time: 1ms
memory: 7708kb
input:
100 100 0 1 27 1 2 28 2 3 0 3 4 18 4 5 40 5 6 12 6 7 6 7 8 29 8 9 37 9 10 39 10 11 6 11 12 32 12 13 34 13 14 30 14 15 39 15 16 39 16 17 46 17 18 23 18 19 43 19 20 47 20 21 46 21 22 34 22 23 31 23 24 28 24 25 12 25 26 13 26 27 19 27 28 25 28 29 44 29 30 25 30 31 9 31 32 29 32 33 11 33 34 45 34 35 30 ...
output:
Correct.
Test #5:
score: 0
Accepted
time: 1ms
memory: 7732kb
input:
100 100 0 1 1 1 2 2 2 3 2 3 4 3 4 5 3 5 6 3 6 7 0 7 8 3 8 9 3 9 10 3 10 11 0 11 12 2 12 13 2 13 14 3 14 15 2 15 16 3 16 17 2 17 18 1 18 19 0 19 20 1 20 21 2 21 22 2 22 23 2 23 24 1 24 25 1 25 26 3 26 27 1 27 28 3 28 29 2 29 30 3 30 31 1 31 32 0 32 33 3 33 34 1 34 35 3 35 36 1 36 37 3 37 38 3 38 39 1...
output:
Correct.
Test #6:
score: 0
Accepted
time: 1ms
memory: 7672kb
input:
100 100 0 1 4 1 2 3 2 3 5 3 4 0 4 5 5 5 6 4 6 7 2 7 8 1 8 9 5 9 10 5 10 11 3 11 12 1 12 13 3 13 14 4 14 15 3 15 16 1 16 17 4 17 18 1 18 19 5 19 20 0 20 21 1 21 22 1 22 23 5 23 24 1 24 25 4 25 26 5 26 27 5 27 28 2 28 29 4 29 30 0 30 31 0 31 32 4 32 33 3 33 34 5 34 35 2 35 36 5 36 37 4 37 38 5 38 39 4...
output:
Correct.
Test #7:
score: 0
Accepted
time: 0ms
memory: 7736kb
input:
100 100 0 1 2 1 2 0 2 3 1 3 4 0 4 5 0 5 6 0 6 7 2 7 8 1 8 9 2 9 10 0 10 11 2 11 12 0 12 13 0 13 14 1 14 15 1 15 16 2 16 17 2 17 18 1 18 19 2 19 20 2 20 21 1 21 22 2 22 23 0 23 24 0 24 25 2 25 26 1 26 27 0 27 28 2 28 29 1 29 30 2 30 31 2 31 32 1 32 33 0 33 34 1 34 35 0 35 36 2 36 37 0 37 38 2 38 39 0...
output:
Correct.
Test #8:
score: 0
Accepted
time: 1ms
memory: 5692kb
input:
100 100 0 1 2 1 2 3 2 3 2 3 4 0 4 5 2 5 6 1 6 7 2 7 8 1 8 9 2 9 10 1 10 11 2 11 12 2 12 13 0 13 14 3 14 15 0 15 16 3 16 17 3 17 18 0 18 19 2 19 20 0 20 21 3 21 22 1 22 23 0 23 24 3 24 25 3 25 26 0 26 27 1 27 28 1 28 29 0 29 30 2 30 31 3 31 32 3 32 33 2 33 34 0 34 35 3 35 36 2 36 37 3 37 38 1 38 39 2...
output:
Correct.
Test #9:
score: 0
Accepted
time: 1ms
memory: 7688kb
input:
100 100 0 1 3 1 2 0 2 3 1 3 4 3 4 5 2 5 6 0 6 7 3 7 8 3 8 9 2 9 10 3 10 11 2 11 12 3 12 13 3 13 14 3 14 15 1 15 16 1 16 17 1 17 18 0 18 19 0 19 20 0 20 21 0 21 22 2 22 23 0 23 24 0 24 25 0 25 26 2 26 27 0 27 28 3 28 29 3 29 30 0 30 31 0 31 32 2 32 33 0 33 34 0 34 35 3 35 36 2 36 37 0 37 38 0 38 39 2...
output:
Correct.
Test #10:
score: 0
Accepted
time: 1ms
memory: 7696kb
input:
100 100 0 1 0 1 2 3 2 3 1 3 4 3 4 5 1 5 6 1 6 7 0 7 8 0 8 9 0 9 10 2 10 11 1 11 12 1 12 13 0 13 14 2 14 15 0 15 16 1 16 17 1 17 18 2 18 19 0 19 20 3 20 21 2 21 22 2 22 23 0 23 24 0 24 25 3 25 26 1 26 27 2 27 28 3 28 29 0 29 30 3 30 31 3 31 32 2 32 33 1 33 34 3 34 35 3 35 36 2 36 37 0 37 38 2 38 39 1...
output:
Correct.
Test #11:
score: 0
Accepted
time: 1ms
memory: 7732kb
input:
100 90 0 1 7 1 2 7 2 3 8 3 4 8 4 5 7 5 6 8 6 7 7 7 8 7 8 9 7 9 10 7 10 11 8 11 12 8 12 13 7 13 14 7 14 15 7 15 16 8 16 17 7 17 18 7 18 19 8 19 20 8 20 21 8 21 22 7 22 23 8 23 24 8 24 25 8 25 26 8 26 27 8 27 28 7 28 29 7 29 30 7 30 31 7 31 32 7 32 33 7 33 34 8 34 35 7 35 36 8 36 37 7 37 38 7 38 39 8 ...
output:
Correct.
Test #12:
score: 0
Accepted
time: 1ms
memory: 7792kb
input:
100 78 0 1 18 1 2 19 2 3 17 3 4 15 4 5 16 5 6 15 6 7 19 7 8 17 8 9 15 9 10 15 10 11 17 11 12 18 12 13 19 13 14 16 14 15 17 15 16 18 16 17 17 17 18 15 18 19 19 19 20 19 20 21 17 21 22 18 22 23 19 23 24 16 24 25 17 25 26 19 26 27 17 27 28 17 28 29 19 29 30 15 30 31 16 31 32 16 32 33 18 33 34 15 34 35 ...
output:
Correct.
Test #13:
score: 0
Accepted
time: 0ms
memory: 7672kb
input:
100 100 1 0 0 2 1 0 3 2 0 4 3 0 5 4 0 6 5 0 7 6 0 8 7 0 9 8 0 10 9 0 11 10 0 12 11 0 13 12 0 14 13 0 15 14 0 16 15 0 17 16 0 18 17 0 19 18 0 20 19 0 21 20 0 22 21 0 23 22 0 24 23 0 25 24 0 26 25 0 27 26 0 28 27 0 29 28 0 30 29 0 31 30 0 32 31 0 33 32 0 34 33 0 35 34 0 36 35 0 37 36 0 38 37 0 39 38 0...
output:
Correct.
Test #14:
score: 0
Accepted
time: 1ms
memory: 7708kb
input:
100 100 1 0 1000000 2 1 1000000 3 2 1000000 4 3 1000000 5 4 1000000 6 5 1000000 7 6 1000000 8 7 1000000 9 8 1000000 10 9 1000000 11 10 1000000 12 11 1000000 13 12 1000000 14 13 1000000 15 14 1000000 16 15 1000000 17 16 1000000 18 17 1000000 19 18 1000000 20 19 1000000 21 20 1000000 22 21 1000000 23 ...
output:
Correct.
Test #15:
score: 0
Accepted
time: 1ms
memory: 7672kb
input:
100 100 0 1 1 1 2 1 2 3 0 3 4 0 4 5 1 5 6 1 6 7 0 7 8 1 8 9 0 9 10 1 10 11 1 11 12 0 12 13 0 13 14 0 14 15 1 15 16 1 16 17 0 17 18 1 18 19 1 19 20 0 20 21 0 21 22 0 22 23 1 23 24 0 24 25 0 25 26 0 26 27 1 27 28 0 28 29 1 29 30 0 30 31 1 31 32 0 32 33 1 33 34 0 34 35 0 35 36 1 36 37 1 37 38 1 38 39 1...
output:
Correct.
Test #16:
score: 0
Accepted
time: 0ms
memory: 7756kb
input:
100 100 0 1 101 1 2 85 2 3 68 3 4 25 4 5 87 5 6 30 6 7 87 7 8 37 8 9 14 9 10 18 10 11 4 11 12 36 12 13 27 13 14 101 14 15 80 15 16 29 16 17 7 17 18 8 18 19 31 19 20 51 20 21 0 21 22 22 22 23 40 23 24 28 24 25 7 25 26 48 26 27 74 27 28 20 28 29 59 29 30 23 30 31 34 31 32 75 32 33 48 33 34 19 34 35 85...
output:
Correct.
Test #17:
score: -9
Wrong Answer
time: 1ms
memory: 7820kb
input:
100 100 0 1 90 1 2 38 2 3 31 3 4 72 4 5 4 5 6 36 6 7 45 7 8 23 8 9 73 9 10 92 10 11 71 11 12 5 12 13 26 13 14 92 14 15 35 15 16 86 16 17 2 17 18 3 18 19 53 19 20 82 20 21 17 21 22 58 22 23 7 23 24 89 24 25 84 25 26 8 26 27 96 27 28 9 28 29 24 29 30 48 30 31 30 31 32 18 32 33 56 33 34 58 34 35 14 35 ...
output:
Incorrect. Returned 4, Expected 2.
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #39:
score: 22
Accepted
time: 83ms
memory: 15088kb
input:
100000 100 1 0 1 2 1 10 3 1 1 4 3 5 5 3 6 6 5 6 7 3 10 8 5 9 9 8 7 10 9 9 11 6 7 12 6 3 13 10 10 14 9 1 15 14 7 16 15 5 17 10 1 18 14 9 19 12 8 20 18 10 21 10 9 22 12 7 23 14 9 24 15 5 25 15 2 26 20 4 27 19 10 28 17 8 29 16 8 30 24 10 31 17 2 32 28 7 33 27 8 34 21 4 35 28 7 36 22 4 37 18 6 38 27 6 3...
output:
Correct.
Test #40:
score: 0
Accepted
time: 209ms
memory: 39656kb
input:
200000 100 192164 110199 93 47882 192164 72 146145 47882 33 126329 146145 51 179411 126329 12 64302 179411 54 149999 64302 60 68743 149999 54 6947 68743 48 34108 6947 96 153071 34108 21 124245 153071 27 80021 124245 78 35586 80021 33 63565 35586 99 146479 63565 78 112365 146479 87 66626 112365 18 16...
output:
Correct.
Test #41:
score: 0
Accepted
time: 220ms
memory: 37664kb
input:
200000 97 124561 2131 18 168021 124561 90 65536 168021 96 130830 65536 6 58340 130830 6 118024 58340 42 104437 118024 36 67532 104437 54 104313 67532 24 132363 104313 96 140771 132363 30 2297 140771 18 82285 2297 48 87437 82285 12 55493 87437 72 179845 55493 90 26917 179845 24 53910 26917 48 129657 ...
output:
Correct.
Test #42:
score: 0
Accepted
time: 115ms
memory: 23904kb
input:
198766 86 38130 38131 5 155346 155639 6 180745 180746 3 185908 185909 7 107946 108231 9 144465 144477 9 176974 176975 7 133125 133389 5 194088 194089 8 188165 188439 4 72065 72340 4 80346 80629 7 52493 52494 7 44364 44365 4 132787 132788 1 111621 111853 3 161345 161508 6 41753 41754 4 78755 78756 7 ...
output:
Correct.
Test #43:
score: 0
Accepted
time: 98ms
memory: 23252kb
input:
198766 86 38130 38131 4 155346 155639 3 180745 180746 7 185908 185909 3 107946 108231 1 144465 144477 5 176974 176975 4 133125 133389 3 194088 194089 6 188165 188439 5 72065 72340 4 80346 80629 1 52493 52494 3 44364 44365 9 132787 132788 3 111621 111853 6 161345 161508 4 41753 41754 5 78755 78756 6 ...
output:
Correct.
Test #44:
score: 0
Accepted
time: 128ms
memory: 23768kb
input:
198451 99 42497 158805 16 83677 171918 6 164409 16480 4 65700 172431 6 20132 33243 6 19027 39931 18 180642 188093 20 110506 2223 12 48861 83975 4 193291 6277 16 37431 41363 6 115876 83987 12 109068 107907 14 167322 157730 8 19357 121205 6 37871 144561 2 158240 55090 4 60419 103727 10 93041 64438 12 ...
output:
Correct.
Test #45:
score: 0
Accepted
time: 175ms
memory: 23756kb
input:
198991 100 196029 70769 1 70769 151830 1 151830 124833 1 124833 168683 1 168683 153063 1 153063 78481 1 78481 126030 1 126030 79598 1 79598 57434 1 57434 135918 1 135918 167763 1 167763 73281 1 73281 66913 1 66913 54923 1 54923 109906 1 109906 77105 1 77105 61892 1 61892 79098 1 79098 22614 1 22614 ...
output:
Correct.
Test #46:
score: 0
Accepted
time: 164ms
memory: 23560kb
input:
198277 100 34664 176620 1 176620 27592 1 27592 122762 1 122762 9726 1 9726 171935 1 171935 110727 1 110727 107016 1 107016 90375 1 90375 45336 1 45336 122311 1 122311 136516 1 136516 171571 1 171571 58056 1 58056 106150 1 106150 165523 1 165523 125382 1 125382 88774 1 88774 95100 1 95100 89056 1 890...
output:
Correct.
Test #47:
score: 0
Accepted
time: 75ms
memory: 15036kb
input:
100000 100 1 0 10 2 1 6 3 1 6 4 3 8 5 4 5 6 5 3 7 6 5 8 6 2 9 6 9 10 6 9 11 10 6 12 8 1 13 7 5 14 9 2 15 10 7 16 15 2 17 11 2 18 15 2 19 12 8 20 15 6 21 13 1 22 13 7 23 18 10 24 15 3 25 17 3 26 17 4 27 14 3 28 20 4 29 23 3 30 19 3 31 28 3 32 16 9 33 28 5 34 30 7 35 32 10 36 29 8 37 24 3 38 29 7 39 2...
output:
Correct.
Test #48:
score: 0
Accepted
time: 77ms
memory: 15084kb
input:
100000 100 1 0 1 2 1 7 3 1 6 4 2 1 5 2 9 6 3 1 7 4 9 8 6 3 9 3 8 10 8 8 11 10 8 12 11 8 13 7 3 14 10 9 15 11 1 16 11 2 17 10 2 18 13 1 19 13 4 20 10 8 21 20 5 22 11 8 23 7 6 24 11 9 25 12 7 26 9 7 27 13 10 28 15 10 29 18 9 30 17 7 31 18 6 32 28 3 33 23 2 34 27 9 35 34 1 36 22 7 37 34 10 38 21 6 39 1...
output:
Correct.
Test #49:
score: 0
Accepted
time: 66ms
memory: 17164kb
input:
100000 100 73221 58566 10 60747 73221 8 16080 58566 12 14740 73221 1 82191 58566 10 34172 58566 5 17344 60747 9 67648 14740 14 83814 14740 12 71932 73221 12 60181 58566 5 60372 14740 4 32835 71932 2 98403 73221 4 18187 17344 14 63623 82191 6 10653 98403 8 18961 60372 1 29161 32835 1 642 34172 6 1568...
output:
Correct.
Test #50:
score: -22
Wrong Answer
time: 70ms
memory: 15140kb
input:
100000 100 31968 17836 43 85028 31968 69 74374 31968 89 49590 85028 59 84942 85028 94 51035 74374 16 96575 74374 35 41094 49590 16 53465 49590 97 75329 84942 95 49720 84942 73 95018 51035 6 32483 51035 51 76446 96575 2 24981 96575 4 86313 41094 31 63589 41094 7 19275 53465 62 50220 53465 52 74546 75...
output:
Incorrect. Returned 2, Expected 1.
Subtask #4:
score: 0
Skipped
Dependency #1:
0%