# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
318759 |
2020-11-03T06:50:28 Z |
shrek12357 |
Deblo (COCI18_deblo) |
C++14 |
|
190 ms |
55140 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0);
const int MAXN = 1e5 + 5;
vector<ll> vals(MAXN);
vector<ll> adjList[MAXN];
ll n;
ll dp[MAXN][25][2];
ll ans[25];
void dfs(int src, int par) {
for (int i = 0; i < 25; i++) {
if ((vals[src] >> i) & 1) {
ans[i]++;
dp[src][i][1] = 1;
}
else {
dp[src][i][0] = 1;
}
}
for (auto i : adjList[src]) {
if (i == par) {
continue;
}
dfs(i, src);
for (int j = 0; j < 25; j++) {
ans[j] += dp[src][j][1] * dp[i][j][0];
ans[j] += dp[src][j][0] * dp[i][j][1];
if ((vals[src] >> j) & 1) {
dp[src][j][1] += dp[i][j][0];
dp[src][j][0] += dp[i][j][1];
}
else {
dp[src][j][1] += dp[i][j][1];
dp[src][j][0] += dp[i][j][0];
}
}
}
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
ll temp;
cin >> temp;
vals[i] = temp;
}
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--; b--;
adjList[a].push_back(b);
adjList[b].push_back(a);
}
dfs(0, 0);
ll ret = 0;
for (int i = 0; i < 25; i++)
ret += (ll)ans[i] * (1 << i);
cout << ret << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3468 KB |
Output is correct |
2 |
Correct |
2 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3564 KB |
Output is correct |
4 |
Correct |
4 ms |
3948 KB |
Output is correct |
5 |
Correct |
4 ms |
3948 KB |
Output is correct |
6 |
Correct |
164 ms |
55140 KB |
Output is correct |
7 |
Correct |
158 ms |
55132 KB |
Output is correct |
8 |
Correct |
164 ms |
47844 KB |
Output is correct |
9 |
Correct |
165 ms |
47076 KB |
Output is correct |
10 |
Correct |
190 ms |
46436 KB |
Output is correct |