QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572494#8948. 报复社会Arghariza0 40ms19360kbC++171.1kb2024-09-18 14:56:022024-09-18 14:56:02

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 14:56:02]
  • 评测
  • 测评结果:0
  • 用时:40ms
  • 内存:19360kb
  • [2024-09-18 14:56:02]
  • 提交

answer

#include <bits/stdc++.h>
#define eb emplace_back
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
bool Mbe;

const int N = 5e5 + 5;
int n, c[N], f[N];
vector<int> g[N];

int sgn(int x) {
	return x > 0 ? 1 : -1;
}

void dfs(int u) {
	if (!g[u].size()) f[u] = (c[u] ? -1 : 1);
	else f[u] = 0;
	for (int v : g[u]) dfs(v), f[u] += f[v];
	if (!f[u]) f[u] = (n & 1) ? -1 : 1;
	else f[u] = sgn(f[u]);
}

void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) g[i].clear();
	for (int i = 2, x; i <= n; i++) 
		cin >> x, g[x].eb(i);
	for (int i = 1; i <= n; i++) cin >> c[i];
	dfs(1);
	if (f[1] == 1) cout << "Alice\n";
	else cout << "Bob\n";
}

// #define FILE

bool Med;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
	#ifdef FILE
		freopen("alphago.in", "r", stdin);
		freopen("alphago.out", "w", stdout);
	#endif
	int T = 1;
	cin >> T;
	while (T--) solve();
	cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 18824kb

input:

1
19
1 2 3 3 2 6 7 7 6 6 6 2 2 2 1 1 1 1
0 0 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0 0 0

output:

Alice

result:

wrong answer 1st words differ - expected: 'Bob', found: 'Alice'

Subtask #2:

score: 0
Wrong Answer

Test #50:

score: 0
Wrong Answer
time: 36ms
memory: 19360kb

input:

10000
49
1 2 2 1 5 5 5 5 5 5 1 12 12 12 12 12 12 1 19 19 19 19 19 19 19 1 27 27 1 1 31 1 33 33 33 33 33 33 33 1 1 1 1 1 1 1 1 1
0 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1
50
1 2 2 2 2 2 1 8 8 8 1 12 1 1 15 15 15 15 1 1 21 21 21 21 1 26 1 1 29 29...

output:

Bob
Alice
Bob
Bob
Alice
Alice
Alice
Bob
Alice
Alice
Bob
Bob
Bob
Alice
Alice
Alice
Bob
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Bob
Bob
Alice
Bob
Bob
Alice
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Alice
Alice
Alice
Alice
Bob
Bob
Bob
Alice
Bob
Alice
Bob
Bob
Alice
Alice
Alice
Alic...

result:

wrong answer 3rd words differ - expected: 'Alice', found: 'Bob'

Subtask #3:

score: 0
Wrong Answer

Test #73:

score: 0
Wrong Answer
time: 40ms
memory: 19308kb

input:

10000
50
1 2 1 4 5 6 5 4 9 4 11 4 1 14 15 16 16 16 15 14 21 21 21 14 14 14 14 14 1 30 30 30 30 30 1 36 37 37 37 36 41 41 41 36 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 1 1 0 1 0 1
50
1 2 3 4 5 4 7 8 7 4 11 12 11 14 11 16 11 18 11 4 21 4 4 4 3 ...

output:

Alice
Bob
Alice
Bob
Alice
Alice
Bob
Bob
Bob
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Bob
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Alice
Alice
Alice
Alice
Alice
Bob
Alice
Bob
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Bob
Alice
Alice
Alice
Bob
Bob
...

result:

wrong answer 2nd words differ - expected: 'Alice', found: 'Bob'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%