fork download
  1. #include <bits/stdc++.h>
  2. #define TASK "TREEXOR"
  3. #define int long long
  4. #define MOD 1000000007
  5.  
  6. using namespace std;
  7.  
  8. int n, x;
  9. int a[100005], xo[100005], res = 0;
  10. vector <int> adj[100005];
  11.  
  12. void dfs(int u, int up) {
  13. xo[u] = a[u];
  14. for (int v : adj[u]) {
  15. if (v != up) {
  16. dfs(v, u);
  17. xo[u] ^= xo[v];
  18. }
  19. }
  20. if (xo[u] == x) {
  21. res = (res == 0) ? 1 : res * 2 % MOD;
  22. }
  23. }
  24.  
  25. signed main() {
  26. if (fopen(TASK".inp", "r")) {
  27. freopen(TASK".inp", "r", stdin);
  28. freopen(TASK".out", "w", stdout);
  29. }
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0);
  32. cout.tie(0);
  33. cin >> n >> x;
  34. for (int i = 1; i <= n; i++) {
  35. cin >> a[i];
  36. }
  37. for (int i = 1; i < n; i++) {
  38. int u, v;
  39. cin >> u >> v;
  40. adj[u].push_back(v);
  41. adj[v].push_back(u);
  42. }
  43. dfs(1, 0);
  44. cout << res;
  45. }
  46.  
Success #stdin #stdout 0.01s 6452KB
stdin
Standard input is empty
stdout
1