結果
| 問題 |
No.1868 Teleporting Cyanmond
|
| コンテスト | |
| ユーザー |
motimoti_purinn
|
| 提出日時 | 2022-03-11 22:02:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,646 bytes |
| コンパイル時間 | 1,858 ms |
| コンパイル使用メモリ | 180,204 KB |
| 実行使用メモリ | 15,104 KB |
| 最終ジャッジ日時 | 2024-09-16 02:19:33 |
| 合計ジャッジ時間 | 3,335 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | WA * 25 |
ソースコード
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define fore(i, a) for (auto& i : a)
#define MP make_pair
using namespace std;
using ld = long double;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using Graph = vector<vector<ll>>;
using in = int;
using vin = vector<in>;
using vvin = vector<vector<int>>;
using PQS = priority_queue<int, vector<int>, greater<int>>;
using PQ = priority_queue<int>;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const string YYY = "YES";
const string yyy = "Yes";
const string NNN = "NO";
const string nnn = "No";
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T>
bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
} else {
return false;
}
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
std::fill((T*)array, (T*)(array + N), val);
}
template <class T>
bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
} else {
return false;
}
}
bool cmp(const pll& a, const pll& b) { return a.second > b.second; }
ll GD(ll num) { //各桁の和
ll digit = 0;
while (num != 0) {
digit += num % 10;
num /= 10;
}
return digit;
}
bool if_integer(ld x) { //整数判定
return std::floor(x) == x;
}
bool if_prime(ll x) {
bool a = true;
for (ll i = 2; i * i <= x; i++) {
if (x % i == 0) {
a = false;
break;
}
}
if (x == 1) a = false;
return a;
}
ll gcd(ll x, ll y) {
if (x % y == 0) {
return (y);
} else {
return (gcd(y, x % y));
}
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int GetDigit(int num) {
int digit = 0;
while (num != 0) {
num /= 10;
digit++;
}
return digit;
}
vector<int> bfs(Graph G, int N, int s) {
vin d(N, -1);
d[s] = 0;
queue<int> que;
que.push(s);
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto nv : G[v]) {
if (d[nv] != -1) {
continue;
}
d[nv] = d[v] + 1;
que.push(nv);
}
}
return d;
}
signed main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << std::fixed << std::setprecision(50);
////////////////////////////
///////////////////////////
in N;
cin >> N;
Graph G(N);
rep(i, N - 1) {
in a;
cin >> a;
a--;
G[i].push_back(a);
}
auto d = bfs(G, N, 0);
cout << d[N - 1] << endl;
}
//
// rm -rf test/ && oj d
// g++ main.cpp
// oj t --ignore-spaces-and-newline
motimoti_purinn