Security Involution

  • + 0 comments

    php solution because why not...

    $_fp = fopen("php://stdin", "r");
    
    $n = fgets($_fp);
    $set = explode(' ', fgets($_fp));
    $set = array_combine(range(1, count($set)), $set);
    $involution = true;
    
    foreach ($set as $k => $v) {
        if ($k !== intval($set[$v])) {
            $involution = false;
            break;
        }
    }
    
    echo ($involution ? "YES" : "NO") . PHP_EOL;