Submission #92531

#TimeUsernameProblemLanguageResultExecution timeMemory
92531ltomicDeblo (COCI18_deblo)C++14
45 / 90
1087 ms14332 KiB
#include <cstdio>
#include <vector>

using namespace std;

using llint = long long;

const int MAXN = 1e5+5;

vector<int> G[MAXN];
int a[MAXN];
int n, x, y;
llint sum;

llint dfs(int x, int p, int val) {
  llint ret = a[x]^val;
  for (int i: G[x]) {
    if (i == p) continue;
    ret += dfs(i, x, val^a[x]);
  }

  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
    sum += a[i];
  }

  for (int i = 0; i < n-1; ++i) {
    scanf("%d %d", &x, &y);
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  for (int i = 0; i < n; ++i) {
    sum += dfs(i, -1, 0);
  }

  printf("%lld\n", sum/2);
  return 0;
}

Compilation message (stderr)

deblo.cpp: In function 'int main()':
deblo.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
deblo.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", a+i);
     ~~~~~^~~~~~~~~~~
deblo.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &x, &y);
     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...