Submission #213566

#TimeUsernameProblemLanguageResultExecution timeMemory
213566erd1Cats or Dogs (JOI18_catdog)C++14
38 / 100
3099 ms5880 KiB
#include "catdog.h" #include<bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define ff first #define ss second #define pb push_back typedef pair<int, int> pii; vector<int> o; vector<vector<int>> G; void initialize(int N, std::vector<int> A, std::vector<int> B) { G.resize(N+1); o.resize(N+1); for(int i = 0; i < N-1; i++){ G[A[i]].pb(B[i]); G[B[i]].pb(A[i]); } } pii dfs(int i, int par){ //cout << i << " " << par << endl; pii ans = {0, 0}; for(auto x: G[i]){ if(x == par)continue; auto a = dfs(x, i); ans.ss += min(a.ss, a.ff+1); ans.ff += min(a.ff, a.ss+1); } if(o[i]&1)ans.ff = INT_MAX-1; if(o[i]>>1)ans.ss = INT_MAX-1; return ans; } int min(pii x){ return min(x.ff, x.ss); } int cat(int v) { o[v] = 1; return min(dfs(1, 1)); } int dog(int v) { o[v] = 2; return min(dfs(1, 1)); } int neighbor(int v) { o[v] = 0; return min(dfs(1, 1)); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...