Submission #92531

# Submission time Handle Problem Language Result Execution time Memory
92531 2019-01-03T10:45:32 Z ltomic Deblo (COCI18_deblo) C++14
45 / 90
1000 ms 14332 KB
#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

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 time Memory Grader output
1 Correct 3 ms 2680 KB Output is correct
2 Correct 3 ms 2680 KB Output is correct
3 Correct 3 ms 2680 KB Output is correct
4 Correct 12 ms 2680 KB Output is correct
5 Correct 12 ms 2684 KB Output is correct
6 Execution timed out 1074 ms 14328 KB Time limit exceeded
7 Execution timed out 1081 ms 14332 KB Time limit exceeded
8 Execution timed out 1087 ms 9208 KB Time limit exceeded
9 Execution timed out 1083 ms 8824 KB Time limit exceeded
10 Execution timed out 1081 ms 8056 KB Time limit exceeded