# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
758598 |
2023-06-15T00:04:16 Z |
DmitryKh |
Deblo (COCI18_deblo) |
C++14 |
|
1000 ms |
65536 KB |
#include <iostream>
#include <vector>
#include <list>
#include <unordered_map>
using namespace std;
using ll = long long;
void DFS(int v,
const vector<vector<int>>& E,
const vector<int>& A,
vector<bool>& V,
vector<ll>& S,
vector<vector<ll>>& TW) {
S[v] = A[v];
TW[v].push_back(A[v]);
V[v] = true;
vector<int> VV;
for (auto u : E[v]) {
if (!V[u]) {
DFS(u, E, A, V, S, TW);
S[v] += S[u];
for (auto tw : TW[u]) {
S[v] += A[v]^tw;
TW[v].push_back(A[v]^tw);
}
for (auto vv : VV) {
for (auto l : TW[u]) {
for (auto r : TW[vv]) {
S[v] += A[v]^l^r;
}
}
}
VV.push_back(u);
}
}
}
int main(int argc, char* argv[]) {
int n;
cin >> n;
vector<int> A(n + 1);
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
vector<vector<int>> E(n + 1);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
E[u].push_back(v);
E[v].push_back(u);
}
{
vector<ll> S(n + 1);
vector<vector<ll>> TW(n + 1);
{
vector<bool> V(n + 1);
DFS(1, E, A, V, S, TW);
}
/*for (int i = 1; i <= n; i++)
cout << "S[" << i << "]=" << S[i] << '\n';*/
cout << S[1] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
2132 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Runtime error |
174 ms |
65536 KB |
Execution killed with signal 9 |
7 |
Runtime error |
154 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Runtime error |
194 ms |
65536 KB |
Execution killed with signal 9 |
9 |
Runtime error |
218 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Execution timed out |
1092 ms |
18512 KB |
Time limit exceeded |