Submission details
Task:Zig Zag
Sender:aalto26jw_003
Submission time:2026-11-11 17:20:37 +0200
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#20.04 sdetails
#30.04 sdetails
#40.04 sdetails
#5ACCEPTED0.04 sdetails
#6ACCEPTED0.04 sdetails
#70.04 sdetails
#8ACCEPTED0.04 sdetails
#90.04 sdetails
#10ACCEPTED0.04 sdetails
#110.04 sdetails
#12ACCEPTED0.04 sdetails
#130.04 sdetails
#140.04 sdetails
#150.04 sdetails
#160.04 sdetails
#170.04 sdetails
#180.04 sdetails
#190.04 sdetails
#200.04 sdetails
#210.04 sdetails
#22ACCEPTED0.04 sdetails
#230.04 sdetails
#240.04 sdetails
#250.04 sdetails
#260.04 sdetails
#270.04 sdetails
#280.04 sdetails
#290.04 sdetails
#300.04 sdetails
#310.04 sdetails
#320.04 sdetails
#330.04 sdetails
#340.04 sdetails
#350.04 sdetails
#360.04 sdetails
#370.04 sdetails
#380.04 sdetails
#390.06 sdetails
#400.06 sdetails
#410.06 sdetails
#420.06 sdetails
#430.06 sdetails
#440.06 sdetails
#450.06 sdetails
#460.06 sdetails
#470.06 sdetails
#480.06 sdetails
#490.06 sdetails
#500.06 sdetails
#510.06 sdetails
#520.06 sdetails
#530.06 sdetails
#540.06 sdetails
#550.06 sdetails
#560.06 sdetails
#570.06 sdetails
#580.06 sdetails
#590.09 sdetails
#600.08 sdetails
#610.09 sdetails
#620.09 sdetails
#630.09 sdetails
#640.13 sdetails
#650.13 sdetails
#660.13 sdetails
#670.13 sdetails
#680.13 sdetails

Code




from collections import deque

def main():

    n = int(input())
    p = []
    for i in range(n):
        p.append(tuple(map(int, input().split())))



    def dist2(i,j):
        a,b = p[i]
        c,d = p[j]
        return (a-c)**2 + (b-d)**2

    
    out = [0]
    # rem_cand = 1
    rem = set(range(1,n))

    for i in range(1,n):
        best = None
        min_dist = None
        for r in rem:
            dist = dist2(out[-1], r)
            if min_dist is None or dist < min_dist:
                best = r
                min_dist = dist
        
        out.append(best)
        rem.remove(best)
            
        # new_cand = i

        # if dist2(out[-1], rem_cand) > dist2(out[-1], new_cand):
        #     out.append(rem_cand)
        #     rem_cand = new_cand
        # else:
        #     out.append(new_cand)
    
    # out.append(rem_cand)


    out = [o+1 for o in out]
    print(*out)



main()

Test details

Test 1

Verdict: ACCEPTED

input
2
2 5
8 9

correct output
1 2 

user output
1 2

Test 2

Verdict:

input
3
3 9
8 7
9 9

correct output
1 3 2 

user output
1 2 3

Test 3

Verdict:

input
3
6 10
8 7
9 4

correct output
1 3 2 

user output
1 2 3

Test 4

Verdict:

input
3
1 2
2 6
9 9

correct output
1 3 2 

user output
1 2 3

Test 5

Verdict: ACCEPTED

input
3
3 4
6 1
6 4

correct output
1 2 3 

user output
1 3 2

Test 6

Verdict: ACCEPTED

input
3
2 9
3 2
6 9

correct output
1 2 3 

user output
1 3 2

Test 7

Verdict:

input
4
2 10
6 5
7 1
9 3

correct output
1 3 2 4 

user output
1 2 4 3

Test 8

Verdict: ACCEPTED

input
4
1 5
2 3
3 8
8 5

correct output
1 4 2 3 

user output
1 2 3 4

Test 9

Verdict:

input
4
2 7
5 4
7 3
10 1

correct output
1 4 2 3 

user output
1 2 3 4

Test 10

Verdict: ACCEPTED

input
4
1 5
4 3
4 8
10 3

correct output
1 4 3 2 

user output
1 2 3 4

Test 11

Verdict:

input
4
1 9
4 7
4 8
5 5

correct output
1 4 3 2 

user output
1 3 2 4

Test 12

Verdict: ACCEPTED

input
4
1 6
3 2
4 9
9 4

correct output
1 4 3 2 

user output
1 3 2 4

Test 13

Verdict:

input
4
3 1
5 10
6 3
9 8

correct output
1 2 3 4 

user output
1 3 4 2

Test 14

Verdict:

input
4
1 7
6 6
8 6
9 3

correct output
1 4 2 3 

user output
1 2 3 4

Test 15

Verdict:

input
4
4 10
6 1
7 4
9 3

correct output
1 2 4 3 

user output
1 3 4 2

Test 16

Verdict:

input
4
1 9
6 4
7 3
8 3

correct output
1 4 2 3 

user output
1 2 3 4

Test 17

Verdict:

input
4
1 2
6 10
7 3
10 5

correct output
1 4 2 3 

user output
1 3 4 2

Test 18

Verdict:

input
4
4 7
9 5
9 9
10 5

correct output
1 4 3 2 

user output
1 2 4 3

Test 19

Verdict:

input
5
5 7
6 6
6 9
7 9
...

correct output
1 5 2 4 3 

user output
1 2 3 4 5

Test 20

Verdict:

input
5
1 2
2 3
4 10
5 10
...

correct output
1 5 2 4 3 

user output
1 2 3 4 5

Test 21

Verdict:

input
5
1 10
5 2
5 4
5 5
...

correct output
1 2 5 3 4 

user output
1 5 4 3 2

Test 22

Verdict: ACCEPTED

input
5
3 2
6 1
6 6
8 9
...

correct output
1 4 2 3 5 

user output
1 2 3 5 4

Test 23

Verdict:

input
5
6 2
7 6
8 7
10 9
...

correct output
1 5 2 4 3 

user output
1 2 3 4 5

Test 24

Verdict:

input
5
3 1
3 4
5 1
9 9
...

correct output
1 5 3 4 2 

user output
1 3 2 4 5

Test 25

Verdict:

input
5
1 4
2 10
4 3
9 1
...

correct output
1 5 4 2 3 

user output
1 3 4 5 2

Test 26

Verdict:

input
5
1 3
5 10
8 4
8 5
...

correct output
1 5 2 3 4 

user output
1 3 4 5 2

Test 27

Verdict:

input
5
3 5
6 9
9 1
9 4
...

correct output
1 5 2 3 4 

user output
1 2 4 5 3

Test 28

Verdict:

input
5
1 4
2 1
2 4
5 1
...

correct output
1 5 2 3 4 

user output
1 3 2 4 5

Test 29

Verdict:

input
10
4 5
5 3
5 7
6 6
...

correct output
1 9 5 10 7 2 8 6 3 4 

user output
1 2 6 4 3 5 7 8 10 9

Test 30

Verdict:

input
10
1 2
1 4
2 3
2 4
...

correct output
1 10 2 8 3 6 4 9 7 5 

user output
1 3 4 2 7 5 9 8 6 10

Test 31

Verdict:

input
10
1 10
3 5
3 7
4 2
...

correct output
1 9 8 4 10 5 3 6 2 7 

user output
1 3 2 7 6 5 4 9 10 8

Test 32

Verdict:

input
10
1 1
2 1
3 2
3 3
...

correct output
1 8 2 10 3 9 5 6 7 4 

user output
1 2 3 4 6 9 10 7 5 8

Test 33

Verdict:

input
10
1 7
3 2
3 10
5 7
...

correct output
1 8 3 5 10 2 9 4 7 6 

user output
1 3 4 6 7 9 10 8 5 2

Test 34

Verdict:

input
10
2 9
3 1
3 4
3 10
...

correct output
1 5 10 2 9 3 4 8 6 7 

user output
1 4 6 7 8 5 2 3 9 10

Test 35

Verdict:

input
10
1 4
2 10
4 3
4 5
...

correct output
1 10 6 2 9 8 3 7 4 5 

user output
1 3 4 5 7 8 10 2 6 9

Test 36

Verdict:

input
10
1 3
1 5
3 1
5 6
...

correct output
1 10 2 8 5 3 9 6 4 7 

user output
1 2 4 7 6 3 8 9 10 5

Test 37

Verdict:

input
10
1 7
3 5
5 5
5 8
...

correct output
1 8 5 10 2 9 7 6 4 3 

user output
1 2 3 4 7 5 9 10 8 6

Test 38

Verdict:

input
10
1 4
2 1
2 4
3 2
...

correct output
1 10 5 7 3 9 2 6 4 8 

user output
1 3 4 2 7 8 6 9 10 5

Test 39

Verdict:

input
100
5041736 157240647
20175393 348043754
21461600 42077569
21590319 177103472
...

correct output
1 95 3 98 4 99 10 81 29 7 96 8...

user output
1 4 6 2 13 17 19 23 25 21 26 3...

Test 40

Verdict:

input
100
122816 137572579
3081988 829722338
16987929 288837678
20795114 89789519
...

correct output
1 94 4 90 14 97 21 96 3 99 8 9...

user output
1 4 14 21 26 25 31 34 35 47 57...

Test 41

Verdict:

input
100
13977261 381987546
27435119 390118206
27838076 590195590
29208319 801689376
...

correct output
1 100 9 94 14 77 12 99 2 97 7 ...

user output
1 2 8 11 10 13 20 21 25 26 28 ...

Test 42

Verdict:

input
100
24822301 241650433
25750352 822299809
32079340 156090008
55262494 100450154
...

correct output
1 100 4 99 3 87 11 77 12 64 20...

user output
1 8 10 17 15 19 21 26 23 25 20...

Test 43

Verdict:

input
100
5539596 212262730
9648746 657694080
20427661 42713839
23212898 52113136
...

correct output
1 94 3 91 4 88 7 81 14 75 28 6...

user output
1 6 20 23 27 29 32 31 28 14 7 ...

Test 44

Verdict:

input
100
1763267 741881723
6157975 278203924
21895078 521944783
24624220 604717980
...

correct output
1 100 16 97 24 77 23 94 15 70 ...

user output
1 9 11 4 3 5 13 20 25 19 15 22...

Test 45

Verdict:

input
100
39308105 838098679
44426603 836947476
51198751 708680148
63176060 437557708
...

correct output
1 99 2 96 5 100 3 97 11 71 25 ...

user output
1 2 5 9 14 12 24 22 31 37 39 4...

Test 46

Verdict:

input
100
26735342 806125341
42569672 497138595
70798611 724056782
77364316 450297483
...

correct output
1 97 6 100 3 98 10 94 25 78 41...

user output
1 6 3 10 18 27 25 34 41 39 47 ...

Test 47

Verdict:

input
100
8921056 150015577
14394691 72903212
22850648 457512559
27825976 466880371
...

correct output
1 81 5 99 2 83 11 54 96 12 88 ...

user output
1 2 5 11 16 22 32 29 27 26 21 ...

Test 48

Verdict:

input
100
4900393 476861950
8745675 461759249
11139168 391337048
37347058 286446807
...

correct output
1 97 6 87 24 84 17 93 25 94 5 ...

user output
1 2 3 10 13 11 14 12 23 30 26 ...

Test 49

Verdict:

input
200
5041736 157240647
12577900 821317682
20175393 348043754
21461600 42077569
...

correct output
1 186 4 183 15 195 5 196 20 19...

user output
1 5 12 23 24 26 38 40 52 53 54...

Test 50

Verdict:

input
200
122816 137572579
3081988 829722338
8592846 688876470
16987929 288837678
...

correct output
1 186 6 200 9 182 31 177 29 19...

user output
1 9 6 19 25 32 38 22 15 4 24 7...

Test 51

Verdict:

input
200
5007418 457386905
9071363 177024747
11005899 132698
13977261 381987546
...

correct output
1 197 3 180 5 195 6 199 19 166...

user output
1 8 4 15 21 30 34 37 38 42 51 ...

Test 52

Verdict:

input
200
24822301 241650433
25750352 822299809
27410345 98925543
32079340 156090008
...

correct output
1 198 5 187 3 197 6 170 19 151...

user output
1 7 13 18 20 34 36 47 51 57 54...

Test 53

Verdict:

input
200
4210032 63222017
5539596 212262730
9648746 657694080
17149028 626575097
...

correct output
1 191 6 186 7 181 13 159 11 16...

user output
1 7 6 13 16 11 5 9 2 15 24 25 ...

Test 54

Verdict:

input
200
1763267 741881723
6157975 278203924
13795513 320861635
21895078 521944783
...

correct output
1 200 28 182 41 187 40 192 18 ...

user output
1 14 16 35 37 34 50 61 65 63 8...

Test 55

Verdict:

input
200
8476925 141485410
8505126 166581265
12461681 74039645
15361440 452562087
...

correct output
1 192 3 196 18 186 2 177 28 18...

user output
1 2 13 19 24 26 17 14 10 11 5 ...

Test 56

Verdict:

input
200
1991410 698069978
7670036 191583196
8822402 685559485
11360091 77004696
...

correct output
1 198 6 192 14 199 7 200 3 194...

user output
1 3 5 16 17 18 21 23 26 25 36 ...

Test 57

Verdict:

input
200
4472345 555680129
7737822 978991670
8921056 150015577
14394691 72903212
...

correct output
1 191 2 188 24 177 22 200 8 18...

user output
1 10 12 20 23 25 27 31 42 45 6...

Test 58

Verdict:

input
200
366794 310416436
4900393 476861950
8745675 461759249
11139168 391337048
...

correct output
1 197 13 193 7 187 39 172 32 1...

user output
1 8 11 12 26 25 33 40 50 61 76...

Test 59

Verdict:

input
1000
4982121 854709206
5051980 969850608
6610770 110841534
7756396 54539209
...

correct output
1 933 2 989 10 938 11 977 45 9...

user output
1 6 26 8 40 51 61 62 75 89 84 ...

Test 60

Verdict:

input
1000
692639 597387122
870901 527592476
3407540 258414659
3706190 578214810
...

correct output
1 987 30 901 17 997 81 942 82 ...

user output
1 10 4 15 25 39 47 60 54 53 24...

Test 61

Verdict:

input
1000
52022 846049438
151015 375423447
798369 995844330
1351954 659601047
...

correct output
1 997 3 944 28 957 6 998 23 90...

user output
1 14 13 51 79 95 74 62 48 41 3...

Test 62

Verdict:

input
1000
1296052 600889338
1645696 768715355
2692564 473274745
3499475 38421523
...

correct output
1 991 59 989 9 958 13 954 80 9...

user output
1 16 42 61 54 51 53 43 26 19 6...

Test 63

Verdict:

input
1000
1126577 499684443
1256131 518722321
5616399 179078305
7506590 750644416
...

correct output
1 993 32 934 82 982 65 913 29 ...

user output
1 2 20 23 42 64 49 67 90 88 92...

Test 64

Verdict:

input
2000
40804 71218080
59095 459895029
423473 9299604
685308 815211163
...

correct output
1 1989 3 1970 60 1943 34 1941 ...

user output
1 22 51 11 20 34 48 61 60 118 ...

Test 65

Verdict:

input
2000
1408858 277110806
2161135 364884754
2812466 979975883
4200717 277590999
...

correct output
1 1975 45 1898 108 1892 134 19...

user output
1 4 66 71 73 65 26 12 24 58 15...

Test 66

Verdict:

input
2000
1709459 406796814
1857492 878587442
2005566 168482214
3426573 973328677
...

correct output
1 2000 31 1928 12 1994 41 1940...

user output
1 32 28 8 73 87 118 137 170 17...

Test 67

Verdict:

input
2000
554335 614887580
2154289 832986059
2227123 110013552
2614185 311227898
...

correct output
1 1977 10 1981 33 1908 34 1978...

user output
1 6 26 51 68 88 106 114 75 72 ...

Test 68

Verdict:

input
2000
890991 100455230
1036021 428733862
1938719 436899661
2001873 863975225
...

correct output
1 1998 24 1999 48 1994 53 1950...

user output
1 49 45 70 75 74 47 57 85 120 ...