QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#599834 | #2002. Race | ModyKachef | 0 | 147ms | 202392kb | C++11 | 1.9kb | 2024-09-29 11:48:14 | 2024-09-29 11:48:14 |
Judging History
answer
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<array<int , 2>>> adj;
int dp[(int)2e5+1][101][3];
int k ;
void dfs1(int node , int par){
for (auto &[i , w] : adj[node]){
if (i == par) continue;
dfs1(i , node);
for (int j = 0 ; j <= k ; j++){
if (j >= w) {
if (dp[i][j-w][0] + 1 <= dp[node][j][0]) {
dp[node][j][1] = dp[node][j][0];
dp[node][j][0] = dp[i][j-w][0] + 1;
}
else if (dp[i][j-w][0] + 1 <= dp[node][j][1]){
dp[node][j][1] = dp[i][j-w][0] + 1;
}
}
}
}
}
void dfs2(int node , int par){
for (auto &[i , w] : adj[node]){
if (i == par) continue;
for (int j = 0 ; j <= k ; j++){
dp[i][j][2] = min(dp[i][j][2] , dp[i][j][0]);
if (j >= w) {
int odp = (j >= 2*w && dp[node][j-w][2] == dp[i][j-2*w][0] + 1 ? dp[node][j-w][1] : dp[node][j-w][2]);
dp[i][j][2] = min(dp[i][j][2] , odp + 1);
}
}
dfs2(i , node);
}
}
signed best_path(signed N, signed K, signed H[][2], signed L[])
{
srand(time(0));
for (int i = 0 ; i < 100 ; i++) {
int a = rand()%((int)2e5) , b = rand()%100;
dp[a][b][0] = dp[a][b][1] = dp[a][b][2] = 1e9;
}
cout << (sizeof dp)/(1<<20);
adj.assign(N , {});
k = K;
for (int i = 0 ; i < N-1 ; i++){
adj[H[i][0]].push_back({H[i][1] , L[i]});
adj[H[i][1]].push_back({H[i][0] , L[i]});
}
for (int i = 0 ; i <= N ; i++){
for (int j = 1 ; j <= K; j++) {
for (int l = 0 ; l < 3 ; l++){
dp[i][j][l] = 1e9;
}
}
}
dfs1(0 , -1);
for (int j = 0 ; j <= K; j++) dp[0][j][2] = dp[0][j][0];
dfs2(0 , -1);
int ans = 1e9;
for (int i = 0 ; i < N ; i++){
ans = min(ans , dp[i][k][2]);
}
return (ans == 1e9 ? -1 : ans);
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 140984kb
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:
Unauthorized output
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #39:
score: 0
Wrong Answer
time: 147ms
memory: 202392kb
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:
Unauthorized output
Subtask #4:
score: 0
Skipped
Dependency #1:
0%