Task: | Kindergarten |
Sender: | aalto2024e_008 |
Submission time: | 2024-09-30 17:38:46 +0300 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.04 s | details |
#2 | ACCEPTED | 0.04 s | details |
#3 | ACCEPTED | 0.04 s | details |
#4 | ACCEPTED | 0.04 s | details |
#5 | ACCEPTED | 0.04 s | details |
#6 | ACCEPTED | 0.04 s | details |
#7 | ACCEPTED | 0.04 s | details |
#8 | ACCEPTED | 0.04 s | details |
#9 | ACCEPTED | 0.04 s | details |
#10 | ACCEPTED | 0.04 s | details |
#11 | ACCEPTED | 0.04 s | details |
#12 | ACCEPTED | 0.04 s | details |
#13 | ACCEPTED | 0.04 s | details |
#14 | ACCEPTED | 0.04 s | details |
#15 | ACCEPTED | 0.04 s | details |
#16 | ACCEPTED | 0.04 s | details |
#17 | ACCEPTED | 0.04 s | details |
#18 | ACCEPTED | 0.04 s | details |
#19 | ACCEPTED | 0.04 s | details |
#20 | ACCEPTED | 0.04 s | details |
#21 | ACCEPTED | 0.07 s | details |
#22 | ACCEPTED | 0.07 s | details |
#23 | ACCEPTED | 0.07 s | details |
#24 | ACCEPTED | 0.07 s | details |
#25 | ACCEPTED | 0.07 s | details |
#26 | ACCEPTED | 0.07 s | details |
#27 | ACCEPTED | 0.07 s | details |
#28 | ACCEPTED | 0.07 s | details |
#29 | ACCEPTED | 0.07 s | details |
#30 | ACCEPTED | 0.07 s | details |
#31 | ACCEPTED | 0.46 s | details |
#32 | ACCEPTED | 0.42 s | details |
#33 | ACCEPTED | 0.45 s | details |
#34 | ACCEPTED | 0.42 s | details |
#35 | ACCEPTED | 0.42 s | details |
#36 | ACCEPTED | 0.42 s | details |
#37 | ACCEPTED | 0.42 s | details |
#38 | ACCEPTED | 0.43 s | details |
#39 | ACCEPTED | 0.43 s | details |
#40 | ACCEPTED | 0.45 s | details |
#41 | ACCEPTED | 0.42 s | details |
#42 | ACCEPTED | 0.46 s | details |
#43 | ACCEPTED | 0.45 s | details |
#44 | ACCEPTED | 0.46 s | details |
#45 | ACCEPTED | 0.45 s | details |
#46 | ACCEPTED | 0.46 s | details |
#47 | ACCEPTED | 0.46 s | details |
#48 | ACCEPTED | 0.42 s | details |
#49 | ACCEPTED | 0.42 s | details |
#50 | ACCEPTED | 0.42 s | details |
#51 | ACCEPTED | 0.42 s | details |
#52 | ACCEPTED | 0.42 s | details |
#53 | ACCEPTED | 0.43 s | details |
#54 | ACCEPTED | 0.42 s | details |
#55 | ACCEPTED | 0.45 s | details |
#56 | ACCEPTED | 0.43 s | details |
#57 | ACCEPTED | 0.45 s | details |
#58 | ACCEPTED | 0.42 s | details |
#59 | ACCEPTED | 0.42 s | details |
#60 | ACCEPTED | 0.42 s | details |
#61 | ACCEPTED | 0.42 s | details |
#62 | ACCEPTED | 0.42 s | details |
#63 | ACCEPTED | 0.42 s | details |
#64 | ACCEPTED | 0.42 s | details |
#65 | ACCEPTED | 0.42 s | details |
#66 | ACCEPTED | 0.45 s | details |
#67 | ACCEPTED | 0.42 s | details |
#68 | ACCEPTED | 0.43 s | details |
#69 | ACCEPTED | 0.45 s | details |
#70 | ACCEPTED | 0.42 s | details |
#71 | ACCEPTED | 0.45 s | details |
#72 | ACCEPTED | 0.46 s | details |
#73 | ACCEPTED | 0.42 s | details |
#74 | ACCEPTED | 0.42 s | details |
#75 | ACCEPTED | 0.45 s | details |
#76 | ACCEPTED | 0.42 s | details |
#77 | ACCEPTED | 0.45 s | details |
#78 | ACCEPTED | 0.42 s | details |
#79 | ACCEPTED | 0.42 s | details |
#80 | ACCEPTED | 0.45 s | details |
#81 | ACCEPTED | 0.42 s | details |
#82 | ACCEPTED | 0.42 s | details |
#83 | ACCEPTED | 0.42 s | details |
#84 | ACCEPTED | 0.42 s | details |
#85 | ACCEPTED | 0.42 s | details |
#86 | ACCEPTED | 0.42 s | details |
#87 | ACCEPTED | 0.42 s | details |
#88 | ACCEPTED | 0.45 s | details |
#89 | ACCEPTED | 0.42 s | details |
#90 | ACCEPTED | 0.42 s | details |
Code
# Python3 program for the above approach # Function to check whether there # exists a Hamiltonian Path or not def Hamiltonian_path(adj, N): dp = [[-1 for i in range(1 << N)] for j in range(N)] for i in range(N): dp[i][1 << i] = 0 for i in range(1 << N): for j in range(N): if (i & (1 << j)) != 0: for k in range(N): if (i & (1 << j)) != 0 and j != k and dp[k][i ^ (1 << j)] != -1: # print('hehe') # print(dp[k][i ^ (1 << j)]) if dp[j][i] == -1: dp[j][i] = dp[k][i ^ (1 << j)] + adj[k][j] dp[j][i] = min(dp[k][i ^ (1 << j)] + adj[k][j], dp[j][i]) res = 10000000000000000000000000000000 for i in range(N): res = min(res, dp[i][(1 << N) - 1]) return res n = int(input()) adj = [] for i in range(n): a = list(map(int, input().split())) adj.append(a) N = len(adj) print(Hamiltonian_path(adj, N))
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 6 |
correct output |
---|
0 |
user output |
---|
0 |
Test 2
Verdict: ACCEPTED
input |
---|
1 4 |
correct output |
---|
0 |
user output |
---|
0 |
Test 3
Verdict: ACCEPTED
input |
---|
2 4 0 0 10 |
correct output |
---|
0 |
user output |
---|
0 |
Test 4
Verdict: ACCEPTED
input |
---|
2 6 7 7 9 |
correct output |
---|
7 |
user output |
---|
7 |
Test 5
Verdict: ACCEPTED
input |
---|
3 10 1 7 1 10 6 7 6 7 |
correct output |
---|
7 |
user output |
---|
7 |
Test 6
Verdict: ACCEPTED
input |
---|
3 2 9 10 9 2 10 10 10 5 |
correct output |
---|
19 |
user output |
---|
19 |
Test 7
Verdict: ACCEPTED
input |
---|
3 9 2 0 2 9 4 0 4 1 |
correct output |
---|
2 |
user output |
---|
2 |
Test 8
Verdict: ACCEPTED
input |
---|
4 0 4 10 5 4 10 3 0 10 3 5 0 5 0 0 4 |
correct output |
---|
4 |
user output |
---|
4 |
Test 9
Verdict: ACCEPTED
input |
---|
4 9 9 2 4 9 4 4 8 2 4 0 4 4 8 4 4 |
correct output |
---|
10 |
user output |
---|
10 |
Test 10
Verdict: ACCEPTED
input |
---|
4 0 5 1 4 5 0 0 1 1 0 2 2 4 1 2 1 |
correct output |
---|
2 |
user output |
---|
2 |
Test 11
Verdict: ACCEPTED
input |
---|
5 7 4 3 7 1 4 1 6 6 1 3 6 10 0 5 7 6 0 4 2 ... |
correct output |
---|
5 |
user output |
---|
5 |
Test 12
Verdict: ACCEPTED
input |
---|
5 3 6 1 10 0 6 10 2 0 9 1 2 9 9 4 10 0 9 5 6 ... |
correct output |
---|
3 |
user output |
---|
3 |
Test 13
Verdict: ACCEPTED
input |
---|
5 9 3 8 3 1 3 10 3 6 0 8 3 1 8 3 3 6 8 6 3 ... |
correct output |
---|
7 |
user output |
---|
7 |
Test 14
Verdict: ACCEPTED
input |
---|
5 2 10 2 9 10 10 2 6 7 2 2 6 0 0 4 9 7 0 5 10 ... |
correct output |
---|
11 |
user output |
---|
11 |
Test 15
Verdict: ACCEPTED
input |
---|
5 0 4 10 4 0 4 6 8 2 8 10 8 4 8 7 4 2 8 4 9 ... |
correct output |
---|
13 |
user output |
---|
13 |
Test 16
Verdict: ACCEPTED
input |
---|
5 5 2 1 3 8 2 3 5 7 8 1 5 6 9 0 3 7 9 7 2 ... |
correct output |
---|
5 |
user output |
---|
5 |
Test 17
Verdict: ACCEPTED
input |
---|
5 8 9 3 4 10 9 1 10 6 8 3 10 2 8 9 4 6 8 0 0 ... |
correct output |
---|
15 |
user output |
---|
15 |
Test 18
Verdict: ACCEPTED
input |
---|
5 10 8 7 6 8 8 6 0 3 6 7 0 1 1 6 6 3 1 8 6 ... |
correct output |
---|
13 |
user output |
---|
13 |
Test 19
Verdict: ACCEPTED
input |
---|
5 4 9 6 1 3 9 7 5 2 8 6 5 2 9 4 1 2 9 0 7 ... |
correct output |
---|
10 |
user output |
---|
10 |
Test 20
Verdict: ACCEPTED
input |
---|
5 6 4 5 7 8 4 1 4 6 5 5 4 5 2 10 7 6 2 10 2 ... |
correct output |
---|
12 |
user output |
---|
12 |
Test 21
Verdict: ACCEPTED
input |
---|
10 549 646 792 87 979 640 264 618... |
correct output |
---|
1257 |
user output |
---|
1257 |
Test 22
Verdict: ACCEPTED
input |
---|
10 417 92 419 671 801 895 98 315 ... |
correct output |
---|
1093 |
user output |
---|
1093 |
Test 23
Verdict: ACCEPTED
input |
---|
10 436 330 621 786 505 597 468 38... |
correct output |
---|
1912 |
user output |
---|
1912 |
Test 24
Verdict: ACCEPTED
input |
---|
10 551 897 29 591 283 781 976 92 ... |
correct output |
---|
1530 |
user output |
---|
1530 |
Test 25
Verdict: ACCEPTED
input |
---|
10 967 216 780 597 436 75 528 545... |
correct output |
---|
1166 |
user output |
---|
1166 |
Test 26
Verdict: ACCEPTED
input |
---|
10 222 612 80 274 600 144 24 578 ... |
correct output |
---|
1310 |
user output |
---|
1310 |
Test 27
Verdict: ACCEPTED
input |
---|
10 893 595 438 991 54 541 717 718... |
correct output |
---|
1942 |
user output |
---|
1942 |
Test 28
Verdict: ACCEPTED
input |
---|
10 76 539 679 910 601 133 205 838... |
correct output |
---|
2202 |
user output |
---|
2202 |
Test 29
Verdict: ACCEPTED
input |
---|
10 874 11 555 426 65 224 28 320 6... |
correct output |
---|
987 |
user output |
---|
987 |
Test 30
Verdict: ACCEPTED
input |
---|
10 10 218 166 573 386 804 650 874... |
correct output |
---|
1545 |
user output |
---|
1545 |
Test 31
Verdict: ACCEPTED
input |
---|
16 78876117 17293464 73807511 451... |
correct output |
---|
141535044 |
user output |
---|
141535044 |
Test 32
Verdict: ACCEPTED
input |
---|
16 18434581 96310208 2094677 8835... |
correct output |
---|
217719706 |
user output |
---|
217719706 |
Test 33
Verdict: ACCEPTED
input |
---|
16 15764865 97858716 92778181 718... |
correct output |
---|
167604914 |
user output |
---|
167604914 |
Test 34
Verdict: ACCEPTED
input |
---|
16 79528724 65612103 26207475 638... |
correct output |
---|
140515513 |
user output |
---|
140515513 |
Test 35
Verdict: ACCEPTED
input |
---|
16 52556424 55139192 95364389 546... |
correct output |
---|
140013397 |
user output |
---|
140013397 |
Test 36
Verdict: ACCEPTED
input |
---|
16 86801053 11426789 72187831 966... |
correct output |
---|
93732738 |
user output |
---|
93732738 |
Test 37
Verdict: ACCEPTED
input |
---|
16 22833997 7191499 71236196 3216... |
correct output |
---|
115026040 |
user output |
---|
115026040 |
Test 38
Verdict: ACCEPTED
input |
---|
16 30132775 3994617 56422716 4279... |
correct output |
---|
122521730 |
user output |
---|
122521730 |
Test 39
Verdict: ACCEPTED
input |
---|
16 66508002 86884113 88110850 970... |
correct output |
---|
206680250 |
user output |
---|
206680250 |
Test 40
Verdict: ACCEPTED
input |
---|
16 9973896 65003382 54473078 6575... |
correct output |
---|
105290977 |
user output |
---|
105290977 |
Test 41
Verdict: ACCEPTED
input |
---|
16 60142917 67282857 11933232 463... |
correct output |
---|
149892373 |
user output |
---|
149892373 |
Test 42
Verdict: ACCEPTED
input |
---|
16 4982660 31508124 77610451 9338... |
correct output |
---|
208191625 |
user output |
---|
208191625 |
Test 43
Verdict: ACCEPTED
input |
---|
16 21317409 22538814 78950075 437... |
correct output |
---|
141684927 |
user output |
---|
141684927 |
Test 44
Verdict: ACCEPTED
input |
---|
16 52899464 63202728 6654687 1447... |
correct output |
---|
162046504 |
user output |
---|
162046504 |
Test 45
Verdict: ACCEPTED
input |
---|
16 98172450 57262621 54713540 967... |
correct output |
---|
151356452 |
user output |
---|
151356452 |
Test 46
Verdict: ACCEPTED
input |
---|
16 88979873 56880637 33342355 868... |
correct output |
---|
159671124 |
user output |
---|
159671124 |
Test 47
Verdict: ACCEPTED
input |
---|
16 31489774 75583422 98416671 495... |
correct output |
---|
177673400 |
user output |
---|
177673400 |
Test 48
Verdict: ACCEPTED
input |
---|
16 43534750 41244279 21038793 242... |
correct output |
---|
174069522 |
user output |
---|
174069522 |
Test 49
Verdict: ACCEPTED
input |
---|
16 74549766 97697405 65731362 223... |
correct output |
---|
164091596 |
user output |
---|
164091596 |
Test 50
Verdict: ACCEPTED
input |
---|
16 88329068 78556994 29213132 737... |
correct output |
---|
150948961 |
user output |
---|
150948961 |
Test 51
Verdict: ACCEPTED
input |
---|
16 11868309 52454190 2188140 3426... |
correct output |
---|
145704982 |
user output |
---|
145704982 |
Test 52
Verdict: ACCEPTED
input |
---|
16 62601211 24407904 38967625 742... |
correct output |
---|
165774974 |
user output |
---|
165774974 |
Test 53
Verdict: ACCEPTED
input |
---|
16 38353763 90537037 98227382 885... |
correct output |
---|
128735723 |
user output |
---|
128735723 |
Test 54
Verdict: ACCEPTED
input |
---|
16 87124995 71164598 85140576 178... |
correct output |
---|
88146905 |
user output |
---|
88146905 |
Test 55
Verdict: ACCEPTED
input |
---|
16 15506055 73736552 44372116 853... |
correct output |
---|
139764802 |
user output |
---|
139764802 |
Test 56
Verdict: ACCEPTED
input |
---|
16 20052620 55628826 15868440 899... |
correct output |
---|
112678656 |
user output |
---|
112678656 |
Test 57
Verdict: ACCEPTED
input |
---|
16 38365166 78120078 30444983 287... |
correct output |
---|
180080436 |
user output |
---|
180080436 |
Test 58
Verdict: ACCEPTED
input |
---|
16 46161809 99247781 74790752 906... |
correct output |
---|
192231810 |
user output |
---|
192231810 |
Test 59
Verdict: ACCEPTED
input |
---|
16 96396611 61707575 39771927 957... |
correct output |
---|
157075200 |
user output |
---|
157075200 |
Test 60
Verdict: ACCEPTED
input |
---|
16 86701456 19718778 48320555 202... |
correct output |
---|
171350081 |
user output |
---|
171350081 |
Test 61
Verdict: ACCEPTED
input |
---|
16 10218362 40742172 91128924 285... |
correct output |
---|
127429234 |
user output |
---|
127429234 |
Test 62
Verdict: ACCEPTED
input |
---|
16 79903579 1974104 24354885 4902... |
correct output |
---|
119531862 |
user output |
---|
119531862 |
Test 63
Verdict: ACCEPTED
input |
---|
16 23816783 24638719 49178170 814... |
correct output |
---|
161233528 |
user output |
---|
161233528 |
Test 64
Verdict: ACCEPTED
input |
---|
16 22336543 34284046 7826114 4407... |
correct output |
---|
172344121 |
user output |
---|
172344121 |
Test 65
Verdict: ACCEPTED
input |
---|
16 4933488 53040995 75121239 3334... |
correct output |
---|
150345908 |
user output |
---|
150345908 |
Test 66
Verdict: ACCEPTED
input |
---|
16 15740195 82161403 83343605 558... |
correct output |
---|
177299100 |
user output |
---|
177299100 |
Test 67
Verdict: ACCEPTED
input |
---|
16 3639374 43311419 10627086 4629... |
correct output |
---|
181883199 |
user output |
---|
181883199 |
Test 68
Verdict: ACCEPTED
input |
---|
16 10600561 29567300 26714920 537... |
correct output |
---|
153201253 |
user output |
---|
153201253 |
Test 69
Verdict: ACCEPTED
input |
---|
16 34181158 4262559 25064528 1281... |
correct output |
---|
110754397 |
user output |
---|
110754397 |
Test 70
Verdict: ACCEPTED
input |
---|
16 1379850 55703817 5455026 69880... |
correct output |
---|
150243591 |
user output |
---|
150243591 |
Test 71
Verdict: ACCEPTED
input |
---|
16 69328497 20779089 35701876 660... |
correct output |
---|
163180293 |
user output |
---|
163180293 |
Test 72
Verdict: ACCEPTED
input |
---|
16 11384815 61579628 8695610 1495... |
correct output |
---|
161906149 |
user output |
---|
161906149 |
Test 73
Verdict: ACCEPTED
input |
---|
16 16054161 19304150 57152778 337... |
correct output |
---|
159099477 |
user output |
---|
159099477 |
Test 74
Verdict: ACCEPTED
input |
---|
16 71221723 14311522 45021194 426... |
correct output |
---|
216877591 |
user output |
---|
216877591 |
Test 75
Verdict: ACCEPTED
input |
---|
16 10846316 79755467 74445718 590... |
correct output |
---|
135548636 |
user output |
---|
135548636 |
Test 76
Verdict: ACCEPTED
input |
---|
16 51818372 6753746 10792121 3914... |
correct output |
---|
164259241 |
user output |
---|
164259241 |
Test 77
Verdict: ACCEPTED
input |
---|
16 10755019 44179719 41876247 694... |
correct output |
---|
133696572 |
user output |
---|
133696572 |
Test 78
Verdict: ACCEPTED
input |
---|
16 53567785 71579417 82569781 317... |
correct output |
---|
150763443 |
user output |
---|
150763443 |
Test 79
Verdict: ACCEPTED
input |
---|
16 88623279 34185830 73137414 387... |
correct output |
---|
198014364 |
user output |
---|
198014364 |
Test 80
Verdict: ACCEPTED
input |
---|
16 58343206 9110482 88825117 5032... |
correct output |
---|
131581281 |
user output |
---|
131581281 |
Test 81
Verdict: ACCEPTED
input |
---|
16 36829570 59249556 69795996 491... |
correct output |
---|
149993947 |
user output |
---|
149993947 |
Test 82
Verdict: ACCEPTED
input |
---|
16 55892938 61714751 75014144 212... |
correct output |
---|
171851792 |
user output |
---|
171851792 |
Test 83
Verdict: ACCEPTED
input |
---|
16 53792259 75175740 86691312 687... |
correct output |
---|
261201544 |
user output |
---|
261201544 |
Test 84
Verdict: ACCEPTED
input |
---|
16 83382234 98447679 33400623 580... |
correct output |
---|
174166475 |
user output |
---|
174166475 |
Test 85
Verdict: ACCEPTED
input |
---|
16 49232089 54075676 50668211 720... |
correct output |
---|
138328462 |
user output |
---|
138328462 |
Test 86
Verdict: ACCEPTED
input |
---|
16 29877190 8099586 92371257 8541... |
correct output |
---|
103011096 |
user output |
---|
103011096 |
Test 87
Verdict: ACCEPTED
input |
---|
16 91519337 33138162 11320405 226... |
correct output |
---|
148911385 |
user output |
---|
148911385 |
Test 88
Verdict: ACCEPTED
input |
---|
16 13035374 24654480 36933166 555... |
correct output |
---|
141610494 |
user output |
---|
141610494 |
Test 89
Verdict: ACCEPTED
input |
---|
16 43339370 14613386 9518839 2982... |
correct output |
---|
126679049 |
user output |
---|
126679049 |
Test 90
Verdict: ACCEPTED
input |
---|
16 9921885 71587757 22396864 1673... |
correct output |
---|
139350643 |
user output |
---|
139350643 |