結果

問題 No.3650 Teleportation Cycles
コンテスト
ユーザー zjsdut
提出日時 2026-09-01 21:00:58
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 14 ms / 2,000 ms
+ 279µs
コード長 772 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,828 ms
コンパイル使用メモリ 335,648 KB
実行使用メモリ 9,780 KB
最終ジャッジ日時 2026-09-01 21:01:14
合計ジャッジ時間 4,187 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/**
 *    author:  zjs
 *    created: 01.09.2026 19:51:18
**/
#include <bits/stdc++.h>
#include <cassert> // <bits/stdc++.h> does not include cassert since GCC 16.
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    
    int ans = 0;
    vector<int> vis(n + 1);
    int t = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            ++t;
            int j = i;
            while (!vis[j]) {
                vis[j] = t;
                j = a[j];
            }
            if (vis[j] == t)
                ans++;
        }
    }
    cout << ans << '\n';
}
0