Submission #27383641


Source Code Expand

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i, a, b) for (int i = (int)(a); (i) < (int)(b); i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

const int MOD = 1000000007;

template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

template <class T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}


int main() {
    ll n, x;
    cin >> n >> x, x--;

    vector<int> a(n);
    rep(i, n) {
      cin >> a[i]; a[i]--;
    }

    map<int, bool> known;
    int ans = 0;
    rep(i, n) {
      if (known[x] != true) {
        known[x] = true;
        x = a[x];
        ans++;
        //cout << x << " " << ans << endl;
      }
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Takahashi's Secret
User m_clove
Language C++ (GCC 9.2.1)
Score 200
Code Size 1215 Byte
Status AC
Exec Time 77 ms
Memory 8292 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 26
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 8 ms 3400 KiB
001.txt AC 77 ms 8232 KiB
002.txt AC 33 ms 3632 KiB
003.txt AC 32 ms 3500 KiB
004.txt AC 73 ms 8144 KiB
005.txt AC 29 ms 3408 KiB
006.txt AC 51 ms 5948 KiB
007.txt AC 49 ms 5968 KiB
008.txt AC 28 ms 3440 KiB
009.txt AC 40 ms 4716 KiB
010.txt AC 35 ms 3748 KiB
011.txt AC 32 ms 3404 KiB
012.txt AC 29 ms 3412 KiB
013.txt AC 51 ms 5856 KiB
014.txt AC 49 ms 5980 KiB
015.txt AC 73 ms 8292 KiB
016.txt AC 29 ms 3620 KiB
017.txt AC 17 ms 3556 KiB
018.txt AC 20 ms 3540 KiB
019.txt AC 29 ms 3608 KiB
020.txt AC 26 ms 3724 KiB
021.txt AC 33 ms 3560 KiB
022.txt AC 35 ms 3688 KiB
023.txt AC 33 ms 3792 KiB
example0.txt AC 2 ms 3456 KiB
example1.txt AC 2 ms 3552 KiB