제출 #758603

#제출 시각아이디문제언어결과실행 시간메모리
758603DmitryKhDeblo (COCI18_deblo)C++14
45 / 90
1068 ms65536 KiB
#include <iostream> #include <vector> #include <list> #include <map> using namespace std; using ll = long long; ll DFS(int v, const vector<vector<int>>& E, const vector<int>& A, vector<bool>& V, map<int, vector<ll>>& TW) { ll S = A[v]; TW[v].push_back(A[v]); V[v] = true; vector<int> VV; for (auto u : E[v]) { if (!V[u]) { S += DFS(u, E, A, V, TW); for (auto tw : TW[u]) { S += 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 += A[v]^l^r; } } } VV.push_back(u); } } return S; } 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); } { ll S = 0; map<int, vector<ll>> TW; { vector<bool> V(n + 1); S = DFS(1, E, A, V, TW); } /*for (int i = 1; i <= n; i++) cout << "S[" << i << "]=" << S[i] << '\n';*/ cout << S << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...