QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#599397 | #2002. Race | iframe# | 21 | 67ms | 56876kb | C++17 | 1.3kb | 2024-09-29 04:05:49 | 2024-09-29 04:05:49 |
Judging History
answer
#include "race.h"
#include <iostream>
#include <vector>
#include <array>
using ll = long long;
std::vector<std::array<int, 2>> adj[200000];
int depth[1000];
ll dist[1000];
void dfs(int i, int p){
for(const auto &[x, d] : adj[i]) if(x != p)
depth[x] = depth[i]+1, dist[x] = dist[i]+d,
dfs(x, i);
}
int subpath[200000][101];
void dfs2(int i, int p){
for(const auto &[x, d] : adj[i]) if(x != p){
dfs2(x, i);
for(int j=0; j+d<101; ++j)
subpath[i][j+d] = std::min(subpath[i][j+d],
subpath[x][j] + 1);
}
}
int best_path(int n, int k, int h[][2], int l[]){
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]});
}
int best = n;
if(k <= 100 && n > 100){
for(int i=0; i<n; ++i)
for(int j=1; j<101; ++j)
subpath[i][j] = n;
dfs2(0, -1);
/*
for(int i=0; i<n; ++i)
for(int j=0; j<=k; ++j)
std::cout << subpath[i][j]%n << " \n"[j==k];
*/
for(int i=0; i<n; ++i)
for(int j=0; j+j<=k; ++j)
best = std::min(best,
subpath[i][j] + subpath[i][k-j]);
}else{
for(int i=0; i<n; ++i){
dist[i] = 0, depth[i] = 0;
dfs(i, -1);
for(int j=0; j<n; ++j) if(dist[j] == k)
best = std::min(best, depth[j]);
}
}
return best == n ? -1 : best;
}
詳細信息
Subtask #1:
score: 9
Accepted
Test #1:
score: 9
Accepted
time: 0ms
memory: 13936kb
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: 9
Accepted
time: 0ms
memory: 13604kb
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
Accepted
time: 0ms
memory: 14308kb
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: 9
Accepted
time: 3ms
memory: 14036kb
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: 9
Accepted
time: 3ms
memory: 14220kb
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: 9
Accepted
time: 0ms
memory: 14196kb
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: 9
Accepted
time: 0ms
memory: 14208kb
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: 9
Accepted
time: 0ms
memory: 14564kb
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: 9
Accepted
time: 0ms
memory: 14312kb
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: 9
Accepted
time: 3ms
memory: 12704kb
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: 9
Accepted
time: 0ms
memory: 13496kb
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: 9
Accepted
time: 0ms
memory: 14424kb
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: 9
Accepted
time: 0ms
memory: 13876kb
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: 9
Accepted
time: 0ms
memory: 13128kb
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: 9
Accepted
time: 3ms
memory: 14600kb
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: 9
Accepted
time: 0ms
memory: 14500kb
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
Accepted
time: 0ms
memory: 13180kb
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:
Correct.
Test #18:
score: 9
Accepted
time: 3ms
memory: 14360kb
input:
100 100 0 1 3 1 2 6 2 3 1 3 4 9 4 5 8 5 6 0 6 7 6 7 8 10 8 9 4 9 10 5 10 11 1 11 12 1 12 13 9 13 14 4 14 15 5 15 16 7 16 17 7 17 18 5 18 19 6 19 20 8 20 21 1 21 22 5 22 23 1 23 24 2 24 25 3 25 26 7 26 27 8 27 28 3 28 29 9 29 30 9 30 31 3 31 32 1 32 33 8 33 34 5 34 35 6 35 36 5 36 37 5 37 38 2 38 39 ...
output:
Correct.
Subtask #2:
score: 12
Accepted
Dependency #1:
100%
Accepted
Test #19:
score: 12
Accepted
time: 0ms
memory: 13788kb
input:
10 7 5 0 1 2 0 1 8 0 2 9 5 2 3 9 1 1 9 3 4 8 3 7 3 3 6 8 1 3
output:
Correct.
Test #20:
score: 12
Accepted
time: 5ms
memory: 14452kb
input:
1000 199112 762 339 28482 749 762 227 319 749 53263 552 762 12523 716 339 46366 613 319 74345 249 339 72086 42 249 2870 589 552 5725 179 42 53677 760 249 5715 298 552 163 67 179 2902 573 319 2 219 573 10621 539 749 4024 335 219 254 727 42 6119 429 298 8518 825 219 17484 248 249 43205 244 67 11387 31...
output:
Correct.
Test #21:
score: 12
Accepted
time: 4ms
memory: 13444kb
input:
1000 324823 854 731 3848 755 731 22202 116 731 82580 306 116 38 985 755 21493 894 755 75174 769 306 7726 382 731 69175 848 985 30471 954 755 7233 249 894 9073 370 854 1356 408 249 51635 227 370 3175 792 370 3593 496 985 80557 428 227 21 301 854 4598 60 954 6099 827 60 44025 37 954 35890 945 731 8090...
output:
Correct.
Test #22:
score: 12
Accepted
time: 4ms
memory: 12788kb
input:
1000 366977 448 502 61189 568 502 12171 32 448 470 182 32 57463 409 448 63075 159 409 57598 901 568 1262 599 568 53 353 901 96550 912 32 16190 217 568 3427 60 448 10526 799 353 1175 549 409 2572 57 159 34913 743 549 2126 293 409 5579 849 60 17348 357 32 11329 477 502 53441 516 477 2105 260 599 84783...
output:
Correct.
Test #23:
score: 12
Accepted
time: 8ms
memory: 13052kb
input:
1000 653406 75 813 588 943 75 95226 449 943 27576 655 943 7287 656 943 48742 138 656 75413 373 138 60 285 449 44721 211 285 16387 699 75 1862 74 813 95942 86 813 35501 723 656 6301 861 373 15368 27 699 53373 492 813 97529 97 699 10036 728 75 77032 781 74 2862 124 728 16153 944 656 23013 745 74 99720...
output:
Correct.
Test #24:
score: 12
Accepted
time: 4ms
memory: 14560kb
input:
1000 709447 236 940 32176 915 940 37864 828 915 4407 537 828 42618 37 940 1193 454 537 61661 209 37 67522 200 209 17413 565 454 42932 433 565 81882 148 37 36134 4 209 92927 467 828 88968 163 148 71394 403 467 96051 749 433 98105 423 537 53373 294 163 52687 165 209 9587 824 148 3534 637 403 97839 685...
output:
Correct.
Test #25:
score: 12
Accepted
time: 6ms
memory: 11444kb
input:
1000 782099 83 140 49127 178 83 5651 988 178 72207 735 178 75496 152 735 2616 453 735 47873 499 152 86016 31 152 65924 548 31 21058 613 31 28790 400 31 28539 225 400 64668 907 613 2098 27 548 91168 668 27 22662 160 27 37531 436 400 11586 440 225 48126 718 440 59242 984 718 73379 922 27 56416 728 668...
output:
Correct.
Test #26:
score: 12
Accepted
time: 14ms
memory: 13592kb
input:
921 590007 171 474 42940 474 831 16568 831 304 14707 304 588 47559 588 873 484 873 248 44533 248 778 30660 778 423 13081 423 757 39197 757 858 31373 858 31 5651 31 326 47096 326 43 12437 43 367 8017 367 175 37267 175 711 20278 711 868 32767 868 166 1147 166 483 20699 483 694 17553 694 343 31933 343 ...
output:
Correct.
Test #27:
score: 12
Accepted
time: 14ms
memory: 14340kb
input:
892 812365 150 547 47626 547 211 8069 211 450 5073 450 83 15844 83 463 32533 463 162 18136 162 616 38946 616 208 46311 208 426 13486 426 711 1563 711 5 34500 5 732 14509 732 348 5191 348 143 41434 143 434 36868 434 129 13120 129 333 2262 333 215 28924 215 504 27493 504 519 45708 519 752 9209 752 798...
output:
Correct.
Test #28:
score: 12
Accepted
time: 9ms
memory: 12836kb
input:
826 930612 414 268 18141 268 369 44539 369 418 21069 418 65 22682 65 269 23679 269 626 2522 626 538 23730 538 705 3402 705 701 27463 701 20 6363 20 513 49707 513 78 44688 78 379 6114 379 386 16315 386 56 159 56 88 19145 88 430 4537 430 743 44073 743 794 16188 794 603 24946 603 480 37555 480 420 2342...
output:
Correct.
Test #29:
score: 12
Accepted
time: 13ms
memory: 13236kb
input:
826 795916 373 680 3800 680 395 1305 395 658 3185 658 795 2839 795 605 139 605 283 2268 283 455 1725 455 451 3782 451 117 277 117 193 4895 193 103 4497 103 254 1140 254 416 384 416 628 4296 628 738 2279 738 275 4969 275 689 2906 689 514 1281 514 396 3635 396 108 2925 108 232 3781 232 306 524 306 293...
output:
Correct.
Test #30:
score: 12
Accepted
time: 0ms
memory: 13448kb
input:
100 22 25 78 3 21 78 1 63 78 2 72 21 1 77 21 2 57 77 3 70 21 3 5 21 3 95 72 2 34 78 3 84 25 1 27 72 3 52 84 2 66 70 1 4 72 1 90 78 3 20 95 3 89 95 1 17 20 3 58 25 3 8 34 3 16 90 1 9 27 3 39 34 3 3 20 2 1 95 3 47 25 3 80 84 1 62 21 3 54 1 3 98 63 1 38 34 3 69 62 1 42 58 3 86 17 1 48 57 2 19 48 2 94 6...
output:
Correct.
Test #31:
score: 12
Accepted
time: 10ms
memory: 13416kb
input:
925 508606 242 124 4984 124 859 874 859 674 26 674 153 626 153 551 977 551 841 2598 841 429 3246 429 610 4421 610 739 4795 739 821 2179 821 508 3127 508 432 2882 432 923 3375 923 308 8 308 842 3669 842 133 4866 133 3 766 3 186 3762 186 80 4224 80 82 4814 82 426 390 426 818 1502 818 147 1092 147 682 ...
output:
Correct.
Test #32:
score: 12
Accepted
time: 4ms
memory: 12680kb
input:
1000 764 518 191 46 805 518 52 381 518 29 422 518 40 4 191 18 817 422 38 894 422 11 821 191 25 896 381 16 349 191 42 39 349 34 179 349 25 772 179 30 912 191 29 323 805 3 636 894 6 228 821 14 197 381 20 255 821 5 91 422 27 162 228 2 781 805 36 352 323 5 417 197 34 559 255 63 994 91 63 7 559 22 784 38...
output:
Correct.
Test #33:
score: 12
Accepted
time: 6ms
memory: 12644kb
input:
1000 920236 750 950 557320 814 750 987579 858 814 966276 143 814 866618 403 858 284391 598 143 125262 536 143 125701 626 598 161758 889 536 330196 396 889 548743 177 889 863105 818 396 751812 271 396 101375 792 177 760904 414 396 710344 661 818 318258 270 818 400012 495 271 667454 653 270 153771 754...
output:
Correct.
Test #34:
score: 12
Accepted
time: 9ms
memory: 12788kb
input:
1000 753860 227 458 21111 570 227 84533 611 570 150029 786 570 269774 412 611 379594 805 412 887270 565 412 317425 367 412 107659 558 565 642786 784 558 978539 780 558 555471 683 784 905071 643 784 169983 802 558 851006 557 784 445461 774 784 708696 179 643 390915 174 683 267650 452 174 368580 806 7...
output:
Correct.
Test #35:
score: 12
Accepted
time: 2ms
memory: 13824kb
input:
1000 864337 468 266 72959 913 266 824883 130 468 336929 397 130 481568 810 913 144973 234 468 65791 174 130 639277 226 266 414771 853 397 519231 561 130 825789 988 130 609107 968 266 494692 443 810 685016 292 810 709882 980 810 663969 876 853 171846 826 226 530930 33 968 725219 514 810 512667 993 39...
output:
Correct.
Test #36:
score: 12
Accepted
time: 5ms
memory: 13028kb
input:
1000 841712 299 962 22090 305 299 45982 29 305 9920 106 962 9594 822 106 52591 357 299 32937 302 29 55377 307 302 78108 278 305 63036 244 106 29944 654 278 59540 418 822 60315 314 106 26572 789 357 31618 49 29 24141 497 418 64807 178 49 69975 111 789 3552 695 178 39397 513 789 53867 129 178 35932 72...
output:
Correct.
Test #37:
score: 12
Accepted
time: 4ms
memory: 13836kb
input:
1000 337882 544 223 336251 299 223 158955 355 223 3643 585 544 157536 351 355 160555 233 351 171262 999 355 273403 651 233 31864 425 585 332969 16 223 191669 758 351 181423 872 223 177793 939 355 154493 8 16 202646 511 872 100159 23 511 257639 279 223 127215 984 999 317347 358 23 205878 473 425 3280...
output:
Correct.
Test #38:
score: 12
Accepted
time: 8ms
memory: 12576kb
input:
1000 801624 832 556 1000000 916 832 1000000 407 916 1000000 383 407 1000000 640 556 1000000 532 407 1000000 347 407 1000000 952 640 1000000 135 832 1000000 577 556 1000000 771 577 1000000 236 347 1000000 587 577 1000000 888 587 1000000 125 347 1000000 156 125 1000000 79 771 1000000 445 156 1000000 2...
output:
Correct.
Subtask #3:
score: 0
Wrong Answer
Test #39:
score: 0
Wrong Answer
time: 67ms
memory: 56876kb
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:
Incorrect. Returned 10, Expected 11.
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%