結果

問題 No.3217 Shiki no Shiki
ユーザー Nauclhlt🪷
提出日時 2025-07-28 23:10:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 2,033 ms
コンパイル使用メモリ 197,620 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-07-28 23:10:28
合計ジャッジ時間 4,093 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> P(N + 1);
    vector<int> in_degree(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> P[i];
        if (P[i] != 0) in_degree[P[i]]++;
    }
    
    vector<bool> is_shikigami(N + 1, false);
    for (int q = 1; q <= N; q++) {
        if (in_degree[q] == 0 && P[q] != 0) {
            int p = P[q];
            if (P[p] != 0) {
                is_shikigami[P[p]] = true;
            }
        }
    }
    
    int count = 0;
    for (int i = 1; i <= N; i++) {
        if (is_shikigami[i]) count++;
    }
    cout << count << endl;
    
    return 0;
}
0