結果

問題 No.2841 Leaf Eater
ユーザー SnowBeenDiding
提出日時 2024-08-10 00:17:00
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 845 bytes
コンパイル時間 2,990 ms
コンパイル使用メモリ 245,644 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-08-10 00:17:07
合計ジャッジ時間 5,889 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace std;

typedef long long ll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
    int n = v.size();
    rep(i, 0, n) { os << v[i] << " \n"[i == n - 1]; }
    return os;
}

void solve() {
    int n;
    cin >> n;
    vector<int> p(n, -1);
    rep(i, 1, n) cin >> p[i], p[i]--;
    vector<int> children_count(n, 0), l(n);
    rep(i, 1, n) children_count[p[i]]++;
    rep(i, 1, n) {
        if (children_count[i] >= 2) {
            l[i] = 0;
        } else {
            l[i] = l[p[i]] + 1;
        }
        if (children_count[i] == 0 && l[i] % 2) {
            cout << "First\n";
            return;
        }
    }
    cout << "Second\n";
}

int main() {
    int t;
    cin >> t;
    while (t--)
        solve();
}
0