結果
| 問題 |
No.3217 Shiki no Shiki
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-01 22:59:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 553 bytes |
| コンパイル時間 | 1,158 ms |
| コンパイル使用メモリ | 167,772 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-08-01 22:59:44 |
| 合計ジャッジ時間 | 2,213 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
ll N;
ll p[100010];
set<ll> s;
void dfs(ll x,ll t){
if(t==3){
s.insert(x);
return;
}
if(p[x]!=0) dfs(p[x],t+1);
}
int main(void){
cin.tie(nullptr); ios_base::sync_with_stdio(false);
ll i,j;
cin >> N;
vector<ll> u(N+1,0);
for(i=1;i<=N;i++){
cin >> p[i];
if(p[i]!=0){
u[p[i]]++;
}
}
for(i=1;i<=N;i++){
if(u[i]==0) dfs(i,1);
}
cout << s.size() << endl;
return 0;
}