Task: | Alpine valley |
Sender: | vgtcross |
Submission time: | 2023-04-18 14:13:17 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 59 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 9 |
#2 | ACCEPTED | 27 |
#3 | ACCEPTED | 23 |
#4 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 2, 4 | details |
#2 | ACCEPTED | 0.01 s | 2, 4 | details |
#3 | ACCEPTED | 0.02 s | 1, 4 | details |
#4 | ACCEPTED | 0.01 s | 1, 4 | details |
#5 | ACCEPTED | 0.01 s | 1, 4 | details |
#6 | ACCEPTED | 0.01 s | 1, 3, 4 | details |
#7 | ACCEPTED | 0.01 s | 2, 4 | details |
#8 | ACCEPTED | 0.01 s | 2, 4 | details |
#9 | ACCEPTED | 0.01 s | 2, 4 | details |
#10 | ACCEPTED | 0.01 s | 2, 4 | details |
#11 | ACCEPTED | 0.01 s | 2, 4 | details |
#12 | ACCEPTED | 0.01 s | 2, 4 | details |
#13 | ACCEPTED | 0.01 s | 2, 3, 4 | details |
#14 | ACCEPTED | 0.01 s | 2, 3, 4 | details |
#15 | ACCEPTED | 0.01 s | 2, 3, 4 | details |
#16 | ACCEPTED | 0.02 s | 2, 4 | details |
#17 | ACCEPTED | 0.13 s | 3, 4 | details |
#18 | ACCEPTED | 0.12 s | 3, 4 | details |
#19 | ACCEPTED | 0.13 s | 3, 4 | details |
#20 | ACCEPTED | 0.15 s | 3, 4 | details |
#21 | ACCEPTED | 0.15 s | 3, 4 | details |
#22 | ACCEPTED | 0.17 s | 3, 4 | details |
#23 | TIME LIMIT EXCEEDED | -- | 4 | details |
#24 | TIME LIMIT EXCEEDED | -- | 4 | details |
#25 | TIME LIMIT EXCEEDED | -- | 4 | details |
#26 | TIME LIMIT EXCEEDED | -- | 4 | details |
#27 | TIME LIMIT EXCEEDED | -- | 4 | details |
#28 | TIME LIMIT EXCEEDED | -- | 4 | details |
#29 | TIME LIMIT EXCEEDED | -- | 4 | details |
#30 | TIME LIMIT EXCEEDED | -- | 4 | details |
#31 | TIME LIMIT EXCEEDED | -- | 4 | details |
#32 | TIME LIMIT EXCEEDED | -- | 4 | details |
#33 | TIME LIMIT EXCEEDED | -- | 4 | details |
#34 | TIME LIMIT EXCEEDED | -- | 4 | details |
#35 | TIME LIMIT EXCEEDED | -- | 4 | details |
#36 | TIME LIMIT EXCEEDED | -- | 4 | details |
#37 | TIME LIMIT EXCEEDED | -- | 4 | details |
#38 | TIME LIMIT EXCEEDED | -- | 4 | details |
Code
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100100; int n, s, q, e; vector<array<ll, 3>> adj[N]; bool shop[N]; bool dfs(int u, int p, int i) { if (u == e) return 1; for (auto v: adj[u]) if (v[0] != p && v[2] != i) { bool good = dfs(v[0], u, i); if (good) return 1; } return 0; } ll dfs2(int u, int p, int i) { if (shop[u]) return 0; ll d = 1e18; for (auto v: adj[u]) if (v[0] != p && v[2] != i) { d = min(d, dfs2(v[0], u, i) + v[1]); } return d; } int jump[18][N]; int dp[N]; int node[N]; void dfs3(int u, int d) { dp[u] = d; for (auto v: adj[u]) if (v[0] != jump[0][u]) { jump[0][v[0]] = u; node[v[2]] = v[0]; dfs3(v[0], d+1); } } void solve() { cin >> n >> s >> q >> e; --e; for (int i = 0; i < n-1; ++i) { int u, v, w; cin >> u >> v >> w; adj[u-1].push_back({v-1, w, i}); adj[v-1].push_back({u-1, w, i}); } for (int i = 0; i < s; ++i) { int c; cin >> c; shop[c-1] = 1; } if (s == n) { jump[0][e] = -1; dfs3(e, 0); for (int j = 1; j < 18; ++j) { for (int i = 0; i < n; ++i) { jump[j][i] = jump[j-1][i] == -1 ? -1 : jump[j-1][jump[j-1][i]]; } } while (q--) { int i, r; cin >> i >> r; --i;--r; int dr = dp[r]; int di = dp[node[i]]; if (di > dr) { cout << "escaped\n"; } else { for (int j = 18; j >= 0; --j) { if (dr - (1 << j) > di) { dr -= 1 << j; r = jump[j][r]; } } cout << (r == node[i] || jump[0][r] == node[i] ? "0\n" : "escaped\n"); } } } else { while (q--) { int i, r; cin >> i >> r; --i;--r; bool good = dfs(r, -1, i); ll d = dfs2(r, -1, i); if (good) cout << "escaped\n"; else if (d < 1e16) cout << d << '\n'; else cout << "oo\n"; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
Test details
Test 1
Group: 2, 4
Verdict: ACCEPTED
input |
---|
5 2 3 1 1 2 3 1 3 2 3 4 1 3 5 2 ... |
correct output |
---|
escaped 3 oo |
user output |
---|
escaped 3 oo |
Test 2
Group: 2, 4
Verdict: ACCEPTED
input |
---|
10 2 5 4 7 2 3 4 8 3 9 10 1 6 7 3 ... |
correct output |
---|
8 escaped escaped escaped 0 |
user output |
---|
8 escaped escaped escaped 0 |
Test 3
Group: 1, 4
Verdict: ACCEPTED
input |
---|
100 1 10000 16 55 54 51 52 51 42 61 60 65 8 7 2 ... |
correct output |
---|
escaped 556 102 escaped escaped ... |
user output |
---|
escaped 556 102 escaped escaped ... Truncated |
Test 4
Group: 1, 4
Verdict: ACCEPTED
input |
---|
100 10 10000 33 9 8 121427413 62 61 566068708 54 53 965740432 15 14 900558622 ... |
correct output |
---|
escaped escaped escaped escaped escaped ... |
user output |
---|
escaped escaped escaped escaped escaped ... Truncated |
Test 5
Group: 1, 4
Verdict: ACCEPTED
input |
---|
100 50 10000 41 50 49 169637902 97 96 415399500 21 20 685901242 80 79 491260472 ... |
correct output |
---|
escaped escaped escaped 0 236683917 ... |
user output |
---|
escaped escaped escaped 0 236683917 ... Truncated |
Test 6
Group: 1, 3, 4
Verdict: ACCEPTED
input |
---|
100 100 10000 72 72 71 184167801 54 53 889251906 84 83 405385709 60 59 13704743 ... |
correct output |
---|
0 0 escaped escaped escaped ... |
user output |
---|
0 0 escaped escaped escaped ... Truncated |
Test 7
Group: 2, 4
Verdict: ACCEPTED
input |
---|
1000 10 1000 775 118 928 460113608 474 70 44866463 733 393 759680660 710 206 648722901 ... |
correct output |
---|
oo escaped escaped escaped escaped ... |
user output |
---|
oo escaped escaped escaped escaped ... Truncated |
Test 8
Group: 2, 4
Verdict: ACCEPTED
input |
---|
1000 10 1000 327 723 162 446180859 68 802 80310794 102 267 312376651 107 624 882387970 ... |
correct output |
---|
oo escaped oo escaped escaped ... |
user output |
---|
oo escaped oo escaped escaped ... Truncated |
Test 9
Group: 2, 4
Verdict: ACCEPTED
input |
---|
1000 10 1000 650 119 161 836736621 838 410 854228864 199 424 454768400 60 883 388702647 ... |
correct output |
---|
escaped escaped escaped escaped escaped ... |
user output |
---|
escaped escaped escaped escaped escaped ... Truncated |
Test 10
Group: 2, 4
Verdict: ACCEPTED
input |
---|
1000 100 1000 904 68 170 85699385 237 651 740139463 43 176 201438090 106 79 819260668 ... |
correct output |
---|
escaped oo escaped 1775619050 escaped ... |
user output |
---|
escaped oo escaped 1775619050 escaped ... Truncated |
Test 11
Group: 2, 4
Verdict: ACCEPTED
input |
---|
1000 100 1000 529 463 789 845004864 358 945 244505855 758 337 184497598 576 316 809439021 ... |
correct output |
---|
escaped 0 696530048 oo escaped ... |
user output |
---|
escaped 0 696530048 oo escaped ... Truncated |
Test 12
Group: 2, 4
Verdict: ACCEPTED
input |
---|
1000 100 1000 399 347 194 896931732 85 77 502917238 383 704 495548440 249 529 89377715 ... |
correct output |
---|
escaped 1803283908 escaped escaped 725025384 ... |
user output |
---|
escaped 1803283908 escaped escaped 725025384 ... Truncated |
Test 13
Group: 2, 3, 4
Verdict: ACCEPTED
input |
---|
1000 1000 1000 417 955 976 76162239 18 206 157439239 568 995 870854038 144 131 177990967 ... |
correct output |
---|
escaped 0 0 0 0 ... |
user output |
---|
escaped 0 0 0 0 ... Truncated |
Test 14
Group: 2, 3, 4
Verdict: ACCEPTED
input |
---|
1000 1000 1000 5 499 981 674767192 867 11 231983677 289 607 850347433 90 435 109149869 ... |
correct output |
---|
escaped 0 escaped escaped 0 ... |
user output |
---|
escaped 0 escaped escaped 0 ... Truncated |
Test 15
Group: 2, 3, 4
Verdict: ACCEPTED
input |
---|
1000 1000 1000 402 827 566 831751863 177 338 737463577 130 290 477228687 381 865 208330027 ... |
correct output |
---|
escaped escaped escaped escaped escaped ... |
user output |
---|
escaped escaped escaped escaped escaped ... Truncated |
Test 16
Group: 2, 4
Verdict: ACCEPTED
input |
---|
1000 250 1000 719 955 478 999987900 118 129 1 693 642 1 89 10 1 ... |
correct output |
---|
escaped escaped escaped 999977335 999996043 ... |
user output |
---|
escaped escaped escaped 999977335 999996043 ... Truncated |
Test 17
Group: 3, 4
Verdict: ACCEPTED
input |
---|
100000 100000 100000 12006 92983 79841 908116525 62826 38940 643240290 40394 33248 544303480 39790 52014 996656288 ... |
correct output |
---|
0 escaped 0 escaped escaped ... |
user output |
---|
0 escaped 0 escaped escaped ... Truncated |
Test 18
Group: 3, 4
Verdict: ACCEPTED
input |
---|
100000 100000 100000 43094 5443 54581 582924938 89476 92046 904127360 75423 44348 666119170 81404 62453 705128933 ... |
correct output |
---|
escaped escaped escaped 0 0 ... |
user output |
---|
escaped escaped escaped 0 0 ... Truncated |
Test 19
Group: 3, 4
Verdict: ACCEPTED
input |
---|
100000 100000 100000 9488 85370 19201 696298836 18577 46570 748157745 93114 16265 496529753 72078 35717 412237533 ... |
correct output |
---|
escaped escaped 0 escaped 0 ... |
user output |
---|
escaped escaped 0 escaped 0 ... Truncated |
Test 20
Group: 3, 4
Verdict: ACCEPTED
input |
---|
100000 100000 100000 92001 67551 36343 183011569 68768 16547 690994742 13471 67372 20695710 98903 83909 529919884 ... |
correct output |
---|
escaped 0 0 0 0 ... |
user output |
---|
escaped 0 0 0 0 ... Truncated |
Test 21
Group: 3, 4
Verdict: ACCEPTED
input |
---|
100000 100000 100000 63926 18158 65925 685699704 99966 63209 722194632 56258 49447 38979748 29360 52524 25423329 ... |
correct output |
---|
escaped escaped escaped escaped escaped ... |
user output |
---|
escaped escaped escaped escaped escaped ... Truncated |
Test 22
Group: 3, 4
Verdict: ACCEPTED
input |
---|
100000 100000 100000 85193 49261 94283 81875369 4550 87086 277612782 72700 32371 96444536 35214 5979 709167976 ... |
correct output |
---|
0 escaped escaped escaped 0 ... |
user output |
---|
0 escaped escaped escaped 0 ... Truncated |
Test 23
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 1 100000 62049 75022 73793 917598653 23223 74953 213701558 70480 94902 210482731 33079 67728 721615672 ... |
correct output |
---|
escaped oo oo oo oo ... |
user output |
---|
(empty) |
Test 24
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 1 100000 60683 9762 13929 907620072 89241 80927 134733122 82965 83054 398493573 4190 85710 220472721 ... |
correct output |
---|
escaped escaped escaped oo oo ... |
user output |
---|
(empty) |
Test 25
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 1 100000 93416 42120 30969 334590602 10610 91725 333854906 42083 81502 240679835 46376 56414 480503067 ... |
correct output |
---|
oo escaped escaped oo escaped ... |
user output |
---|
(empty) |
Test 26
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 1 100000 49260 46043 27573 782901085 51894 53168 613136964 51695 80449 302924017 93824 72798 926998901 ... |
correct output |
---|
escaped oo oo escaped oo ... |
user output |
---|
(empty) |
Test 27
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 1 100000 48778 3031 66280 306595565 79785 6125 348382536 94956 48606 123996452 55800 22463 47341587 ... |
correct output |
---|
20156757703441 escaped 20262827699543 escaped escaped ... |
user output |
---|
(empty) |
Test 28
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 100 100000 45904 91930 987 534423336 39029 44466 55162879 2591 7401 202591700 39136 56566 892409583 ... |
correct output |
---|
escaped escaped oo escaped escaped ... |
user output |
---|
(empty) |
Test 29
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 100 100000 52351 4136 69049 98258152 1792 36401 226432996 75376 71266 993314697 69397 76013 629006800 ... |
correct output |
---|
oo escaped escaped escaped oo ... |
user output |
---|
(empty) |
Test 30
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 100 100000 53445 34402 59905 406487655 56698 75242 807833720 81339 68024 45910238 65317 68290 1780385 ... |
correct output |
---|
oo escaped escaped escaped escaped ... |
user output |
---|
(empty) |
Test 31
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 100 100000 47731 54332 9781 136759305 68411 656 232175662 94782 84387 638037402 32454 10432 915608818 ... |
correct output |
---|
escaped escaped oo escaped oo ... |
user output |
---|
(empty) |
Test 32
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 100 100000 93400 41569 42438 321398411 49592 36193 851003327 97175 8604 619586051 49225 51930 774715298 ... |
correct output |
---|
escaped escaped escaped escaped 169890887130 ... |
user output |
---|
(empty) |
Test 33
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 10000 100000 93612 38831 95327 244435916 89221 84478 457809450 19641 22100 136197388 30274 55704 225978648 ... |
correct output |
---|
escaped oo oo escaped escaped ... |
user output |
---|
(empty) |
Test 34
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 10000 100000 87842 98378 17648 944109570 15907 38157 120262987 22016 83274 39186354 60388 31304 479667455 ... |
correct output |
---|
escaped 1139182192 1232429781 0 oo ... |
user output |
---|
(empty) |
Test 35
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 10000 100000 67190 83252 69978 629862602 59544 15851 9101373 65114 24734 594009368 80279 35421 30446439 ... |
correct output |
---|
escaped escaped oo escaped oo ... |
user output |
---|
(empty) |
Test 36
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 10000 100000 99161 72942 44990 542188499 43085 52327 474981003 35672 65958 618901863 47062 48069 864393688 ... |
correct output |
---|
escaped 653059479 escaped escaped 0 ... |
user output |
---|
(empty) |
Test 37
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 10000 100000 10932 61909 89572 45368675 5240 30566 274286750 59949 57340 817361702 76233 22765 595831327 ... |
correct output |
---|
escaped escaped escaped 832606240 530619380 ... |
user output |
---|
(empty) |
Test 38
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 25000 100000 61734 16733 18530 1 47096 33881 1 95659 47 1 90943 69095 1 ... |
correct output |
---|
escaped escaped escaped escaped escaped ... |
user output |
---|
(empty) |