제출 #707432

#제출 시각아이디문제언어결과실행 시간메모리
707432nguyentunglamDeblo (COCI18_deblo)C++17
90 / 90
139 ms35368 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 1e5 + 10; int a[N], f[2][26][N]; vector<int> adj[N]; long long res; void dfs(int u, int par, int h) { for(int bit = 0; bit <= 22; bit++) f[(h >> bit) & 1][bit][u]++; res += a[u]; for(int v : adj[u]) if (v != par) { dfs(v, u, h ^ a[v]); for(int bit = 0; bit <= 22; bit++) for(int j = 0; j < 2; j++) for(int k = 0; k < 2; k++) { bool x = (a[u] >> bit) & 1; if (x ^ j ^ k) res += (1LL << bit) * f[j][bit][u] * f[k][bit][v]; } for(int bit = 0; bit <= 22; bit++) for(int j = 0; j < 2; j++) f[j][bit][u] += f[j][bit][v]; } } int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i < n; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1, 0, a[1]); cout << res; }

컴파일 시 표준 에러 (stderr) 메시지

deblo.cpp: In function 'int main()':
deblo.cpp:27:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
deblo.cpp:28:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
deblo.cpp:31:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
deblo.cpp:32:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...