QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#728148 | #4589. White-Black Tree | MeatInTheMiddle# | WA | 1ms | 6804kb | C++17 | 1.2kb | 2024-11-09 14:39:13 | 2024-11-09 14:39:15 |
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 ^= dfs(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: 0ms
memory: 6504kb
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: 6000kb
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: 6804kb
input:
4 1 1 1 1 1 0 1
output:
First
result:
ok single line: 'First'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5952kb
input:
2 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5964kb
input:
3 1 2 0 1 1
output:
First
result:
ok single line: 'First'
Test #6:
score: 0
Accepted
time: 1ms
memory: 6192kb
input:
3 1 2 1 1 1
output:
First
result:
ok single line: 'First'
Test #7:
score: 0
Accepted
time: 1ms
memory: 6256kb
input:
3 1 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #8:
score: 0
Accepted
time: 1ms
memory: 6032kb
input:
3 1 1 0 1 0
output:
First
result:
ok single line: 'First'
Test #9:
score: 0
Accepted
time: 0ms
memory: 6348kb
input:
3 1 1 0 1 1
output:
Second
result:
ok single line: 'Second'
Test #10:
score: 0
Accepted
time: 1ms
memory: 5952kb
input:
4 1 1 2 0 1 1 0
output:
First
result:
ok single line: 'First'
Test #11:
score: 0
Accepted
time: 1ms
memory: 6076kb
input:
4 1 1 1 0 1 1 1
output:
First
result:
ok single line: 'First'
Test #12:
score: 0
Accepted
time: 0ms
memory: 6332kb
input:
4 1 2 3 0 1 0 1
output:
First
result:
ok single line: 'First'
Test #13:
score: 0
Accepted
time: 1ms
memory: 6608kb
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: 6016kb
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: 5960kb
input:
2 1 1 0
output:
First
result:
ok single line: 'First'
Test #16:
score: 0
Accepted
time: 1ms
memory: 6776kb
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: 6268kb
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: 5952kb
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: 6460kb
input:
5 1 1 2 3 0 1 1 1 1
output:
Second
result:
ok single line: 'Second'
Test #20:
score: 0
Accepted
time: 1ms
memory: 6024kb
input:
5 1 1 2 3 0 1 1 1 0
output:
First
result:
ok single line: 'First'
Test #21:
score: 0
Accepted
time: 1ms
memory: 6020kb
input:
6 1 1 1 3 3 0 1 0 1 1 1
output:
Second
result:
ok single line: 'Second'
Test #22:
score: 0
Accepted
time: 1ms
memory: 6440kb
input:
6 1 1 1 3 3 0 1 1 0 1 1
output:
First
result:
ok single line: 'First'
Test #23:
score: -100
Wrong Answer
time: 0ms
memory: 6024kb
input:
8 1 2 3 4 5 6 7 0 1 1 1 1 1 1 1
output:
Second
result:
wrong answer 1st lines differ - expected: 'First', found: 'Second'