제출 #213563

#제출 시각아이디문제언어결과실행 시간메모리
213563erd1Cats or Dogs (JOI18_catdog)C++14
0 / 100
5 ms384 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 = {o[i]&1, o[i]>>1}; 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); } 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...