Task: | Jimi Hendrix |
Sender: | zxc |
Submission time: | 2016-08-04 14:23:05 +0300 |
Language: | C++ |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.06 s | details |
#2 | ACCEPTED | 0.06 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | ACCEPTED | 0.06 s | details |
#5 | ACCEPTED | 0.06 s | details |
#6 | ACCEPTED | 0.06 s | details |
#7 | ACCEPTED | 0.06 s | details |
#8 | WRONG ANSWER | 0.06 s | details |
#9 | WRONG ANSWER | 0.06 s | details |
#10 | WRONG ANSWER | 0.06 s | details |
#11 | ACCEPTED | 0.05 s | details |
#12 | WRONG ANSWER | 0.06 s | details |
#13 | ACCEPTED | 0.06 s | details |
#14 | ACCEPTED | 0.06 s | details |
#15 | ACCEPTED | 0.06 s | details |
#16 | ACCEPTED | 0.06 s | details |
#17 | WRONG ANSWER | 0.06 s | details |
#18 | ACCEPTED | 0.06 s | details |
#19 | WRONG ANSWER | 0.06 s | details |
#20 | ACCEPTED | 0.06 s | details |
#21 | WRONG ANSWER | 0.05 s | details |
#22 | ACCEPTED | 0.06 s | details |
#23 | WRONG ANSWER | 0.12 s | details |
#24 | ACCEPTED | 0.11 s | details |
#25 | ACCEPTED | 0.18 s | details |
#26 | ACCEPTED | 0.21 s | details |
#27 | ACCEPTED | 0.18 s | details |
#28 | ACCEPTED | 0.21 s | details |
#29 | ACCEPTED | 0.18 s | details |
#30 | ACCEPTED | 0.18 s | details |
#31 | WRONG ANSWER | 0.20 s | details |
#32 | WRONG ANSWER | 0.17 s | details |
#33 | ACCEPTED | 0.18 s | details |
#34 | ACCEPTED | 0.16 s | details |
#35 | WRONG ANSWER | 0.18 s | details |
#36 | ACCEPTED | 0.17 s | details |
#37 | ACCEPTED | 0.17 s | details |
#38 | WRONG ANSWER | 0.17 s | details |
#39 | ACCEPTED | 0.18 s | details |
#40 | WRONG ANSWER | 0.18 s | details |
#41 | WRONG ANSWER | 0.19 s | details |
#42 | ACCEPTED | 0.18 s | details |
#43 | WRONG ANSWER | 0.19 s | details |
#44 | ACCEPTED | 0.17 s | details |
#45 | WRONG ANSWER | 0.18 s | details |
#46 | WRONG ANSWER | 0.18 s | details |
#47 | WRONG ANSWER | 0.18 s | details |
#48 | ACCEPTED | 0.18 s | details |
#49 | WRONG ANSWER | 0.20 s | details |
#50 | WRONG ANSWER | 0.21 s | details |
#51 | WRONG ANSWER | 0.21 s | details |
#52 | WRONG ANSWER | 0.21 s | details |
#53 | ACCEPTED | 0.17 s | details |
#54 | ACCEPTED | 0.17 s | details |
Code
#include <vector> #include <cstring> #include <iostream> #define F first #define S second using namespace std; const int MN = 5e5+100; vector<pair<int, char> > v[MN]; int dp[MN]; bool used[MN]; int n,m; string s; void f1(int x) { used[x] = 1; for(auto y: v[x]) { if(!used[y.F]) { f1(y.F); int q = dp[y.F]; if(q < m && y.S == s[q]) { dp[x] = max(dp[x], dp[y.F]+1); } dp[x] = max(dp[x], dp[y.F]); } } } int f2(int x, int up) { pair<int, int> b1 = {up, -1}; pair<int, int> b2 = {0, -1}; used[x] = 1; for(auto y: v[x]) { if(!used[y.F]) { int q = dp[y.F]; if(q < m && y.S == s[q]) { ++q; } if(q > b1.F) { b2 = b1; b1 = {q, y.F}; } else if(q > b2.F) { b2 = {q, y.F}; } } } if(b1.F == m) { return x; } for(auto y: v[x]) { if(!used[y.F]) { int nUp; if(b1.S == y.F) { nUp = b2.F; } else { nUp = b1.F; } if(nUp < m && y.S == s[nUp]) { ++nUp; } int q = f2(y.F, nUp); if(q != -1) return q; } } return -1; } int f3(int x, int q) { used[x] = 1; if(q == m) { return x; } for(auto y: v[x]) { if(!used[y.F]) { int nq = q; if(y.S == s[q]) { ++nq; } int w = f3(y.F, nq); if(w != -1) return w; } } return -1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; for(int i = 0; i < n-1; ++i) { int a,b; char c; cin>>a>>b>>c; v[a].push_back({b, c}); v[b].push_back({a, c}); } cin>>s; f1(1); memset(used, 0, sizeof used); int root = f2(1, 0); if(root == -1) { cout<<-1<<' '<<-1<<endl; } memset(used, 0, sizeof used); int q = f3(root, 0); cout<<root<<' '<<q<<endl; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
9 3 1 2 a 2 3 b 2 4 a 4 5 b ... |
correct output |
---|
1 9 |
user output |
---|
3 9 |
Test 2
Verdict: ACCEPTED
input |
---|
2 1 1 2 b b |
correct output |
---|
2 1 |
user output |
---|
1 2 |
Test 3
Verdict: ACCEPTED
input |
---|
2 1 1 2 k p |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 4
Verdict: ACCEPTED
input |
---|
10 2 1 4 a 7 5 c 1 9 a 10 1 c ... |
correct output |
---|
2 1 |
user output |
---|
1 8 |
Test 5
Verdict: ACCEPTED
input |
---|
10 5 6 1 c 7 6 a 7 8 c 6 5 c ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 6
Verdict: ACCEPTED
input |
---|
10 3 3 10 c 1 9 b 4 8 a 10 4 b ... |
correct output |
---|
10 1 |
user output |
---|
1 10 |
Test 7
Verdict: ACCEPTED
input |
---|
10 5 9 1 c 5 4 c 1 7 a 3 9 c ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 8
Verdict: WRONG ANSWER
input |
---|
10 2 9 10 c 9 8 c 9 3 c 9 4 c ... |
correct output |
---|
1 10 |
user output |
---|
10 -1 |
Test 9
Verdict: WRONG ANSWER
input |
---|
10 2 10 3 c 10 4 b 10 8 b 10 1 a ... |
correct output |
---|
1 9 |
user output |
---|
3 -1 |
Test 10
Verdict: WRONG ANSWER
input |
---|
10 2 6 7 e 6 9 l 6 2 q 6 10 i ... |
correct output |
---|
1 9 |
user output |
---|
9 -1 |
Test 11
Verdict: ACCEPTED
input |
---|
10 2 4 1 s 4 6 y 4 9 p 4 2 t ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 12
Verdict: WRONG ANSWER
input |
---|
1000 11 987 593 b 428 821 a 865 116 b 676 817 a ... |
correct output |
---|
998 1 |
user output |
---|
1 -1 |
Test 13
Verdict: ACCEPTED
input |
---|
1000 10 782 148 a 498 256 a 389 269 a 156 291 b ... |
correct output |
---|
652 1 |
user output |
---|
1 561 |
Test 14
Verdict: ACCEPTED
input |
---|
1000 20 657 328 a 185 518 a 778 343 b 56 390 a ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 15
Verdict: ACCEPTED
input |
---|
1000 10 555 641 a 309 489 b 799 943 b 934 662 a ... |
correct output |
---|
953 332 |
user output |
---|
381 774 |
Test 16
Verdict: ACCEPTED
input |
---|
1000 6 161 816 b 25 712 b 540 233 b 980 204 c ... |
correct output |
---|
990 1 |
user output |
---|
1 536 |
Test 17
Verdict: WRONG ANSWER
input |
---|
1000 635 163 159 o 615 797 x 192 770 n 211 860 j ... |
correct output |
---|
650 951 |
user output |
---|
151 -1 |
Test 18
Verdict: ACCEPTED
input |
---|
1000 191 370 983 e 792 207 u 260 334 t 504 718 t ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 19
Verdict: WRONG ANSWER
input |
---|
1000 40 471 594 o 345 995 n 973 405 y 215 646 o ... |
correct output |
---|
1 982 |
user output |
---|
556 -1 |
Test 20
Verdict: ACCEPTED
input |
---|
1000 100 151 902 a 730 935 b 295 369 b 823 145 a ... |
correct output |
---|
948 1 |
user output |
---|
1 103 |
Test 21
Verdict: WRONG ANSWER
input |
---|
1000 2 660 306 n 660 778 l 660 924 y 660 902 n ... |
correct output |
---|
988 969 |
user output |
---|
70 -1 |
Test 22
Verdict: ACCEPTED
input |
---|
1000 2 526 579 a 526 150 b 526 168 a 526 24 b ... |
correct output |
---|
1000 1 |
user output |
---|
1 579 |
Test 23
Verdict: WRONG ANSWER
input |
---|
200000 2 140844 190697 r 140844 124115 f 140844 112461 i 140844 19992 d ... |
correct output |
---|
124115 199952 |
user output |
---|
73325 -1 |
Test 24
Verdict: ACCEPTED
input |
---|
200000 2 105421 5980 b 105421 150207 a 105421 115929 a 105421 77625 b ... |
correct output |
---|
200000 1 |
user output |
---|
1 5980 |
Test 25
Verdict: ACCEPTED
input |
---|
200000 50000 38207 51908 a 123390 86325 b 123134 78235 b 104677 7330 a ... |
correct output |
---|
112796 1 |
user output |
---|
1 133316 |
Test 26
Verdict: ACCEPTED
input |
---|
200000 150000 116487 13268 b 84833 43815 b 40993 188837 a 197098 131672 a ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 27
Verdict: ACCEPTED
input |
---|
200000 5000 6663 37269 l 74938 58143 w 79955 85205 e 172041 175241 z ... |
correct output |
---|
199644 1 |
user output |
---|
1 96212 |
Test 28
Verdict: ACCEPTED
input |
---|
200000 10000 162365 187926 o 25849 45282 n 69475 76654 d 59397 127873 g ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 29
Verdict: ACCEPTED
input |
---|
200000 4736 135910 152433 b 196857 44930 b 180142 58474 b 123198 131735 a ... |
correct output |
---|
193336 1 |
user output |
---|
1 112766 |
Test 30
Verdict: ACCEPTED
input |
---|
200000 54739 116541 156209 b 112813 171247 b 134494 179457 b 52303 59188 b ... |
correct output |
---|
175912 1 |
user output |
---|
1 133751 |
Test 31
Verdict: WRONG ANSWER
input |
---|
200000 49999 117084 195231 a 38504 191202 n 134618 132918 i 24748 150597 v ... |
correct output |
---|
198783 1 |
user output |
---|
1 -1 |
Test 32
Verdict: WRONG ANSWER
input |
---|
200000 20 56534 21846 a 127466 99775 b 197009 10481 a 13071 25861 a ... |
correct output |
---|
154647 179047 |
user output |
---|
68809 -1 |
Test 33
Verdict: ACCEPTED
input |
---|
200000 18 25645 115335 b 138086 169629 b 147195 28130 a 90251 19229 b ... |
correct output |
---|
1 11192 |
user output |
---|
184 118646 |
Test 34
Verdict: ACCEPTED
input |
---|
200000 15 130040 52065 a 85066 121947 a 142587 138972 c 98852 109707 b ... |
correct output |
---|
186271 1 |
user output |
---|
1 189745 |
Test 35
Verdict: WRONG ANSWER
input |
---|
200000 13 186972 158038 n 141304 144334 c 150644 92260 d 75472 56494 e ... |
correct output |
---|
134673 188304 |
user output |
---|
188304 -1 |
Test 36
Verdict: ACCEPTED
input |
---|
200000 22 77116 177355 b 41248 8511 a 196560 61055 b 93074 47152 b ... |
correct output |
---|
101231 1 |
user output |
---|
1 55135 |
Test 37
Verdict: ACCEPTED
input |
---|
200000 24 12092 977 b 89606 92554 a 98999 130713 b 29359 58778 a ... |
correct output |
---|
45421 191976 |
user output |
---|
169667 127234 |
Test 38
Verdict: WRONG ANSWER
input |
---|
200000 32 42678 46956 a 85804 92343 a 58647 187834 a 40022 25789 a ... |
correct output |
---|
170898 83806 |
user output |
---|
141727 -1 |
Test 39
Verdict: ACCEPTED
input |
---|
200000 37 97344 4860 b 59032 105557 b 33232 135880 a 41849 198146 b ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 40
Verdict: WRONG ANSWER
input |
---|
200000 35 165160 188580 b 169019 179034 a 162600 167716 b 12953 68090 b ... |
correct output |
---|
34556 152796 |
user output |
---|
121411 -1 |
Test 41
Verdict: WRONG ANSWER
input |
---|
200000 36 25981 130203 b 96700 180125 a 127368 165961 b 64857 173799 b ... |
correct output |
---|
140998 25928 |
user output |
---|
82384 -1 |
Test 42
Verdict: ACCEPTED
input |
---|
200000 37 84272 141200 a 115974 60401 b 164159 9233 b 95061 109295 a ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 43
Verdict: WRONG ANSWER
input |
---|
200000 9 64062 160380 r 125886 155571 c 171774 169538 y 98278 87688 l ... |
correct output |
---|
178549 166726 |
user output |
---|
34044 -1 |
Test 44
Verdict: ACCEPTED
input |
---|
200000 10 180259 144845 g 116606 49642 c 17065 195194 h 19110 15737 w ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 45
Verdict: WRONG ANSWER
input |
---|
200000 28 69795 159223 b 120740 49968 a 175591 112576 b 13475 97987 b ... |
correct output |
---|
191304 139389 |
user output |
---|
35027 -1 |
Test 46
Verdict: WRONG ANSWER
input |
---|
200000 29 196920 93284 b 10733 37080 b 60158 81484 a 182923 50537 a ... |
correct output |
---|
118826 166004 |
user output |
---|
102972 -1 |
Test 47
Verdict: WRONG ANSWER
input |
---|
200000 29 139335 36430 a 19077 167148 a 14826 196018 a 24497 91018 b ... |
correct output |
---|
176667 184941 |
user output |
---|
22290 -1 |
Test 48
Verdict: ACCEPTED
input |
---|
200000 38 198494 65812 a 154023 48530 a 161230 125892 a 163972 48765 b ... |
correct output |
---|
-1 -1 |
user output |
---|
-1 -1 -1 -1 |
Test 49
Verdict: WRONG ANSWER
input |
---|
200000 100000 138756 91790 c 50567 42961 d 199463 59094 d 158218 93083 e ... |
correct output |
---|
120276 158931 |
user output |
---|
158931 -1 |
Test 50
Verdict: WRONG ANSWER
input |
---|
200000 100000 93749 174202 a 182960 2304 n 23460 111271 d 142390 124490 h ... |
correct output |
---|
197101 82602 |
user output |
---|
82602 -1 |
Test 51
Verdict: WRONG ANSWER
input |
---|
200000 50000 26351 4065 d 190076 154406 b 47708 176166 c 56748 94747 d ... |
correct output |
---|
102345 166560 |
user output |
---|
166560 -1 |
Test 52
Verdict: WRONG ANSWER
input |
---|
200000 50000 25937 89996 f 147254 157058 r 72097 126197 k 143403 116253 i ... |
correct output |
---|
175469 125703 |
user output |
---|
125703 -1 |
Test 53
Verdict: ACCEPTED
input |
---|
200000 1000 138872 149623 e 161260 117770 a 151105 54329 a 120464 187446 d ... |
correct output |
---|
188942 1 |
user output |
---|
1 143516 |
Test 54
Verdict: ACCEPTED
input |
---|
200000 1000 53986 146114 r 139076 142403 c 86688 88562 g 40058 165888 g ... |
correct output |
---|
140202 1 |
user output |
---|
1 127219 |