197932025-12-23 14:06:13GergoszaboÜltetéscpp17Wrong answer 0/756ms760 KiB
#include <iostream>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

int main()
{
    ll n; cin >> n;
    vector<ll> v(n+1);
    vector<ll> be(n+1, 0);
    for (ll i = 1; i <= n; i++){
        cin >> v[i];
        be[v[i]] = 1;
    }
    vector<ll> ul(n+1, 0), kesz(n+1, 0);
    ll szek = 1, ans = 0;
    for (ll i = 1; i <= n; i++){
        if (be[i] == 0){
            ll guy = i;
            while (!kesz[guy]){
                ul[szek] = guy;
                kesz[guy] = 1;
                szek++;
                if (!kesz[v[guy]]) ans++;
                guy = v[guy];
            }
        }
    }
    for (ll i = 1; i <= n; i++){
        if (kesz[i] == 0){
            ll guy = i;
            while (!kesz[guy]){
                ul[szek] = guy;
                kesz[guy] = 1;
                szek++;
                if (!kesz[v[guy]]) ans++;
                guy = v[guy];
            }
        }
    }
    ans = 0;
    cout << ans << "\n";
    for (ll i = 1; i <= n; i++){
        cout << ul[i] << " ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer1ms316 KiB
2Wrong answer4ms572 KiB
subtask20/5
3Wrong answer1ms316 KiB
4Wrong answer1ms316 KiB
5Wrong answer1ms316 KiB
6Wrong answer1ms316 KiB
7Wrong answer1ms316 KiB
subtask30/5
8Wrong answer1ms316 KiB
9Wrong answer1ms316 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms316 KiB
12Wrong answer1ms316 KiB
subtask40/5
13Wrong answer1ms316 KiB
14Wrong answer1ms316 KiB
15Wrong answer1ms316 KiB
16Wrong answer1ms316 KiB
17Wrong answer1ms316 KiB
subtask50/10
18Wrong answer1ms332 KiB
19Wrong answer1ms316 KiB
20Wrong answer1ms500 KiB
21Wrong answer1ms316 KiB
22Wrong answer2ms524 KiB
23Wrong answer1ms316 KiB
24Wrong answer1ms316 KiB
25Wrong answer1ms316 KiB
26Wrong answer4ms720 KiB
27Wrong answer4ms644 KiB
subtask60/10
28Wrong answer1ms316 KiB
29Wrong answer2ms316 KiB
30Wrong answer2ms316 KiB
31Wrong answer3ms524 KiB
32Wrong answer3ms480 KiB
33Wrong answer4ms564 KiB
34Wrong answer3ms580 KiB
35Wrong answer4ms564 KiB
36Wrong answer4ms564 KiB
37Wrong answer4ms640 KiB
subtask70/40
38Wrong answer1ms316 KiB
39Wrong answer2ms316 KiB
40Wrong answer2ms444 KiB
41Wrong answer3ms316 KiB
42Wrong answer3ms564 KiB
43Wrong answer3ms564 KiB
44Wrong answer4ms564 KiB
45Wrong answer4ms644 KiB
46Wrong answer4ms760 KiB
47Wrong answer4ms564 KiB
48Wrong answer4ms568 KiB
49Wrong answer4ms564 KiB
50Wrong answer4ms564 KiB
51Wrong answer4ms572 KiB
52Wrong answer4ms564 KiB
53Wrong answer6ms564 KiB
54Wrong answer6ms756 KiB
55Wrong answer6ms748 KiB
56Wrong answer6ms580 KiB
57Wrong answer6ms564 KiB