190232025-11-17 20:03:47birozsÜltetéspypy3Accepted 75/75500ms23276 KiB
N = int(input())
T = list(map(int,input().split()))
E = []
for i in range(1,N+1):
    if i not in T:
        E.append(i)
hiba = 0
sor = []
for k in E:
    if T[k-1] not in sor:
        sor.append(k)
        while T[k-1] not in sor:
            sor.append(T[k-1])
            k = T[k-1]
        hiba += 1
    else:
        hiba += 1
for k in range(1,N+1):
    if k not in sor and k not in E and T[k-1] not in sor:
        sor.append(k)
        while T[k-1] not in sor:
            sor.append(T[k-1])
            k = T[k-1]
        hiba += 1
    elif k not in sor and k not in E and T[k-1] in sor:
        hiba += 1
for k in E:
    if k not in sor:
        sor.append(k)
print(N-hiba)

szekrend = [0] * (N+1)
szek = 0
for k in sor:
    szek += 1
    szekrend[k] = szek
for i in range(1,N+1):
    print(szekrend[i],end=" ")       


    
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted39ms19624 KiB
2Accepted344ms23012 KiB
subtask25/5
3Accepted43ms19660 KiB
4Accepted43ms19592 KiB
5Accepted39ms19644 KiB
6Accepted39ms19592 KiB
7Accepted46ms19468 KiB
subtask35/5
8Accepted39ms19672 KiB
9Accepted39ms19496 KiB
10Accepted43ms19668 KiB
11Accepted43ms19640 KiB
12Accepted39ms19588 KiB
subtask45/5
13Accepted39ms19632 KiB
14Accepted45ms19836 KiB
15Accepted41ms19856 KiB
16Accepted43ms19832 KiB
17Accepted46ms19644 KiB
subtask510/10
18Accepted41ms19864 KiB
19Accepted56ms21404 KiB
20Accepted61ms21420 KiB
21Accepted61ms21408 KiB
22Accepted64ms21400 KiB
23Accepted41ms19692 KiB
24Accepted39ms19748 KiB
25Accepted61ms21288 KiB
26Accepted405ms22780 KiB
27Accepted407ms22864 KiB
subtask610/10
28Accepted56ms21360 KiB
29Accepted75ms22208 KiB
30Accepted100ms22316 KiB
31Accepted125ms22336 KiB
32Accepted148ms22248 KiB
33Accepted186ms22428 KiB
34Accepted196ms22368 KiB
35Accepted238ms22504 KiB
36Accepted407ms22760 KiB
37Accepted405ms22756 KiB
subtask740/40
38Accepted57ms21272 KiB
39Accepted82ms22152 KiB
40Accepted114ms22268 KiB
41Accepted144ms23044 KiB
42Accepted174ms22404 KiB
43Accepted231ms22504 KiB
44Accepted273ms22756 KiB
45Accepted344ms22776 KiB
46Accepted411ms23092 KiB
47Accepted500ms23276 KiB
48Accepted490ms23016 KiB
49Accepted499ms23260 KiB
50Accepted497ms23016 KiB
51Accepted500ms23012 KiB
52Accepted490ms23084 KiB
53Accepted488ms23012 KiB
54Accepted495ms22980 KiB
55Accepted497ms23016 KiB
56Accepted490ms23072 KiB
57Accepted497ms23200 KiB