Task: | Toll Roads |
Sender: | eXeP |
Submission time: | 2016-07-29 17:20:24 +0300 |
Language: | C++ |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.06 s | details |
#2 | WRONG ANSWER | 0.05 s | details |
#3 | WRONG ANSWER | 0.06 s | details |
#4 | WRONG ANSWER | 0.06 s | details |
#5 | WRONG ANSWER | 0.06 s | details |
#6 | WRONG ANSWER | 0.05 s | details |
#7 | WRONG ANSWER | 0.05 s | details |
#8 | ACCEPTED | 0.06 s | details |
#9 | ACCEPTED | 0.06 s | details |
#10 | WRONG ANSWER | 0.06 s | details |
#11 | WRONG ANSWER | 0.06 s | details |
#12 | WRONG ANSWER | 0.05 s | details |
#13 | WRONG ANSWER | 0.05 s | details |
#14 | WRONG ANSWER | 0.05 s | details |
#15 | ACCEPTED | 0.06 s | details |
#16 | WRONG ANSWER | 0.05 s | details |
#17 | WRONG ANSWER | 0.06 s | details |
#18 | WRONG ANSWER | 0.05 s | details |
#19 | WRONG ANSWER | 0.06 s | details |
#20 | ACCEPTED | 0.06 s | details |
#21 | WRONG ANSWER | 0.06 s | details |
#22 | WRONG ANSWER | 0.05 s | details |
#23 | WRONG ANSWER | 0.06 s | details |
#24 | WRONG ANSWER | 0.05 s | details |
#25 | WRONG ANSWER | 0.07 s | details |
#26 | WRONG ANSWER | 0.05 s | details |
#27 | ACCEPTED | 0.06 s | details |
#28 | WRONG ANSWER | 0.06 s | details |
#29 | WRONG ANSWER | 0.06 s | details |
#30 | WRONG ANSWER | 0.68 s | details |
#31 | WRONG ANSWER | 0.06 s | details |
#32 | WRONG ANSWER | 0.06 s | details |
#33 | WRONG ANSWER | 0.10 s | details |
#34 | WRONG ANSWER | 0.74 s | details |
#35 | WRONG ANSWER | 6.86 s | details |
#36 | WRONG ANSWER | 7.86 s | details |
#37 | WRONG ANSWER | 7.88 s | details |
#38 | WRONG ANSWER | 7.93 s | details |
#39 | WRONG ANSWER | 7.94 s | details |
#40 | WRONG ANSWER | 7.87 s | details |
#41 | WRONG ANSWER | 0.06 s | details |
#42 | WRONG ANSWER | 0.05 s | details |
#43 | WRONG ANSWER | 0.11 s | details |
#44 | WRONG ANSWER | 0.06 s | details |
#45 | WRONG ANSWER | 0.06 s | details |
#46 | WRONG ANSWER | 0.08 s | details |
#47 | WRONG ANSWER | 0.14 s | details |
#48 | WRONG ANSWER | 0.64 s | details |
#49 | WRONG ANSWER | 9.35 s | details |
#50 | WRONG ANSWER | 8.51 s | details |
#51 | WRONG ANSWER | 8.80 s | details |
#52 | WRONG ANSWER | 9.26 s | details |
#53 | WRONG ANSWER | 9.37 s | details |
#54 | WRONG ANSWER | 0.05 s | details |
#55 | WRONG ANSWER | 0.05 s | details |
#56 | WRONG ANSWER | 1.58 s | details |
#57 | WRONG ANSWER | 0.07 s | details |
#58 | WRONG ANSWER | 0.07 s | details |
#59 | WRONG ANSWER | 0.43 s | details |
#60 | WRONG ANSWER | 5.85 s | details |
#61 | WRONG ANSWER | 6.58 s | details |
#62 | WRONG ANSWER | 5.93 s | details |
#63 | WRONG ANSWER | 6.17 s | details |
#64 | WRONG ANSWER | 6.59 s | details |
#65 | WRONG ANSWER | 6.84 s | details |
#66 | WRONG ANSWER | 5.85 s | details |
#67 | TIME LIMIT EXCEEDED | -- | details |
#68 | WRONG ANSWER | 4.81 s | details |
#69 | WRONG ANSWER | 0.05 s | details |
#70 | WRONG ANSWER | 1.43 s | details |
#71 | WRONG ANSWER | 0.06 s | details |
#72 | WRONG ANSWER | 0.06 s | details |
Code
#include <bits/stdc++.h> #define i64 long long #define u64 unsigned long long #define i32 int #define u32 unsigned int #define pii pair<int, int> #define pll pair<long long, long long> #define ld long double #define defmod 1000000007 #define mati64(a,b) vector<vector<i64>>(a, vector<i64>(b, 0)); using namespace std; int n, k; vector<int> v[5050]; int pa[5050]; vector<pair<int, int>> al[5050]; int de[5050]; void hae1(int cur){ for(auto f: v[cur]){ if(f == pa[cur]) continue; pa[f] = cur; hae1(f); al[cur].push_back({de[f]+1, f}); de[cur] = max(de[f]+1, de[cur]); } } vector<bool> d1; multiset<int> cc; int gp(int cur, int last){ if(al[cur][0].second == last){ if(al[cur].size() == 1) return -1; return al[cur][1].first; } return al[cur][0].first; } int gp2(int cur, int last, int last2){ if(al[cur][0].second == last || al[cur][0].second == last2){ if(al[cur].size() == 1) return 0; if(al[cur][1].second == last || al[cur][1].second == last2){ if(al[cur].size() == 2) return 0; return al[cur][2].first; } return al[cur][1].first; } return al[cur][0].first; } void adpis(int cur){ for(auto f: v[cur]){ if(f == pa[cur]) continue; al[f].push_back({gp(cur, f)+1, cur}); sort(al[f].begin(), al[f].end(), greater<pair<int, int>>()); adpis(f); } } int ans = 10000, at = 10000, aa, ab; int alk = 0; void hae2(int cur, int last, int d){ //cout << "cur " << cur << " last " << last << " d " << d << endl; if(d > k) return; cc.insert(gp2(cur, last, -1)); int be = 10000; if(cc.size() == 1){ //cout << "be " << *cc.rbegin() << endl; be = *cc.rbegin(); } else{ be = *cc.rbegin(); cc.erase(cc.find(be)); int vv = *cc.rbegin(); cc.insert(be); be+=vv;; } if(be < ans){ ans = be; at = d; aa = alk; ab = cur; //cout << "taalla " << aa << " " << ab << " " << d<< endl; } else if(be == ans && d < at){ ans = be; at = d; aa = alk; ab = cur; //cout << "taalla " << aa << " " << ab << " " << d<< endl; } //cout << alk << "->"<< cur << " mukana " << endl; // for(auto f: cc) // cout << f << " "; //cout << endl << endl; cc.erase(cc.find(gp2(cur, last, -1))); for(auto f: v[cur]){ if(f == last) continue; int lis = gp2(cur, last, f); cc.insert(lis); hae2(f, cur, d+1); cc.erase(cc.find(lis)); } } int main(){ cin.sync_with_stdio(0); cin.tie(0); cin >> n >> k; for(int i = 0; i < n-1; ++i){ int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } hae1(0); for(int i = 0; i < n; ++i){ sort(al[i].begin(), al[i].end(), greater<pair<int, int>>()); } adpis(0); for(int i = 0; i < n; ++i){ d1 = vector<bool>(n, 0); cc.clear(); int be = 0; //cout << i << ": "; // for(auto f: al[i]) // cout << f.first << "," << f.second << " "; //cout << endl; if(al[i].size() == 1) be = al[i][0].first; else if(al[i].size() > 1) be = al[i][0].first+al[i][1].first; if(be < ans){ ans = be; at = 0; aa = i; ab = i; } alk = i; hae2(i, -1, 0); } cout << ans << endl << at << endl << aa << " " << ab << endl; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
8 3 0 2 0 5 2 3 5 1 ... |
correct output |
---|
2 3 2 6 |
user output |
---|
2 3 2 6 |
Test 2
Verdict: WRONG ANSWER
input |
---|
5 2 0 1 0 2 0 3 0 4 |
correct output |
---|
2 0 |
user output |
---|
1 0 0 0 |
Test 3
Verdict: WRONG ANSWER
input |
---|
2 1 0 1 |
correct output |
---|
0 1 0 1 |
user output |
---|
0 0 1 1 |
Test 4
Verdict: WRONG ANSWER
input |
---|
3 1 0 1 2 1 |
correct output |
---|
1 1 0 1 |
user output |
---|
0 1 1 2 |
Test 5
Verdict: WRONG ANSWER
input |
---|
3 1 0 2 1 2 |
correct output |
---|
1 1 0 2 |
user output |
---|
0 1 1 2 |
Test 6
Verdict: WRONG ANSWER
input |
---|
3 2 0 2 1 2 |
correct output |
---|
0 2 0 1 |
user output |
---|
0 1 1 2 |
Test 7
Verdict: WRONG ANSWER
input |
---|
4 1 0 3 0 1 3 2 |
correct output |
---|
2 1 0 3 |
user output |
---|
2 0 0 0 |
Test 8
Verdict: ACCEPTED
input |
---|
4 2 0 3 0 1 3 2 |
correct output |
---|
1 2 0 2 |
user output |
---|
1 2 0 2 |
Test 9
Verdict: ACCEPTED
input |
---|
4 3 0 3 0 1 3 2 |
correct output |
---|
0 3 1 2 |
user output |
---|
0 3 1 2 |
Test 10
Verdict: WRONG ANSWER
input |
---|
4 1 0 1 0 2 0 3 |
correct output |
---|
2 0 |
user output |
---|
1 0 0 0 |
Test 11
Verdict: WRONG ANSWER
input |
---|
4 2 0 1 0 2 0 3 |
correct output |
---|
1 2 1 2 |
user output |
---|
1 0 0 0 |
Test 12
Verdict: WRONG ANSWER
input |
---|
4 3 0 1 0 2 0 3 |
correct output |
---|
1 2 1 2 |
user output |
---|
1 0 0 0 |
Test 13
Verdict: WRONG ANSWER
input |
---|
6 3 0 1 0 2 0 3 2 4 ... |
correct output |
---|
2 2 2 3 |
user output |
---|
2 0 0 0 |
Test 14
Verdict: WRONG ANSWER
input |
---|
6 3 0 1 0 2 0 3 2 4 ... |
correct output |
---|
2 1 0 2 |
user output |
---|
2 0 0 0 |
Test 15
Verdict: ACCEPTED
input |
---|
8 5 0 1 1 2 2 3 0 4 ... |
correct output |
---|
2 4 2 5 |
user output |
---|
2 4 2 5 |
Test 16
Verdict: WRONG ANSWER
input |
---|
2 1 0 1 |
correct output |
---|
0 1 0 1 |
user output |
---|
0 0 1 1 |
Test 17
Verdict: WRONG ANSWER
input |
---|
3 1 2 1 0 2 |
correct output |
---|
1 1 0 2 |
user output |
---|
0 1 1 2 |
Test 18
Verdict: WRONG ANSWER
input |
---|
3 1 0 2 0 1 |
correct output |
---|
1 1 0 2 |
user output |
---|
1 0 0 0 |
Test 19
Verdict: WRONG ANSWER
input |
---|
3 2 1 0 1 2 |
correct output |
---|
0 2 0 2 |
user output |
---|
0 1 1 2 |
Test 20
Verdict: ACCEPTED
input |
---|
3 2 0 1 0 2 |
correct output |
---|
0 2 1 2 |
user output |
---|
0 2 1 2 |
Test 21
Verdict: WRONG ANSWER
input |
---|
4 1 2 1 2 0 1 3 |
correct output |
---|
2 1 0 2 |
user output |
---|
1 0 1 1 |
Test 22
Verdict: WRONG ANSWER
input |
---|
4 1 2 0 0 3 1 0 |
correct output |
---|
2 0 |
user output |
---|
1 0 0 0 |
Test 23
Verdict: WRONG ANSWER
input |
---|
4 2 3 0 1 2 2 3 |
correct output |
---|
1 2 0 2 |
user output |
---|
0 2 1 3 |
Test 24
Verdict: WRONG ANSWER
input |
---|
4 2 1 0 0 3 0 2 |
correct output |
---|
1 2 1 3 |
user output |
---|
1 0 0 0 |
Test 25
Verdict: WRONG ANSWER
input |
---|
4 3 3 0 3 2 2 1 |
correct output |
---|
0 3 0 1 |
user output |
---|
0 2 1 3 |
Test 26
Verdict: WRONG ANSWER
input |
---|
4 3 1 0 3 0 2 0 |
correct output |
---|
1 2 1 3 |
user output |
---|
1 0 0 0 |
Test 27
Verdict: ACCEPTED
input |
---|
10 3 3 0 8 1 9 5 0 4 ... |
correct output |
---|
2 3 0 5 |
user output |
---|
2 3 0 5 |
Test 28
Verdict: WRONG ANSWER
input |
---|
100 4 32 66 29 26 86 0 71 83 ... |
correct output |
---|
12 4 86 89 |
user output |
---|
8 0 62 62 |
Test 29
Verdict: WRONG ANSWER
input |
---|
1000 1 155 994 213 449 582 440 277 0 ... |
correct output |
---|
22 1 1 330 |
user output |
---|
12 0 486 486 |
Test 30
Verdict: WRONG ANSWER
input |
---|
2500 10 517 660 971 230 982 1721 2200 2124 ... |
correct output |
---|
23 4 294 943 |
user output |
---|
13 0 676 676 |
Test 31
Verdict: WRONG ANSWER
input |
---|
5000 1 1611 2785 2978 4796 3783 4548 1074 1256 ... |
correct output |
---|
34 1 0 1611 |
user output |
---|
18 0 2352 2352 |
Test 32
Verdict: WRONG ANSWER
input |
---|
5000 2 3110 2737 2365 2830 2914 874 3720 2637 ... |
correct output |
---|
30 2 844 1623 |
user output |
---|
16 0 3631 3631 |
Test 33
Verdict: WRONG ANSWER
input |
---|
5000 4 664 4317 295 764 4857 1869 1111 1915 ... |
correct output |
---|
33 4 541 2936 |
user output |
---|
19 0 2816 2816 |
Test 34
Verdict: WRONG ANSWER
input |
---|
5000 8 4033 4112 3295 1781 1623 933 2035 1665 ... |
correct output |
---|
30 7 2605 4351 |
user output |
---|
19 0 2219 2219 |
Test 35
Verdict: WRONG ANSWER
input |
---|
5000 20 2304 353 834 2090 1767 72 3026 4211 ... |
correct output |
---|
26 12 1708 3762 |
user output |
---|
18 0 3455 3455 |
Test 36
Verdict: WRONG ANSWER
input |
---|
5000 100 1688 3447 496 2607 1054 2586 4259 2671 ... |
correct output |
---|
29 5 1379 2879 |
user output |
---|
17 0 0 0 |
Test 37
Verdict: WRONG ANSWER
input |
---|
5000 1000 638 3198 3452 4568 2723 2277 1947 4539 ... |
correct output |
---|
28 6 517 4411 |
user output |
---|
16 0 0 0 |
Test 38
Verdict: WRONG ANSWER
input |
---|
5000 2000 1451 4112 1730 1026 1556 1248 4723 678 ... |
correct output |
---|
28 6 82 4161 |
user output |
---|
16 0 12 12 |
Test 39
Verdict: WRONG ANSWER
input |
---|
5000 4000 3618 1301 2744 1363 1705 3118 2385 2886 ... |
correct output |
---|
28 11 1526 2510 |
user output |
---|
20 0 421 421 |
Test 40
Verdict: WRONG ANSWER
input |
---|
5000 4999 1647 992 3574 4278 2808 2380 3945 287 ... |
correct output |
---|
25 10 510 839 |
user output |
---|
17 0 157 157 |
Test 41
Verdict: WRONG ANSWER
input |
---|
100 4 48 94 54 34 25 31 12 16 ... |
correct output |
---|
18 3 13 24 |
user output |
---|
11 0 7 7 |
Test 42
Verdict: WRONG ANSWER
input |
---|
1000 1 649 341 964 65 43 702 226 543 ... |
correct output |
---|
54 1 23 833 |
user output |
---|
28 0 524 524 |
Test 43
Verdict: WRONG ANSWER
input |
---|
2500 10 2238 1206 1470 365 1938 1220 962 2009 ... |
correct output |
---|
51 10 333 1068 |
user output |
---|
30 0 912 912 |
Test 44
Verdict: WRONG ANSWER
input |
---|
5000 1 1600 4821 4466 2988 261 1010 1777 2935 ... |
correct output |
---|
84 1 36 723 |
user output |
---|
43 0 2443 2443 |
Test 45
Verdict: WRONG ANSWER
input |
---|
5000 2 2161 2849 1729 1347 1763 2560 2098 2899 ... |
correct output |
---|
112 2 1 1769 |
user output |
---|
57 0 1481 1481 |
Test 46
Verdict: WRONG ANSWER
input |
---|
5000 4 3961 4831 2920 3199 4703 3118 201 1241 ... |
correct output |
---|
112 4 43 4157 |
user output |
---|
58 0 2442 2442 |
Test 47
Verdict: WRONG ANSWER
input |
---|
5000 8 3226 1183 3536 3297 2501 261 3071 4107 ... |
correct output |
---|
122 8 133 2017 |
user output |
---|
65 0 3786 3786 |
Test 48
Verdict: WRONG ANSWER
input |
---|
5000 20 1221 3603 3259 3147 3676 1561 4574 962 ... |
correct output |
---|
86 20 128 2391 |
user output |
---|
53 0 3333 3333 |
Test 49
Verdict: WRONG ANSWER
input |
---|
5000 100 50 2333 699 2904 4502 392 2177 3778 ... |
correct output |
---|
75 42 1627 3129 |
user output |
---|
58 0 730 730 |
Test 50
Verdict: WRONG ANSWER
input |
---|
5000 1000 1025 4349 3214 4639 4004 2506 652 4796 ... |
correct output |
---|
38 10 2964 4732 |
user output |
---|
23 0 1212 1212 |
Test 51
Verdict: WRONG ANSWER
input |
---|
5000 2000 4108 791 4770 1666 4203 4197 2566 728 ... |
correct output |
---|
48 19 2640 4559 |
user output |
---|
31 0 254 254 |
Test 52
Verdict: WRONG ANSWER
input |
---|
5000 4000 2183 3550 857 549 4752 3563 4198 4895 ... |
correct output |
---|
69 26 3244 4780 |
user output |
---|
45 0 3882 3882 |
Test 53
Verdict: WRONG ANSWER
input |
---|
5000 4999 4282 2328 4163 653 929 3214 3631 4207 ... |
correct output |
---|
79 26 2794 4878 |
user output |
---|
50 0 1911 1911 |
Test 54
Verdict: WRONG ANSWER
input |
---|
100 4 51 84 32 89 92 51 67 4 ... |
correct output |
---|
5 3 14 50 |
user output |
---|
4 0 0 0 |
Test 55
Verdict: WRONG ANSWER
input |
---|
1000 1 942 999 402 534 533 278 228 908 ... |
correct output |
---|
10 1 0 968 |
user output |
---|
6 0 0 0 |
Test 56
Verdict: WRONG ANSWER
input |
---|
2500 10 1639 991 640 223 1940 1067 801 257 ... |
correct output |
---|
12 2 2075 2395 |
user output |
---|
7 0 0 0 |
Test 57
Verdict: WRONG ANSWER
input |
---|
5000 1 1585 3293 3686 3851 1447 1604 392 2681 ... |
correct output |
---|
14 0 |
user output |
---|
7 0 0 0 |
Test 58
Verdict: WRONG ANSWER
input |
---|
5000 2 626 3760 2593 3177 1343 889 1377 596 ... |
correct output |
---|
14 0 |
user output |
---|
7 0 0 0 |
Test 59
Verdict: WRONG ANSWER
input |
---|
5000 4 1462 182 3060 4479 3021 4111 3145 2887 ... |
correct output |
---|
12 2 2219 3145 |
user output |
---|
7 0 0 0 |
Test 60
Verdict: WRONG ANSWER
input |
---|
5000 8 671 2837 3952 4186 828 1632 3885 2545 ... |
correct output |
---|
10 1 0 2405 |
user output |
---|
6 0 0 0 |
Test 61
Verdict: WRONG ANSWER
input |
---|
5000 20 3274 1781 3151 566 1298 1210 495 4010 ... |
correct output |
---|
14 0 |
user output |
---|
7 0 0 0 |
Test 62
Verdict: WRONG ANSWER
input |
---|
5000 100 487 1275 4234 2960 1502 3713 2471 819 ... |
correct output |
---|
10 1 0 4411 |
user output |
---|
6 0 0 0 |
Test 63
Verdict: WRONG ANSWER
input |
---|
5000 1000 2192 4468 4475 4665 81 4277 998 1960 ... |
correct output |
---|
12 1 0 910 |
user output |
---|
7 0 0 0 |
Test 64
Verdict: WRONG ANSWER
input |
---|
5000 2000 686 0 3311 3404 176 2362 119 2765 ... |
correct output |
---|
14 1 0 3007 |
user output |
---|
8 0 0 0 |
Test 65
Verdict: WRONG ANSWER
input |
---|
5000 4000 2848 3939 1514 2396 527 821 2586 4938 ... |
correct output |
---|
16 3 318 3675 |
user output |
---|
10 0 0 0 |
Test 66
Verdict: WRONG ANSWER
input |
---|
5000 4999 2128 1367 1616 1575 4936 3022 339 4210 ... |
correct output |
---|
10 0 |
user output |
---|
5 0 0 0 |
Test 67
Verdict: TIME LIMIT EXCEEDED
input |
---|
5000 4999 2858 558 4677 2444 3042 610 1950 4352 ... |
correct output |
---|
0 4999 0 1971 |
user output |
---|
(empty) |
Test 68
Verdict: WRONG ANSWER
input |
---|
5000 4999 0 3957 0 2864 0 2018 2678 0 ... |
correct output |
---|
2 0 |
user output |
---|
1 0 0 0 |
Test 69
Verdict: WRONG ANSWER
input |
---|
5000 1 2654 1880 2560 3683 4613 596 4860 1233 ... |
correct output |
---|
4998 1 0 1782 |
user output |
---|
2499 0 4100 4100 |
Test 70
Verdict: WRONG ANSWER
input |
---|
5000 1 3762 0 0 2803 0 1387 610 0 ... |
correct output |
---|
2 0 |
user output |
---|
1 0 0 0 |
Test 71
Verdict: WRONG ANSWER
input |
---|
10 4 3 0 8 4 5 7 3 8 ... |
correct output |
---|
3 4 3 5 |
user output |
---|
2 4 7 8 |
Test 72
Verdict: WRONG ANSWER
input |
---|
10 5 1 3 5 9 9 2 6 3 ... |
correct output |
---|
2 5 2 6 |
user output |
---|
2 4 6 9 |