Submission #429432

#TimeUsernameProblemLanguageResultExecution timeMemory
429432OzyStar Trek (CEOI20_startrek)C++17
23 / 100
113 ms12956 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define lli long long int #define rep(i,a,b) for (lli i = (a); i <= (b); i++) #define repa(i,a,b) for (lli i = (a); i >= (b); i--) #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " #define MAX 100000 #define mod 1000000007 #define pe first #define ga second lli n,d,a,b,g,p; lli arr[3][MAX+2]; vector<lli> hijos[MAX+2]; pair<lli,lli> total; lli ini(lli pos, lli padre) { lli res = 1; for (auto h : hijos[pos]) { if (h == padre) continue; a = ini(h,pos); arr[a][pos]++; res *= a; } if (res == 0) {arr[2][pos] = 1; return 1;} else {arr[2][pos] = 0; return 0;} } void DFS(lli pos, lli padre,lli val) { lli act; arr[val][pos]++; if (arr[0][pos] > 0) g++; else p++; for (auto h : hijos[pos]){ if (h == padre) continue; arr[arr[2][h]][pos]--; if (arr[0][pos] > 0) act = 1; else act = 0; arr[arr[2][h]][pos]++; DFS(h,pos,act); } arr[val][pos]--; } pair<lli,lli> resuelve(lli pos, lli padre) { pair<lli,lli> k,res; res = {0,0}; for (auto h : hijos[pos]) { if (h == padre) continue; k = resuelve(h,pos); arr[arr[2][h]][pos]--; if (arr[0][pos] == 0) { res.ga += k.pe; res.pe += k.ga; } else { res.ga += k.pe; res.ga += k.ga; } arr[arr[2][h]][pos]++; } res.ga += p; if (arr[0][pos] > 0) res.ga += g; else res.pe += g; return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> d; rep(i,1,n-1) { cin >> a >> b; hijos[a].push_back(b); hijos[b].push_back(a); } a = ini(1,0); DFS(1,0,1); total = resuelve(1,0); cout << total.ga; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...