Submission #42729325
Source Code Expand
/*+Rainybunny+*/
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l, rep##i = r; i <= rep##i; ++i)
#define per(i, r, l) for (int i = r, per##i = l; i >= per##i; --i)
const int MAXN = 1e3;
int n, k, fa[MAXN + 5], a[MAXN + 5], lak[MAXN + 5], req[MAXN + 5];
std::bitset<MAXN + 5> ocr[MAXN + 5];
std::vector<int> adj[MAXN + 5];
inline bool solve(const int u) {
ocr[u].reset(), lak[u] = 0;
if (a[u] == -1) ++lak[u];
else ocr[u][a[u]] = true;
bool bjkasef = false;
for (int v: adj[u]) {
bjkasef |= solve(v);
ocr[u] |= ocr[v], lak[u] += lak[v];
}
if (bjkasef) return true;
if (!ocr[u][k]) {
int cnt = 0;
rep (i, 0, k - 1) cnt += !ocr[u][i];
if (cnt <= lak[u]) return ++req[lak[u]], true;
}
return false;
}
int main() {
int T; scanf("%d", &T);
while (T--) {
scanf("%d %d", &n, &k);
rep (i, 2, n) scanf("%d", &fa[i]);
rep (i, 1, n) scanf("%d", &a[i]);
memset(req, 0, n + 1 << 2);
rep (i, 1, n) adj[i].clear();
rep (i, 2, n) adj[fa[i]].push_back(i);
solve(1);
if (req[0] || req[1]) puts("Alice");
else puts("Bob");
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - Mex Game on Tree |
| User |
Rainybunny |
| Language |
C++ (GCC 9.2.1) |
| Score |
500 |
| Code Size |
1251 Byte |
| Status |
AC |
| Exec Time |
9 ms |
| Memory |
3900 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:38:26: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
38 | memset(req, 0, n + 1 << 2);
| ~~^~~
./Main.cpp:32:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
32 | int T; scanf("%d", &T);
| ~~~~~^~~~~~~~~~
./Main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
34 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
./Main.cpp:35:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
35 | rep (i, 2, n) scanf("%d", &fa[i]);
| ~~~~~^~~~~~~~~~~~~~
./Main.cpp:36:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
36 | rep (i, 1, n) scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_01.txt |
| All |
00_sample_01.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 02_handmade_01.txt, 02_handmade_02.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_01.txt |
AC |
5 ms |
3712 KiB |
| 01_test_01.txt |
AC |
5 ms |
3776 KiB |
| 01_test_02.txt |
AC |
8 ms |
3900 KiB |
| 01_test_03.txt |
AC |
5 ms |
3764 KiB |
| 01_test_04.txt |
AC |
3 ms |
3548 KiB |
| 01_test_05.txt |
AC |
3 ms |
3672 KiB |
| 01_test_06.txt |
AC |
3 ms |
3672 KiB |
| 01_test_07.txt |
AC |
2 ms |
3628 KiB |
| 01_test_08.txt |
AC |
2 ms |
3668 KiB |
| 01_test_09.txt |
AC |
8 ms |
3540 KiB |
| 02_handmade_01.txt |
AC |
6 ms |
3760 KiB |
| 02_handmade_02.txt |
AC |
9 ms |
3796 KiB |