QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#728218 | #4589. White-Black Tree | MeatInTheMiddle# | WA | 1ms | 6860kb | C++17 | 1.2kb | 2024-11-09 14:48:08 | 2024-11-09 14:48:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fastio (ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL))
typedef long long ll;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int MAXSIZE = 2000000;
const long long INF = 1e18 + 5;
const double EPSILON = 1e-14;
const ll DIV = 2000003;
const long double pi = 3.14159265358979323846264338327950288419716939937510L;
int n;
int tg[101001];
int cnt[101010];
vector<int> adj[101010];
int dfs(int cur)
{
int ret = 0;
cnt[cur] = 1;
for (int nxt : adj[cur])
{
ret ^= dfs(nxt);
cnt[cur] += cnt[nxt];
}
if (tg[cur])
ret ^= cnt[cur];
return ret;
}
int dfs2(int cur)
{
if (tg[cur])
return cnt[cur];
int ret = 0;
for (int nxt : adj[cur])
{
ret ^= dfs2(nxt);
}
return ret;
}
int main()
{
fastio;
cin >> n;
for (int i = 2; i <= n; i++)
{
int a;
cin >> a;
adj[a].push_back(i);
}
for (int i = 1; i <= n; i++)
cin >> tg[i];
int t = dfs(1);
t = dfs2(1);
if (t)
cout << "First";
else
cout << "Second";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5960kb
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: 6800kb
input:
5 1 1 2 3 0 1 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #3:
score: 0
Accepted
time: 1ms
memory: 6080kb
input:
4 1 1 1 1 1 0 1
output:
First
result:
ok single line: 'First'
Test #4:
score: 0
Accepted
time: 0ms
memory: 5952kb
input:
2 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #5:
score: 0
Accepted
time: 0ms
memory: 6668kb
input:
3 1 2 0 1 1
output:
First
result:
ok single line: 'First'
Test #6:
score: 0
Accepted
time: 1ms
memory: 6668kb
input:
3 1 2 1 1 1
output:
First
result:
ok single line: 'First'
Test #7:
score: 0
Accepted
time: 1ms
memory: 6016kb
input:
3 1 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5964kb
input:
3 1 1 0 1 0
output:
First
result:
ok single line: 'First'
Test #9:
score: 0
Accepted
time: 0ms
memory: 6196kb
input:
3 1 1 0 1 1
output:
Second
result:
ok single line: 'Second'
Test #10:
score: 0
Accepted
time: 0ms
memory: 5960kb
input:
4 1 1 2 0 1 1 0
output:
First
result:
ok single line: 'First'
Test #11:
score: 0
Accepted
time: 0ms
memory: 6028kb
input:
4 1 1 1 0 1 1 1
output:
First
result:
ok single line: 'First'
Test #12:
score: 0
Accepted
time: 1ms
memory: 5956kb
input:
4 1 2 3 0 1 0 1
output:
First
result:
ok single line: 'First'
Test #13:
score: 0
Accepted
time: 1ms
memory: 6500kb
input:
5 1 1 2 2 0 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #14:
score: 0
Accepted
time: 1ms
memory: 6256kb
input:
5 1 1 2 2 0 0 1 0 1
output:
Second
result:
ok single line: 'Second'
Test #15:
score: 0
Accepted
time: 1ms
memory: 6016kb
input:
2 1 1 0
output:
First
result:
ok single line: 'First'
Test #16:
score: 0
Accepted
time: 1ms
memory: 6088kb
input:
5 1 1 2 2 0 1 1 0 0
output:
First
result:
ok single line: 'First'
Test #17:
score: 0
Accepted
time: 0ms
memory: 6076kb
input:
5 1 1 1 2 0 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #18:
score: 0
Accepted
time: 1ms
memory: 6708kb
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: 5968kb
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: 6860kb
input:
5 1 1 2 3 0 1 1 1 0
output:
Second
result:
wrong answer 1st lines differ - expected: 'First', found: 'Second'