Submission #42721271


Source Code Expand

#ifdef LOCAL
class SS {
   int x[0];
};
extern "C" SS __sanitizer_print_stack_trace();
#define __last_state                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   \
   }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   \
   ;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   \
   SS x {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              \
      __sanitizer_print_stack_trace()
#endif
#include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <math.h>

using namespace __gnu_pbds;
using namespace std;
#define endl "\n"
#define mp make_pair
#define st first
#define nd second
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10), cin.tie(0), cout.tie(0);
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fwd(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(c) (c).begin(), (c).end()
#define sz(X) (int)((X).size())
typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; // find_by_order(x) <-returns x-th element   order_of_key(x) <- returns order of element x
// mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());uniform_int_distribution<int> distr(0, 1e9);auto my_rand = bind(distr, gen); // my_rand() zwraca teraz liczbe z przedzialu [a, b]
#ifdef LOCAL
ostream &operator<<(ostream &out, string str) {
   for (char c : str)
      out << c;
   return out;
}
template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.st << ", " << p.nd << ")"; }
template <class L, class R, class S> ostream &operator<<(ostream &out, tuple<L, R, S> p) {
   auto &[a, b, c] = p;
   return out << "(" << a << ", " << b << ", " << c << ")";
}
template <class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
   out << '{';
   for (auto it = a.begin(); it != a.end(); it = next(it))
      out << (it != a.begin() ? ", " : "") << *it;
   return out << '}';
}
void dump() { cerr << "\n"; }
template <class T, class... Ts> void dump(T a, Ts... x) {
   cerr << a << ", ";
   dump(x...);
}
#define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#define debug(...) ;
#endif

vector<vector<int>> G;
vector<map<int, int>> M;

void dfs(int x) {

   for (int y : G[x]) {
      dfs(y);
      for (auto [a, b] : M[y])
         M[x][a] += b;
   }
}

bool good(map<int, int> &M, int k) {
   int cnt = 0;
   bool ok = M[k] == 0 and M[-1] <= 1;
   for (int i = 0; i < k; i++)
      cnt += (M[i] > 0);

   return ok and (cnt == k or (cnt == k - 1 and M[-1] == 1));
}

void solve() {
   int n, k;
   cin >> n >> k;
   G.clear();
   G.resize(n);
   M.clear();
   M.resize(n);

   rep(i, n - 1) {
      int a;
      cin >> a;
      G[--a].push_back(i + 1);
   }

   rep(i, n) {
      int val;
      cin >> val;
      M[i][val] = 1;
   }
   dfs(0);

   bool gd = false;
   rep(i, n) gd |= good(M[i], k);
   cout << (gd ? "Alice" : "Bob") << endl;
}

int32_t main() {
   _upgrade;
   int Z;
   cin >> Z;
   while (Z--)
      solve();
}

Submission Info

Submission Time
Task C - Mex Game on Tree
User jacynkaa
Language C++ (GCC 9.2.1)
Score 500
Code Size 7077 Byte
Status AC
Exec Time 219 ms
Memory 50744 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 1
AC × 12
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 1 ms 3596 KiB
01_test_01.txt AC 89 ms 33672 KiB
01_test_02.txt AC 45 ms 18028 KiB
01_test_03.txt AC 106 ms 41288 KiB
01_test_04.txt AC 6 ms 3696 KiB
01_test_05.txt AC 6 ms 3716 KiB
01_test_06.txt AC 10 ms 3588 KiB
01_test_07.txt AC 6 ms 3552 KiB
01_test_08.txt AC 5 ms 3612 KiB
01_test_09.txt AC 4 ms 3632 KiB
02_handmade_01.txt AC 172 ms 50744 KiB
02_handmade_02.txt AC 219 ms 50112 KiB