This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |