QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#270643 | #2002. Race | LeticiaFCS | 0 | 110ms | 40744kb | C++20 | 1.8kb | 2023-12-01 10:49:42 | 2023-12-01 10:49:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int n, k;
pii path[1000005];
vector<pii> g[1000005];
bool vis[1000005];
int mini[1000005];
int ans, inf;
int dfs(int u, int p){
pii child = {0, u};
int sub = 0;
for(auto [l, v] : g[u]){
if(vis[v] || v == p) continue;
int cur = dfs(v, u);
sub += cur;
child = max<pii>(child, {cur, v});
}
path[u] = child;
return sub;
}
vector<pii> cur;
void dist(int u, int p, int prof, int edges){
if(prof > k || edges >= ans) return;
int comp = k - prof;
if(comp >= 0)
ans = min(ans, edges + mini[comp]);
cur.emplace_back(prof, edges);
for(auto [l, v] : g[u]){
if(vis[v] || v == p) continue;
dist(v, u, prof + l, edges + 1);
}
}
vector<pii> child;
void decomp(int u){
int sub = dfs(u, u);
int c = u;
while(path[c].first > sub/2) c = path[c].second;
vis[c] = true;
child.clear();
cur.reserve(sub);
for(auto [l, v] : g[c]){
if(vis[v]) continue;
cur.clear();
dist(v, c, l, 1);
child.insert(child.end(), cur.begin(), cur.end());
for(auto [prof, edges] : cur)
mini[prof] = min(mini[prof], edges);
}
for(auto [prof, edges] : child)
mini[prof] = inf;
for(auto [l, v] : g[c])
if(!vis[v])
decomp(v);
}
int best_path(int N,int K,int H[][2], int L[]){
inf = ans = 1000005;
n = N;
k = K;
for(int i = 0; i < inf; i++) mini[i] = inf;
mini[0] = 0;
for(int i = 0; i + 1 < n; i++){
int u = H[i][0], v = H[i][1], c = L[i];
g[u].emplace_back(c, v);
g[v].emplace_back(c, u);
}
decomp(0);
if(ans >= inf) ans = -1;
return ans;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 9
Accepted
time: 0ms
memory: 36568kb
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: 0ms
memory: 36628kb
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: -9
Wrong Answer
time: 4ms
memory: 36696kb
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:
Incorrect. Returned -1, Expected 3.
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Time Limit Exceeded
Test #39:
score: 22
Accepted
time: 110ms
memory: 40744kb
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: -22
Time Limit Exceeded
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:
Unauthorized output
Subtask #4:
score: 0
Skipped
Dependency #1:
0%