結果

問題 No.3217 Shiki no Shiki
ユーザー しもりん
提出日時 2025-08-01 21:27:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 85,940 KB
最終ジャッジ日時 2025-08-01 21:27:14
合計ジャッジ時間 2,969 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import os


IS_LOCAL = os.environ.get("LOCAL") == "true"


def debug(*args, sep=" ", end="\n", flush=False) -> None:
    if IS_LOCAL:
        print(*args, sep=sep, end=end, file=sys.stderr, flush=flush)


def yn(flg: bool) -> bool:
    print('Yes' if flg else 'No')
    return flg


def gcd(a, b):
    a = abs(a); b = abs(b)
    if a < b: a, b = b, a
    while b > 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    readline = sys.stdin.readline
    float("inf")

    N = int(input())
    P = list(map(lambda x: int(x) - 1, readline().split()))
    S = [0] * N
    for p in P:
        if p >= 0:
            S[p] += 1
    seen = [False] * N
    for k in range(N):
        if S[k] == 0 and P[k] >= 0:
            j = P[k]
            if P[j] >= 0:
                i = P[j]
                seen[i] = True
    ans = sum(seen)
    print(ans)


if __name__ == "__main__":
    main()
0