結果

問題 No.2841 Leaf Eater
ユーザー karinohitokarinohito
提出日時 2024-08-09 23:17:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 205,164 KB
実行使用メモリ 15,796 KB
最終ジャッジ日時 2024-08-09 23:18:03
合計ジャッジ時間 4,914 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 46 ms
6,944 KB
testcase_02 AC 47 ms
6,940 KB
testcase_03 AC 48 ms
6,940 KB
testcase_04 AC 47 ms
6,940 KB
testcase_05 AC 48 ms
6,940 KB
testcase_06 AC 162 ms
6,940 KB
testcase_07 AC 123 ms
6,944 KB
testcase_08 AC 109 ms
6,940 KB
testcase_09 AC 71 ms
15,796 KB
testcase_10 AC 72 ms
15,424 KB
testcase_11 AC 75 ms
15,560 KB
testcase_12 AC 76 ms
15,544 KB
testcase_13 AC 55 ms
6,944 KB
testcase_14 AC 62 ms
6,944 KB
testcase_15 AC 57 ms
6,940 KB
testcase_16 AC 64 ms
6,940 KB
testcase_17 AC 55 ms
6,940 KB
testcase_18 AC 52 ms
6,940 KB
testcase_19 AC 66 ms
6,944 KB
testcase_20 AC 65 ms
6,944 KB
testcase_21 AC 62 ms
6,940 KB
testcase_22 AC 58 ms
6,944 KB
testcase_23 AC 58 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve(){
    ll N;
    cin>>N;
    vector<vector<int>> G(N);
    vector<int> D(N,0);
    vector<int> E(N,0);
    for(int i=0;i<N-1;i++){
        int p;
        cin>>p;
        p--;
        G[i+1].push_back(p);
        D[i+1]=D[p]+1;
        E[p]++;
        E[i+1]++;
    }
    bool W=0;
    for(int i=1;i<N;i++){
        if(E[i]==1){
            ll x=G[i][0];
            ll cnt=1;
            while(E[x]==2&&x){
                cnt++;
                x=G[x][0];
            }
            if(cnt%2==1)W=1;
        }
    }
    cout<<(W?"First":"Second")<<endl;
}

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