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;
#ifndef EVAL
#include "grader.cpp"
#endif
const int N = 1e3 + 5;
vector<int> edges[N];
int a[N], dp[N][2];
int dfs(int u, int p = -1){
dp[u][0] = dp[u][1] = 0;
for(auto x : edges[u]){
if(x == p) continue;
dfs(x, u);
dp[u][0] += min(dp[x][0], dp[x][1] + 1);
dp[u][1] += min(dp[x][0] + 1, dp[x][1]);
}
if(a[u] == 1) dp[u][1] = 1e9;
if(a[u] == 2) dp[u][0] = 1e9;
return min(dp[u][0], dp[u][1]);
}
void initialize(int n, vector<int> a, vector<int> b) {
for(int i=0;i<(int)a.size();i++){
edges[a[i]].push_back(b[i]);
edges[b[i]].push_back(a[i]);
}
}
int cat(int v) {
a[v] = 1;
return dfs(1);
}
int dog(int v) {
a[v] = 2;
return dfs(1);
}
int neighbor(int v) {
a[v] = 0;
return dfs(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... |