提出 #27418439
ソースコード 拡げる
// {{{
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define debug(x...)
#define debug_arr(x...)
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// }}}
const int N = 2e5 + 10;
int head[N], e;
struct E
{
int v, next;
} edge[N << 1];
void addedge(int u, int v)
{
edge[e].v = v, edge[e].next = head[u];
head[u] = e++;
}
int vis[N];
void dfs(int u, int f)
{
if (vis[u]) return;
vis[u] = 1;
for (int i = head[u]; ~i; i = edge[i].next)
{
int v = edge[i].v;
if (v == f) continue;
dfs(v, u);
}
}
int n, x;
int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
while (cin >> n >> x)
{
clr(head, -1), e = 0;
for (int i = 1; i <= n; i++)
{
int u = i;
int v;
cin >> v;
addedge(u, v);
}
clr(vis, false);
dfs(x, -1);
int ans = 0;
for (int i = 1; i <= n; i++) ans += vis[i];
cout << ans << '\n';
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - Takahashi's Secret |
| ユーザ | mickeyandkaka |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 200 |
| コード長 | 1406 Byte |
| 結果 | AC |
| 実行時間 | 26 ms |
| メモリ | 10688 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 200 / 200 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 8 ms | 5088 KiB |
| 001.txt | AC | 22 ms | 10688 KiB |
| 002.txt | AC | 14 ms | 5892 KiB |
| 003.txt | AC | 14 ms | 5936 KiB |
| 004.txt | AC | 23 ms | 10580 KiB |
| 005.txt | AC | 18 ms | 5932 KiB |
| 006.txt | AC | 17 ms | 8264 KiB |
| 007.txt | AC | 26 ms | 8280 KiB |
| 008.txt | AC | 14 ms | 5952 KiB |
| 009.txt | AC | 16 ms | 7112 KiB |
| 010.txt | AC | 16 ms | 5952 KiB |
| 011.txt | AC | 19 ms | 5948 KiB |
| 012.txt | AC | 19 ms | 5844 KiB |
| 013.txt | AC | 19 ms | 8184 KiB |
| 014.txt | AC | 18 ms | 8216 KiB |
| 015.txt | AC | 23 ms | 10684 KiB |
| 016.txt | AC | 12 ms | 5696 KiB |
| 017.txt | AC | 10 ms | 5552 KiB |
| 018.txt | AC | 13 ms | 5584 KiB |
| 019.txt | AC | 21 ms | 5932 KiB |
| 020.txt | AC | 17 ms | 5940 KiB |
| 021.txt | AC | 14 ms | 5972 KiB |
| 022.txt | AC | 14 ms | 5960 KiB |
| 023.txt | AC | 18 ms | 5976 KiB |
| example0.txt | AC | 3 ms | 5096 KiB |
| example1.txt | AC | 4 ms | 5100 KiB |