## AGC 017

### A

DP 即可。

const int N = 55;

int n, p, a[N];
ll dp[N][2];

int main () {
IN (n), IN (p);
lep (i, 1, n) IN (a[i]), a[i] &= 1;

dp[0][0] = 1;
lep (i, 1, n) lep (j, 0, 1) dp[i][j] = dp[i - 1][j] + dp[i - 1][j ^ a[i]];
printf ("%lld\n", dp[n][p]);
return 0;
}


### B

int n, A, B, C, D;

int main () {
IN (n), IN (A), IN (B), IN (C), IN (D);

bool flag = false;
lep (i, 0, n - 1) {
ll L = 1ll * C * (n - i - 1) - 1ll * D * i;
ll R = 1ll * D * (n - i - 1) - 1ll * C * i;
flag |= (L <= B - A && B - A <= R);
}

puts (flag ? "YES" : "NO");
return 0;
}


### C

const int N = 2e5 + 5;

int n, m, ans, a[N], sta[N], seq[N];

int main () {
IN (n), IN (m);
lep (i, 1, n) {
IN (a[i]), ++ sta[a[i]];
if (a[i] - sta[a[i]] + 1 > 0) ++ seq[a[i] - sta[a[i]] + 1];
}
lep (i, 1, n) ans += ! seq[i];

int x, y;
while (m -- ) {
IN (x), IN (y);
if (a[x] - sta[a[x]] + 1 > 0) -- seq[a[x] - sta[a[x]] + 1], ans += ! seq[a[x] - sta[a[x]] + 1];
-- sta[a[x]], a[x] = y, ++ sta[a[x]];
if (a[x] - sta[a[x]] + 1 > 0) ans -= ! seq[a[x] - sta[a[x]] + 1], ++ seq[a[x] - sta[a[x]] + 1];
printf ("%d\n", ans);
}
return 0;
}


### D

const int N = 1e5 + 5;

int n;
vector <int> to[N];

int sg (int u, int pre) {
int now = 0;
for (int v : to[u]) if (v != pre) now ^= sg (v, u) + 1;
return now;
}

int u, v;
int main () {
IN (n);
lep (i, 2, n) IN (u), IN (v), to[u].pb (v), to[v].pb (u);
puts (sg (1, 0) ? "Alice" : "Bob");
return 0;
}


### E

const int N = 1e5 + 5;
const int H = 4e2 + 5;
const int _ = 2e2;

bool able[H];
int n, h, a, b, c, d, in[H], ot[H], fa[H];
int find (int x) { return x == fa[x] ? x : fa[x] = find (fa[x]); }

int u, v;
int main () {
IN (n), IN (h);
lep (i, 0, _ << 1) fa[i] = i;
lep (i, 1, n) {
IN (a), IN (b), IN (c), IN (d);
c == 0 ? ++ ot[u = _ + a] : ++ ot[u = _ - c];
d == 0 ? ++ in[v = _ - b] : ++ in[v = _ + d];
if (find (u) != find (v)) fa[find (u)] = find (v);
}

int s = 0, t = 0;
Lep (i, 0, _) if (in[i] < ot[i]) return puts ("NO"), 0;
lep (i, _ + 1, _ << 1) if (in[i] > ot[i]) return puts ("NO"), 0;
lep (i, 0, _ << 1) if (in[i] != ot[i]) able[find (i)] = true;
lep (i, 0, _ << 1) if (in[i] + ot[i]) if (! able[find (i)]) return puts ("NO"), 0;
puts (s == t ? "YES" : "NO");
return 0;
}


QAQ