QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65354 | #4589. White-Black Tree | Sa3tElSefr# | WA | 4ms | 5872kb | C++20 | 1.1kb | 2022-11-29 22:16:56 | 2022-11-29 22:16:57 |
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];
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 5688kb
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: 1ms
memory: 5676kb
input:
5 1 1 2 3 0 1 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #3:
score: 0
Accepted
time: 0ms
memory: 5872kb
input:
4 1 1 1 1 1 0 1
output:
First
result:
ok single line: 'First'
Test #4:
score: 0
Accepted
time: 4ms
memory: 5688kb
input:
2 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #5:
score: 0
Accepted
time: 2ms
memory: 5688kb
input:
3 1 2 0 1 1
output:
First
result:
ok single line: 'First'
Test #6:
score: 0
Accepted
time: 2ms
memory: 5780kb
input:
3 1 2 1 1 1
output:
First
result:
ok single line: 'First'
Test #7:
score: 0
Accepted
time: 0ms
memory: 5684kb
input:
3 1 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #8:
score: 0
Accepted
time: 4ms
memory: 5776kb
input:
3 1 1 0 1 0
output:
First
result:
ok single line: 'First'
Test #9:
score: 0
Accepted
time: 2ms
memory: 5788kb
input:
3 1 1 0 1 1
output:
Second
result:
ok single line: 'Second'
Test #10:
score: 0
Accepted
time: 4ms
memory: 5692kb
input:
4 1 1 2 0 1 1 0
output:
First
result:
ok single line: 'First'
Test #11:
score: 0
Accepted
time: 2ms
memory: 5708kb
input:
4 1 1 1 0 1 1 1
output:
First
result:
ok single line: 'First'
Test #12:
score: 0
Accepted
time: 4ms
memory: 5840kb
input:
4 1 2 3 0 1 0 1
output:
First
result:
ok single line: 'First'
Test #13:
score: 0
Accepted
time: 2ms
memory: 5784kb
input:
5 1 1 2 2 0 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #14:
score: 0
Accepted
time: 4ms
memory: 5872kb
input:
5 1 1 2 2 0 0 1 0 1
output:
Second
result:
ok single line: 'Second'
Test #15:
score: 0
Accepted
time: 4ms
memory: 5788kb
input:
2 1 1 0
output:
First
result:
ok single line: 'First'
Test #16:
score: 0
Accepted
time: 4ms
memory: 5704kb
input:
5 1 1 2 2 0 1 1 0 0
output:
First
result:
ok single line: 'First'
Test #17:
score: 0
Accepted
time: 1ms
memory: 5688kb
input:
5 1 1 1 2 0 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #18:
score: 0
Accepted
time: 4ms
memory: 5680kb
input:
5 1 1 1 2 0 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #19:
score: 0
Accepted
time: 1ms
memory: 5688kb
input:
5 1 1 2 3 0 1 1 1 1
output:
Second
result:
ok single line: 'Second'
Test #20:
score: -100
Wrong Answer
time: 1ms
memory: 5788kb
input:
5 1 1 2 3 0 1 1 1 0
output:
Second
result:
wrong answer 1st lines differ - expected: 'First', found: 'Second'