QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65360 | #4589. White-Black Tree | Sa3tElSefr | WA | 4ms | 5780kb | C++20 | 1.1kb | 2022-11-29 22:24:36 | 2022-11-29 22:24:37 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int N = 1e5 + 5, lg = 17, mod = 1e9 + 7;
vector<int> adj[N];
int sz[N];
void dfs(int node, int par) {
sz[node] = 1;
for(auto i: adj[node]) {
if(i == par) continue;
dfs(i, node);
sz[node] += sz[i];
}
}
int xr = 0, col[N];
void dfsAns(int node, int par) {
if(col[node] == 1) {
// cout << node << ' ' << col[node] << '\n';
xr ^= (sz[node] - 1);
return;
}
for(auto i: adj[node]) {
if(i == par) continue;
dfsAns(i, node);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i = 2; i <= n; i++) {
int u = i, v;
cin >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1; i <= n; i++) cin >> col[i];
dfs(1, 0);
dfsAns(1, 0);
if(xr == 0) cout << "Second";
else cout << "First";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 5764kb
input:
7 1 1 1 3 3 3 0 1 1 0 0 0 1
output:
First
result:
ok single line: 'First'
Test #2:
score: 0
Accepted
time: 4ms
memory: 5664kb
input:
5 1 1 2 3 0 1 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #3:
score: 0
Accepted
time: 4ms
memory: 5776kb
input:
4 1 1 1 1 1 0 1
output:
First
result:
ok single line: 'First'
Test #4:
score: 0
Accepted
time: 4ms
memory: 5780kb
input:
2 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #5:
score: 0
Accepted
time: 4ms
memory: 5704kb
input:
3 1 2 0 1 1
output:
First
result:
ok single line: 'First'
Test #6:
score: 0
Accepted
time: 4ms
memory: 5716kb
input:
3 1 2 1 1 1
output:
First
result:
ok single line: 'First'
Test #7:
score: 0
Accepted
time: 2ms
memory: 5660kb
input:
3 1 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #8:
score: -100
Wrong Answer
time: 4ms
memory: 5700kb
input:
3 1 1 0 1 0
output:
Second
result:
wrong answer 1st lines differ - expected: 'First', found: 'Second'