結果
問題 | No.2841 Leaf Eater |
ユーザー | karinohito |
提出日時 | 2024-08-09 23:17:57 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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(); }