結果
| 問題 |
No.2841 Leaf Eater
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-09 23:17:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 189 ms / 2,000 ms |
| コード長 | 696 bytes |
| コンパイル時間 | 2,252 ms |
| コンパイル使用メモリ | 198,832 KB |
| 最終ジャッジ日時 | 2025-02-23 22:09:54 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 |
ソースコード
#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();
}