結果
| 問題 | 
                            No.3217 Shiki no Shiki
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-08-02 16:31:22 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,959 bytes | 
| コンパイル時間 | 3,887 ms | 
| コンパイル使用メモリ | 281,408 KB | 
| 実行使用メモリ | 7,720 KB | 
| 最終ジャッジ日時 | 2025-08-02 16:31:28 | 
| 合計ジャッジ時間 | 5,248 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 3 WA * 20 | 
ソースコード
#include <bits/stdc++.h>
#define REP(i, n)     for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n)    for(int i = (int)(n); i-- > 0;)
#define FOR(i, l, r)  for(int i = (int)(l); i < (int)(r); ++i)
#define RFOR(i, l, r) for(int i = (int)(r); i-- > (int)(l);)
#define ALL(v)        std::begin(v), std::end(v)
using llong = long long;
using vi    = std::vector<int>;
using vvi   = std::vector<vi>;
using pii   = std::pair<int, int>;
using namespace std;
constexpr int       INF  = 1e9;
constexpr long long LINF = 1e18;
constexpr double    EPS  = 1e-10;
constexpr int       MOD  = 998'244'353;
constexpr int       MOD2 = 1e9 + 7;
template <typename C, typename Tr, typename R, typename T = std::ranges::range_value_t<R>>
    requires std::ranges::output_range<R, T>
inline auto &operator>>(std::basic_istream<C, Tr> &is, R &r) {
    for(auto &elem : r) is >> elem;
    return is;
}
template <typename C, typename Tr, std::ranges::input_range R>
    requires(!std::convertible_to<R, const char *>)
inline auto &operator<<(std::basic_ostream<C, Tr> &os, const R &r) {
    if(std::ranges::empty(r)) return os;
    auto iter = std::ranges::cbegin(r);
    const auto end = std::ranges::cend(r);
    os << *iter++;
    while(iter != end) os << " " << *iter++;
    return os;
}
#ifdef DEBUG
#include <debug>
#else
#define debug(...) static_cast<void>(0)
#endif
int main(){
    int n;
    cin>>n;
    vi p(n);
    vi deg(n,0);
    for(auto &e:p){
        cin>>e;
        if(e!=0) deg[e-1]++;
    }
    debug(deg);
    vi depth(n,-1);
    queue<int> que;
    REP(i,n){
        if(deg[i]>0) continue;
        depth[i]=0;
        que.push(i);
    }
    while(!que.empty()){
        auto u=que.front();
        que.pop();
        if(p[u]==0) continue;
        auto v=p[u]-1;
        if(depth[v]!=-1) continue;
        depth[v]=depth[u]+1;
        que.push(v);
    }
    
    int ans=0;
    for(auto e:depth){
        if(e==2) ans++;
    }
    cout<<ans<<endl;
}