QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245089 | #4583. Concerto de Pandemic | warner1129# | RE | 0ms | 0kb | C++20 | 1.7kb | 2023-11-09 18:37:05 | 2023-11-09 18:37:05 |
answer
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template<class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
constexpr int inf = 1e9;
constexpr int mod = 998244353;
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }
void solve() {
int n;
cin >> n;
vector<int> A(n);
vector G(n, vector<int>{});
for (int i = 1; i < n; i++) {
int f;
cin >> f;
f--;
G[f].push_back(i);
}
for (int &x : A) cin >> x;
vector<i64> siz(n, 1);
function<i64(int)> dfs = [&](int u) -> int {
i64 x = 0;
for (int v : G[u]) {
x ^= dfs(v);
siz[u] *= siz[v] + 1;
}
if (A[u]) return siz[u];
else return x;
};
if (dfs(0)) cout << "First\n";
else cout << "Second\n";
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Runtime Error
input:
10 4 3 2 1 2 4 4 6 2 7 5 2 5 8